Skip to content

Commit

Permalink
chore: update llm path check algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Dec 22, 2024
1 parent 80601ba commit 22c323d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ public async Task TranslateAsync(object request, Action<string> onDataReceived,
a_model = string.IsNullOrEmpty(a_model) ? "gpt35" : a_model;

var path = $"/openai/deployments/{a_model}/chat/completions";
// 如果路径为空或者不是有效的API路径结尾,使用默认路径
if (!uriBuilder.Path.EndsWith(path) && uriBuilder.Path == "/")
if (uriBuilder.Path == "/")
uriBuilder.Path = path;

if (string.IsNullOrEmpty(uriBuilder.Query))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ public async Task TranslateAsync(object request, Action<string> onDataReceived,
UriBuilder uriBuilder = new(Url);

// 兼容旧版API: https://open.bigmodel.cn/dev/api#glm-4
// 如果路径为空或者不是有效的API路径结尾,使用默认路径
if (!uriBuilder.Path.EndsWith("/api/paas/v4/chat/completions") && uriBuilder.Path == "/")
if (uriBuilder.Path == "/")
uriBuilder.Path = "/api/paas/v4/chat/completions";

// 选择模型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ public async Task TranslateAsync(object request, Action<string> onDataReceived,

UriBuilder uriBuilder = new(Url);

// 如果路径为空或者不是有效的API路径结尾,使用默认路径
if (!uriBuilder.Path.EndsWith("/v1/messages") && uriBuilder.Path == "/")
if (uriBuilder.Path == "/")
uriBuilder.Path = "/v1/messages";

// 选择模型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ public async Task TranslateAsync(object request, Action<string> onDataReceived,

UriBuilder uriBuilder = new(Url);

// 如果路径为空或者不是有效的API路径结尾,使用默认路径
if (!uriBuilder.Path.EndsWith("/chat/completions") && uriBuilder.Path == "/")
if (uriBuilder.Path == "/")
uriBuilder.Path = "/chat/completions";

// 选择模型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ public async Task TranslateAsync(object request, Action<string> onDataReceived,
var a_model = Model.Trim();
a_model = string.IsNullOrEmpty(a_model) ? "gemini-pro" : a_model;

// 如果路径为空或者不是有效的API路径结尾,使用默认路径
if (!uriBuilder.Path.EndsWith($"/v1beta/models/{a_model}:streamGenerateContent") && uriBuilder.Path == "/")
if (uriBuilder.Path == "/")
uriBuilder.Path = $"/v1beta/models/{a_model}:streamGenerateContent";

uriBuilder.Query = $"key={AppKey}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ public async Task TranslateAsync(object request, Action<string> onDataReceived,

UriBuilder uriBuilder = new(Url);

// 如果路径为空或者不是有效的API路径结尾,使用默认路径
if (!uriBuilder.Path.EndsWith("/api/chat") && uriBuilder.Path == "/")
if (uriBuilder.Path == "/")
uriBuilder.Path = "/api/chat";

// 选择模型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ public async Task TranslateAsync(object request, Action<string> onDataReceived,
UriBuilder uriBuilder = new(Url);

// 兼容旧版API: https://platform.openai.com/docs/guides/text-generation
// 如果路径为空或者不是有效的API路径结尾,使用默认路径
if (!uriBuilder.Path.EndsWith("/v1/chat/completions") && !uriBuilder.Path.EndsWith("/v1/completions") && uriBuilder.Path == "/")
// 如果路径不是有效的API路径结尾,使用默认路径
if (uriBuilder.Path == "/")
uriBuilder.Path = "/v1/chat/completions";

// 选择模型
Expand Down

0 comments on commit 22c323d

Please sign in to comment.