mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 18:01:22 +00:00
fix: Adjust max tokens for Anthropic and improve Google tools handling
- Reduce default max tokens for Anthropic to 1/3 of model max - Fix Google provider to properly handle empty tools array - Ensure toolConfig is undefined when no tools are present
This commit is contained in:
parent
433b42ac91
commit
73d2119606
2 changed files with 7 additions and 4 deletions
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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) => ({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue