From a5b47d1473b2e3e4b3b3743460826b972803420e Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 16 Dec 2024 17:58:02 +0400 Subject: [PATCH] fix: bring back body --- packages/framework/src/providers/openai.ts | 3 ++- packages/framework/src/providers/openai_response_functions.ts | 3 ++- packages/framework/src/providers/openrouter.ts | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/providers/openai.ts b/packages/framework/src/providers/openai.ts index 893f420..52e7edf 100644 --- a/packages/framework/src/providers/openai.ts +++ b/packages/framework/src/providers/openai.ts @@ -23,7 +23,7 @@ export type OpenAIProviderOptions = { * otherwise you will get an error. Otherwise, use the one from `openai_response_functions.js` instead. */ export const openai = (options: OpenAIProviderOptions = {}): Provider => { - const { model = 'gpt-4o', options: clientOptions } = options + const { model = 'gpt-4o', options: clientOptions, body = {} } = options const client = new OpenAI(clientOptions) return { @@ -36,6 +36,7 @@ export const openai = (options: OpenAIProviderOptions = {}): Provider => { tools: mappedTools.length > 0 ? mappedTools : undefined, temperature, response_format: responseAsStructuredOutput(response_format), + ...body, }) const message = response.choices[0].message diff --git a/packages/framework/src/providers/openai_response_functions.ts b/packages/framework/src/providers/openai_response_functions.ts index ad6b786..cbc7134 100644 --- a/packages/framework/src/providers/openai_response_functions.ts +++ b/packages/framework/src/providers/openai_response_functions.ts @@ -32,7 +32,7 @@ export type OpenAIProviderOptions = BaseOpenAIProviderOptions & { * but tools as response to enforce the right JSON schema. */ export const openai = (options: OpenAIProviderOptions): Provider => { - const { model, options: clientOptions, strictMode = false } = options + const { model, options: clientOptions, strictMode = false, body = {} } = options const client = new OpenAI(clientOptions) return { @@ -45,6 +45,7 @@ export const openai = (options: OpenAIProviderOptions): Provider => { messages, temperature, tool_choice: 'required', + ...body, }) /** diff --git a/packages/framework/src/providers/openrouter.ts b/packages/framework/src/providers/openrouter.ts index 0768cca..2999f8d 100644 --- a/packages/framework/src/providers/openrouter.ts +++ b/packages/framework/src/providers/openrouter.ts @@ -25,6 +25,7 @@ export const openrouter = (options: OpenRouterOptions = {}): Provider => { model = 'meta-llama/llama-3.1-405b-instruct', structured_output = true, options: clientOptions, + body = {}, } = options const openAiOptions = { model, @@ -38,11 +39,13 @@ export const openrouter = (options: OpenRouterOptions = {}): Provider => { * support structured output. */ body: { + ...body, provider: { /** * @see https://openrouter.ai/docs/provider-routing#required-parameters-_beta_ */ require_parameters: true, + ...body?.provider, }, }, }