Skip to content

Commit

Permalink
perf(openai): Compatible with both old and new APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Jan 18, 2024
1 parent a9355c1 commit a7ee7e9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions STranslate/ViewModels/ServiceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ public static async Task OpenAIHandlerAsync(ITranslator service, string content,

UriBuilder uriBuilder = new(service.Url);

if (!uriBuilder.Path.EndsWith("/v1/completions"))
// 兼容旧版API: https://platform.openai.com/docs/guides/text-generation
if (!uriBuilder.Path.EndsWith("/v1/chat/completions") && !uriBuilder.Path.EndsWith("/v1/completions"))
{
uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/v1/completions";
uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/v1/chat/completions";
}

var a_model = (service as TranslatorOpenAI)?.Model;
Expand Down

0 comments on commit a7ee7e9

Please sign in to comment.