* 自动选择最佳的函数调用方式 * 优先使用 tools 格式,如果不支持则回退到 functions 格式
(
messages: any[],
toolsOrFunctions: any[],
options?: Partial<LLMRequest>
)
| 355 | * 优先使用 tools 格式,如果不支持则回退到 functions 格式 |
| 356 | */ |
| 357 | public async smartFunctionCall( |
| 358 | messages: any[], |
| 359 | toolsOrFunctions: any[], |
| 360 | options?: Partial<LLMRequest> |
| 361 | ): Promise<any> { |
| 362 | try { |
| 363 | // 首先尝试使用现代 tools 格式 |
| 364 | const tools = this.convertToToolsFormat(toolsOrFunctions); |
| 365 | return await this.toolsCall(messages, tools, options); |
| 366 | } catch (error) { |
| 367 | // 如果 tools 格式失败,回退到 functions 格式 |
| 368 | if (error instanceof Error && error.message.includes('tools')) { |
| 369 | console.warn('Qwen: Tools 格式不支持,回退到 functions 格式'); |
| 370 | const functions = this.convertToFunctionsFormat(toolsOrFunctions); |
| 371 | return await this.functionCall(messages, functions, options); |
| 372 | } |
| 373 | throw error; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * 将工具定义转换为 OpenAI Tools 格式 |
no test coverage detected