diff --git a/packages/ai/src/providers/anthropic.ts b/packages/ai/src/providers/anthropic.ts index 832c48cc..5be7eb70 100644 --- a/packages/ai/src/providers/anthropic.ts +++ b/packages/ai/src/providers/anthropic.ts @@ -261,7 +261,7 @@ function buildParams( const params: MessageCreateParamsStreaming = { model: model.id, messages: convertMessages(context.messages, model), - max_tokens: options?.maxTokens || model.maxTokens, + max_tokens: options?.maxTokens || (model.maxTokens / 3) | 0, stream: true, }; diff --git a/packages/ai/src/providers/google.ts b/packages/ai/src/providers/google.ts index aa184c3d..b2a955ac 100644 --- a/packages/ai/src/providers/google.ts +++ b/packages/ai/src/providers/google.ts @@ -270,15 +270,17 @@ function buildParams( const config: GenerateContentConfig = { ...(Object.keys(generationConfig).length > 0 && generationConfig), ...(context.systemPrompt && { systemInstruction: context.systemPrompt }), - ...(context.tools && { tools: convertTools(context.tools) }), + ...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }), }; - if (context.tools && options.toolChoice) { + if (context.tools && context.tools.length > 0 && options.toolChoice) { config.toolConfig = { functionCallingConfig: { mode: mapToolChoice(options.toolChoice), }, }; + } else { + config.toolConfig = undefined; } if (options.thinking?.enabled && model.reasoning) { @@ -385,7 +387,8 @@ function convertMessages(model: Model<"google-generative-ai">, context: Context) return contents; } -function convertTools(tools: Tool[]): any[] { +function convertTools(tools: Tool[]): any[] | undefined { + if (tools.length === 0) return undefined; return [ { functionDeclarations: tools.map((tool) => ({