mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 15:01:24 +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 = {
|
const params: MessageCreateParamsStreaming = {
|
||||||
model: model.id,
|
model: model.id,
|
||||||
messages: convertMessages(context.messages, model),
|
messages: convertMessages(context.messages, model),
|
||||||
max_tokens: options?.maxTokens || model.maxTokens,
|
max_tokens: options?.maxTokens || (model.maxTokens / 3) | 0,
|
||||||
stream: true,
|
stream: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -270,15 +270,17 @@ function buildParams(
|
||||||
const config: GenerateContentConfig = {
|
const config: GenerateContentConfig = {
|
||||||
...(Object.keys(generationConfig).length > 0 && generationConfig),
|
...(Object.keys(generationConfig).length > 0 && generationConfig),
|
||||||
...(context.systemPrompt && { systemInstruction: context.systemPrompt }),
|
...(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 = {
|
config.toolConfig = {
|
||||||
functionCallingConfig: {
|
functionCallingConfig: {
|
||||||
mode: mapToolChoice(options.toolChoice),
|
mode: mapToolChoice(options.toolChoice),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
config.toolConfig = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.thinking?.enabled && model.reasoning) {
|
if (options.thinking?.enabled && model.reasoning) {
|
||||||
|
|
@ -385,7 +387,8 @@ function convertMessages(model: Model<"google-generative-ai">, context: Context)
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertTools(tools: Tool[]): any[] {
|
function convertTools(tools: Tool[]): any[] | undefined {
|
||||||
|
if (tools.length === 0) return undefined;
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
functionDeclarations: tools.map((tool) => ({
|
functionDeclarations: tools.map((tool) => ({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue