@nomyx/assistant
Version:
A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)
36 lines (33 loc) • 1.08 kB
text/typescript
import { GenericToolSchema, StandardizedToolCall, ParameterDefinition } from '../../../types/tool';
export function convertToolSchema(schema: GenericToolSchema): any {
return {
name: schema.name,
description: schema.description,
parameters: {
type: 'object',
properties: Object.entries(schema.parameters.properties).reduce<Record<string, { type: string }>>((acc, [key, value]) => {
const paramDef = value as ParameterDefinition;
acc[key] = { type: paramDef.type };
return acc;
}, {}),
required: schema.parameters.required || [],
},
};
}
export function convertToolCall(call: any): StandardizedToolCall {
return {
name: call.name,
arguments: JSON.parse(call.arguments || '{}'),
};
}
export function convertMessages(messages: any[]): any[] {
return messages.map(msg => ({
role: msg.role,
content: msg.content,
name: msg.name,
function_call: msg.function_call ? {
name: msg.function_call.name,
arguments: JSON.stringify(msg.function_call.arguments)
} : undefined
}));
}