Skip to content

Commit

Permalink
update dependency; remove azure support since miscrosoft no longer pr…
Browse files Browse the repository at this point in the history
…ovide service for personal usage for users in mainland China; change publish config to embed windows desktop runtime since apparently the runtime installer is making trouble for some users (see microsoft/WindowsAppSDK#4268)
  • Loading branch information
lone-wolf-akela committed Nov 15, 2024
1 parent 6025845 commit 3c5ce82
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 244 deletions.
14 changes: 7 additions & 7 deletions ChatGptApiClientV2/ChatGptApiClientV2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,32 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0-beta.1" />
<PackageReference Include="boilerplatezero" Version="2.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Coltr.Markdig.Wpf.ColorCode" Version="1.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.1.1" />
<PackageReference Include="Flurl" Version="4.0.0" />
<PackageReference Include="HandyControls" Version="3.5.3" />
<PackageReference Include="HandyControls.Lang.zh-CN" Version="3.5.3" />
<PackageReference Include="Lib.Harmony" Version="2.3.3" />
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="Markdig" Version="0.38.0" />
<PackageReference Include="Markdig.Wpf" Version="0.5.0.1" />
<PackageReference Include="Microsoft.ML.Tokenizers" Version="0.22.0-preview.24378.1" />
<PackageReference Include="Microsoft.ML.Tokenizers" Version="1.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NJsonSchema" Version="11.0.2" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.2" />
<PackageReference Include="OpenAI" Version="2.1.0-beta.1" />
<PackageReference Include="PuppeteerSharp" Version="20.0.2" />
<PackageReference Include="PuppeteerSharp" Version="20.0.5" />
<PackageReference Include="pythonnet" Version="3.0.4" />
<PackageReference Include="SharpVectors" Version="1.8.4.2" />
<PackageReference Include="System.IO.Packaging" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.IO.Packaging" Version="9.0.0" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
104 changes: 14 additions & 90 deletions ChatGptApiClientV2/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public enum ServiceProviderType
{
[Description("Artonelico OpenAI 代理")] ArtonelicoOpenAIProxy,
[Description("OpenAI 官方接口(需科学上网)")] OpenAI,
[Description("Microsoft Azure")] Azure,
[Description("其他")] Others
}

Expand All @@ -110,7 +109,6 @@ public enum ServiceProviderType
partial void OnServiceProviderChanged(ServiceProviderType value)
{
ValidateProperty(ServiceURL, nameof(ServiceURL));
ValidateProperty(AzureEndpoint, nameof(AzureEndpoint));
UpdateModelOptionList();
UpdateModelVersionList();
SaveConfig();
Expand All @@ -125,7 +123,6 @@ public string ServiceURL
{
ServiceProviderType.ArtonelicoOpenAIProxy => "https://www.artonelico.top/openai-proxy/v1",
ServiceProviderType.OpenAI => "https://api.openai.com/v1",
ServiceProviderType.Azure => AzureEndpoint,
_ => serviceURL
};
set
Expand Down Expand Up @@ -220,23 +217,14 @@ public string AnthropicServiceURL
}
}

[ObservableProperty] [NotifyDataErrorInfo] [Url(ErrorMessage = "必须为合法的 Http 或 Https 地址")]
private string azureEndpoint;

[JsonIgnore]
public string DalleImageGenServiceURL => ServiceProvider switch
{
ServiceProviderType.Azure => Url.Combine(AzureEndpoint,
$"openai/deployments/{AzureDalleDeploymentId}/images/generations?api-version=2024-02-01"),
_ => Url.Combine(ServiceURL, "images/generations")
};
public string DalleImageGenServiceURL => Url.Combine(ServiceURL, "images/generations");

