* 生成工具调用示例
(tool: OpenAITool)
| 201 | * 生成工具调用示例 |
| 202 | */ |
| 203 | static generateExample(tool: OpenAITool): string { |
| 204 | const params = tool.function.parameters; |
| 205 | const properties = params?.properties || {}; |
| 206 | const required = params?.required || []; |
| 207 | |
| 208 | const exampleParams: any = {}; |
| 209 | |
| 210 | // 为必需参数生成示例值 |
| 211 | for (const paramName of required) { |
| 212 | const paramSchema = properties[paramName]; |
| 213 | if (paramSchema) { |
| 214 | exampleParams[paramName] = this.generateExampleValue(paramSchema); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return JSON.stringify( |
| 219 | { |
| 220 | name: tool.function.name, |
| 221 | arguments: exampleParams, |
| 222 | }, |
| 223 | null, |
| 224 | 2 |
| 225 | ); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * 根据参数模式生成示例值 |
no test coverage detected