* 工具格式转换示例
()
| 195 | * 工具格式转换示例 |
| 196 | */ |
| 197 | async function demonstrateFormatConversion() { |
| 198 | console.log('=== 工具格式转换示例 ==='); |
| 199 | |
| 200 | const toolManager = await createToolManager(); |
| 201 | const tools = toolManager.getAllTools().slice(0, 3); |
| 202 | |
| 203 | console.log('原始工具定义:'); |
| 204 | tools.forEach(tool => { |
| 205 | console.log(`- ${tool.name}: ${tool.description}`); |
| 206 | }); |
| 207 | |
| 208 | console.log('\n转换为 OpenAI Tools 格式:'); |
| 209 | const openaiTools = ToolFormatConverter.toOpenAITools(tools); |
| 210 | console.log(JSON.stringify(openaiTools[0], null, 2)); |
| 211 | |
| 212 | console.log('\n转换为 OpenAI Functions 格式:'); |
| 213 | const openaiFunctions = ToolFormatConverter.toOpenAIFunctions(tools); |
| 214 | console.log(JSON.stringify(openaiFunctions[0], null, 2)); |
| 215 | |
| 216 | console.log('\n为 Qwen 优化的格式:'); |
| 217 | const optimizedTools = ToolFormatConverter.optimizeForQwen(openaiTools); |
| 218 | console.log('优化后的描述:', optimizedTools[0].function.description); |
| 219 | |
| 220 | console.log('\n生成调用示例:'); |
| 221 | const example = ToolFormatConverter.generateExample(openaiTools[0]); |
| 222 | console.log(example); |
| 223 | } |
| 224 | |
| 225 | // 运行示例 |
| 226 | if (import.meta.url === `file://${process.argv[1]}`) { |
nothing calls this directly
no test coverage detected