@oh-my-pi/pi-ai 4.4.5 → 4.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -695,7 +695,7 @@ function buildRequest(
|
|
|
695
695
|
}
|
|
696
696
|
|
|
697
697
|
if (context.tools && context.tools.length > 0) {
|
|
698
|
-
request.tools = convertTools(context.tools);
|
|
698
|
+
request.tools = convertTools(context.tools, model);
|
|
699
699
|
if (options.toolChoice) {
|
|
700
700
|
request.toolConfig = {
|
|
701
701
|
functionCallingConfig: {
|
|
@@ -240,22 +240,31 @@ export function sanitizeSchemaForGoogle(value: unknown): unknown {
|
|
|
240
240
|
return result;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
function sanitizeToolNoop(tool: Tool): Tool {
|
|
244
|
+
return {
|
|
245
|
+
name: tool.name,
|
|
246
|
+
description: tool.description,
|
|
247
|
+
parameters: structuredClone(tool.parameters),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function sanitizeToolGoogle(tool: Tool): Tool {
|
|
251
|
+
return {
|
|
252
|
+
name: tool.name,
|
|
253
|
+
description: tool.description,
|
|
254
|
+
parameters: sanitizeSchemaForGoogle(tool.parameters) as any,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
243
258
|
/**
|
|
244
259
|
* Convert tools to Gemini function declarations format.
|
|
245
260
|
*/
|
|
246
261
|
export function convertTools(
|
|
247
262
|
tools: Tool[],
|
|
263
|
+
model: Model<"google-generative-ai" | "google-gemini-cli" | "google-vertex">,
|
|
248
264
|
): { functionDeclarations: { name: string; description?: string; parameters: Schema }[] }[] | undefined {
|
|
249
265
|
if (tools.length === 0) return undefined;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
functionDeclarations: tools.map((tool) => ({
|
|
253
|
-
name: tool.name,
|
|
254
|
-
description: tool.description,
|
|
255
|
-
parameters: sanitizeSchemaForGoogle(tool.parameters) as Schema,
|
|
256
|
-
})),
|
|
257
|
-
},
|
|
258
|
-
];
|
|
266
|
+
const toolSanitizer = model?.id.startsWith("gemini-") ? sanitizeToolGoogle : sanitizeToolNoop;
|
|
267
|
+
return [{ functionDeclarations: tools.map(toolSanitizer) }];
|
|
259
268
|
}
|
|
260
269
|
|
|
261
270
|
/**
|
|
@@ -326,7 +326,7 @@ function buildParams(
|
|
|
326
326
|
const config: GenerateContentConfig = {
|
|
327
327
|
...(Object.keys(generationConfig).length > 0 && generationConfig),
|
|
328
328
|
...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),
|
|
329
|
-
...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),
|
|
329
|
+
...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools, model) }),
|
|
330
330
|
};
|
|
331
331
|
|
|
332
332
|
if (context.tools && context.tools.length > 0 && options.toolChoice) {
|
package/src/providers/google.ts
CHANGED
|
@@ -297,7 +297,7 @@ function buildParams(
|
|
|
297
297
|
const config: GenerateContentConfig = {
|
|
298
298
|
...(Object.keys(generationConfig).length > 0 && generationConfig),
|
|
299
299
|
...(context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) }),
|
|
300
|
-
...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }),
|
|
300
|
+
...(context.tools && context.tools.length > 0 && { tools: convertTools(context.tools, model) }),
|
|
301
301
|
};
|
|
302
302
|
|
|
303
303
|
if (context.tools && context.tools.length > 0 && options.toolChoice) {
|