mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Make Tool inputSchema optional
This commit is contained in:
8 files changed
+40
-52
No files matched your search
@@ -5,13 +5,22 @@ import { Tool } from './Tool';
|
||||
* Convert a custom Tool to OpenAI's ChatCompletionTool format
|
||||
*/
|
||||
export function toolToOpenAI<TParams>(name: string, tool: Tool<TParams>): OpenAI.Chat.Completions.ChatCompletionTool {
|
||||
const functionDef: {
|
||||
name: string;
|
||||
description: string;
|
||||
parameters?: Record<string, unknown>;
|
||||
} = {
|
||||
name,
|
||||
description: tool.description,
|
||||
};
|
||||
|
||||
if (tool.inputSchema) {
|
||||
functionDef.parameters = zodSchemaToJsonSchema(tool.inputSchema);
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'function',
|
||||
function: {
|
||||
name,
|
||||
description: tool.description,
|
||||
parameters: zodSchemaToJsonSchema(tool.inputSchema)
|
||||
}
|
||||
function: functionDef
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user