Skip to content

Commit

Permalink
Optimize APIURL settings to support the input of Path.
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Jan 22, 2025
1 parent c55b64c commit 4aecb45
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ChatGPTSharp.Sample/ChatGPTSharp.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
9 changes: 7 additions & 2 deletions ChatGPTSharp.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

ChatGPTClientSettings settings = new ChatGPTClientSettings();
settings.OpenAIToken = File.ReadAllText("KEY.txt");
settings.ModelName = "gpt-4o";
settings.ProxyUri = "http://127.0.0.1:1081";
settings.ModelName = "anthropic/claude-3.5-sonnet";
settings.APIURL = "https://openrouter.ai/api";




var client = new ChatGPTClient(settings);


client.IsDebug = true;

var ChatImageModels = new List<ChatImageModel>()
Expand Down
12 changes: 11 additions & 1 deletion ChatGPTSharp/ChatGPTClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ public ChatGPTClient(ChatGPTClientSettings settings)


Settings = settings;
_tiktoken = TikToken.EncodingForModel(settings.ModelName);


try
{
_tiktoken = TikToken.EncodingForModel(settings.ModelName);
}
catch (Exception ex)
{
_tiktoken = null;
settings.DisableCheckTokens = true;
}
}


Expand Down
5 changes: 4 additions & 1 deletion ChatGPTSharp/Model/ChatGPTClientSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ChatGPTSharp.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -75,7 +76,9 @@ private void UpdateCompletionsUrl()
{
UriBuilder uriBuilder = new UriBuilder(APIURL);

uriBuilder.Path = "/v1/chat/completions";


uriBuilder.Path = uriBuilder.Path + (uriBuilder.Path.EndsWith("/") ? "" : "/") + "v1/chat/completions";

CompletionsUrl = uriBuilder.Uri.AbsoluteUri;
}
Expand Down
2 changes: 1 addition & 1 deletion ChatGPTSharp/Model/ClientModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ChatMessage
public List<ChatImageModel> ImageContent { get; set; } = new List<ChatImageModel> { };


public (JObject body, int tokens) GetTokens (TikToken tikToken)
public (JObject body, int tokens) GetTokens (TikToken? tikToken)
{
var body = MessageBody;
var textTokens = TokenUtils.GetTokensForSingleMessage(tikToken, body);
Expand Down

0 comments on commit 4aecb45

Please sign in to comment.