[JsonIgnore]
public bool ServiceURLEditable => ServiceProvider switch
{
ServiceProviderType.ArtonelicoOpenAIProxy => false,
ServiceProviderType.OpenAI => false,
ServiceProviderType.Azure => true,
ServiceProviderType.Others => true,
_ => throw new InvalidOperationException()
};
Expand All @@ -256,28 +244,12 @@ [ObservableProperty] [NotifyDataErrorInfo] [Url(ErrorMessage = "必须为合法

partial void OnAPI_KEYChanged(string value) => SaveConfig();

[ObservableProperty] private string azureAPIKey;
partial void OnAzureAPIKeyChanged(string value) => SaveConfig();
public ObservableCollection<string> AzureDeploymentList { get; } = [];

[ObservableProperty] private string anthropicAPIKey;
partial void OnAnthropicAPIKeyChanged(string value) => SaveConfig();

[ObservableProperty] private string otherOpenAICompatModelAPIKey;
partial void OnOtherOpenAICompatModelAPIKeyChanged(string value) => SaveConfig();

private void AzureDeploymentListCollectionChanged(object? sender,
System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (ServiceProvider == ServiceProviderType.Azure)
{
UpdateModelVersionList();
}
}

[ObservableProperty] private string azureDalleDeploymentId;
partial void OnAzureDalleDeploymentIdChanged(string value) => SaveConfig();

/* Google Search Plugin Config */
[ObservableProperty] private string googleSearchEngineID;
partial void OnGoogleSearchEngineIDChanged(string value) => SaveConfig();
Expand Down Expand Up @@ -333,19 +305,11 @@ public enum MarkdownRenderMode
private void UpdateModelOptionList()
{
ModelOptions.Clear();
if (ServiceProvider == ServiceProviderType.Azure)
{
ModelOptions.Add(new ModelInfo
{ Name = "azure", Description = "Azure OpenAI Service", DisplayPriority = -100 });
}
else
foreach (var model in ModelInfo.ModelList)
{
foreach (var model in ModelInfo.ModelList)
if (model.Provider == ModelInfo.ProviderEnum.OpenAI)
{
if (model.Provider == ModelInfo.ProviderEnum.OpenAI)
{
ModelOptions.Add(model);
}
ModelOptions.Add(model);
}
}

Expand Down Expand Up @@ -395,55 +359,19 @@ private void UpdateModelVersionList()
return;
}

if (SelectedModelType.Name == "azure")
{
foreach (var id in AzureDeploymentList)
{
var knowledgeCutoff =
id.Contains("gpt-4o") ? new DateTime(2023, 10, 1) :
id.Contains("gpt-4") && id.Contains("1106") ? new DateTime(2023, 4, 1) :
id.Contains("gpt-4") && id.Contains("0125") ? new DateTime(2023, 12, 1) :
id.Contains("gpt-4") && id.Contains("2024-04-09") ? new DateTime(2023, 12, 1) :
new DateTime(2021, 9, 1);

// ReSharper disable SimplifyConditionalTernaryExpression
var functionCallSupported =
id.Contains("0301") ? false :
id.Contains("vision") && id.Contains("1106") ? false :
id.Contains("0314") ? false :
true;
// ReSharper restore SimplifyConditionalTernaryExpression

var tokenizer = id.Contains("gpt-4o") ? ModelVersionInfo.TokenizerEnum.O200KBase :
ModelVersionInfo.TokenizerEnum.Cl100KBase;

ModelVersionOptions.Add(new ModelVersionInfo
{
ModelType = "azure",
Name = id,
Description = id,
KnowledgeCutoff = knowledgeCutoff,
FunctionCallSupported = functionCallSupported,
Tokenizer = tokenizer
});
}
}
else
var models = from model in ModelVersionInfo.VersionList
where model.ModelType == SelectedModelType.Name
select model;
foreach (var model in models)
{
var models = from model in ModelVersionInfo.VersionList
where model.ModelType == SelectedModelType.Name
select model;
foreach (var model in models)
if (model.ModelType == "Local")
{
if (model.ModelType == "Local")
{
model.KnowledgeCutoff = OtherOpenAICompatModelKnowledgeCutoff;
model.FunctionCallSupported = OtherOpenAICompatModelEnableToolUse;
model.Name = OtherOpenAICompatModelName;
model.Description = OtherOpenAICompatModelName;
}
ModelVersionOptions.Add(model);
model.KnowledgeCutoff = OtherOpenAICompatModelKnowledgeCutoff;
model.FunctionCallSupported = OtherOpenAICompatModelEnableToolUse;
model.Name = OtherOpenAICompatModelName;
model.Description = OtherOpenAICompatModelName;
}
ModelVersionOptions.Add(model);
}

SelectedModelVersionIndex = 0;
Expand Down Expand Up @@ -511,12 +439,9 @@ public Config()
otherOpenAICompatModelProviderName = "Meta AI";
anthropicServiceProvider = AnthropicServiceProviderType.ArtonelicAnthropicProxy;
anthropicServiceURL = "";
azureEndpoint = "";
_API_KEY = "";
anthropicAPIKey = "";
otherOpenAICompatModelAPIKey = "";
azureAPIKey = "";
azureDalleDeploymentId = "dall-e-3";
googleSearchAPIKey = "";
googleSearchEngineID = "";
bingSearchAPIKey = "";
Expand All @@ -534,7 +459,6 @@ public Config()
pythonDllPath = "";
pythonEnv = null;

AzureDeploymentList.CollectionChanged += AzureDeploymentListCollectionChanged;
StopSequences.CollectionChanged += StopSequencesCollectionChanged;

UpdateModelOptionList();
Expand Down
2 changes: 1 addition & 1 deletion ChatGptApiClientV2/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public enum ProviderEnum
},
new ModelInfo
{
Name = "Local", Description = "本地部署端口", Provider = ProviderEnum.OtherOpenAICompat,
Name = "Local", Description = "第三方聊天服务", Provider = ProviderEnum.OtherOpenAICompat,
DisplayPriority = 300
},
/*new ModelInfo
Expand Down
30 changes: 16 additions & 14 deletions ChatGptApiClientV2/Properties/PublishProfiles/x64Publish.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<PublishDir>bin\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<SelfContained>false</SelfContained>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<PublishDir>bin\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<SelfContained>false</SelfContained>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<EnableMsixTooling>true</EnableMsixTooling>
<PublishTrimmed>false</PublishTrimmed>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
</PropertyGroup>
</Project>
11 changes: 0 additions & 11 deletions ChatGptApiClientV2/ServerDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ You should have received a copy of the GNU General Public License
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.AI.OpenAI;
using Flurl;
using HandyControl.Tools.Extension;
using HarmonyLib;
Expand Down Expand Up @@ -106,7 +104,6 @@ public class ServerEndpointOptions
public enum ServiceType
{
OpenAI,
Azure,
Claude,
OtherOpenAICompat,
Custom
Expand All @@ -115,7 +112,6 @@ public enum ServiceType
public ServiceType Service { get; set; }
public string Endpoint { get; set; } = "";
public string Key { get; set; } = "";
public string AzureKey { get; set; } = "";
public string Model { get; set; } = "";
public int? MaxTokens { get; set; }
public float? PresencePenalty { get; set; }
Expand Down Expand Up @@ -153,13 +149,6 @@ public OpenAIEndpoint(ServerEndpointOptions o)

switch (options.Service)
{
case ServerEndpointOptions.ServiceType.Azure:
{
var opt = new AzureOpenAIClientOptions { NetworkTimeout = defaultTimeout };
var azure = new AzureOpenAIClient(new Uri(options.Endpoint), new ApiKeyCredential(options.AzureKey), opt);
client = azure.GetChatClient(options.Model);
break;
}
case ServerEndpointOptions.ServiceType.OpenAI:
{
var opt = new OpenAIClientOptions { NetworkTimeout = defaultTimeout };
Expand Down
Loading

0 comments on commit 3c5ce82

Please sign in to comment.