* 自动检测格式并转换为 OpenAI Tools 格式
(input: any[])
| 88 | * 自动检测格式并转换为 OpenAI Tools 格式 |
| 89 | */ |
| 90 | static autoConvertToTools(input: any[]): OpenAITool[] { |
| 91 | if (!input.length) return []; |
| 92 | |
| 93 | const first = input[0]; |
| 94 | |
| 95 | // 如果已经是 OpenAI Tools 格式 |
| 96 | if (first.type === 'function' && first.function) { |
| 97 | return input as OpenAITool[]; |
| 98 | } |
| 99 | |
| 100 | // 如果是 OpenAI Functions 格式 |
| 101 | if (first.name && first.description && first.parameters && !first.type) { |
| 102 | return this.functionsToTools(input as OpenAIFunction[]); |
| 103 | } |
| 104 | |
| 105 | // 如果是项目内部的 ToolDefinition 格式 |
| 106 | if (first.name && first.description && first.parameters && first.execute) { |
| 107 | return this.toOpenAITools(input as ToolDefinition[]); |
| 108 | } |
| 109 | |
| 110 | // 默认尝试当作 Functions 格式处理 |
| 111 | return this.functionsToTools(input as OpenAIFunction[]); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * 自动检测格式并转换为 OpenAI Functions 格式 |
nothing calls this directly
no test coverage detected