Fix max_tokens OpenAI compatibility
This commit is contained in:
parent
4050bf66e5
commit
43894b0ac9
1 changed files with 10 additions and 0 deletions
10
src/main.ts
10
src/main.ts
|
|
@ -18,6 +18,16 @@ const providers: CreateAnthropicProxyOptions["providers"] = {
|
|||
openai: createOpenAI({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
baseURL: process.env.OPENAI_API_URL,
|
||||
fetch: (async (url, init) => {
|
||||
if (init?.body && typeof init.body === "string") {
|
||||
const body = JSON.parse(init.body);
|
||||
const maxTokens = body.max_tokens;
|
||||
delete body["max_tokens"];
|
||||
body.max_completion_tokens = maxTokens;
|
||||
init.body = JSON.stringify(body);
|
||||
}
|
||||
return globalThis.fetch(url, init);
|
||||
}) as typeof fetch,
|
||||
}),
|
||||
azure: createAzure({
|
||||
apiKey: process.env.AZURE_API_KEY,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue