| 632 | 'Content-Type': 'application/json', |
| 633 | }, |
| 634 | timeout: 60000, |
| 635 | }); |
| 636 | |
| 637 | const messages: any[] = []; |
| 638 | if (SYSTEM_PROMPT) { |
| 639 | messages.push({ role: 'system', content: SYSTEM_PROMPT }); |
| 640 | } |
| 641 | |
| 642 | // 构建用户消息内容 |
| 643 | if (imageInfo) { |
| 644 | const content: any[] = []; |
| 645 | if (question) { |
| 646 | content.push({ type: 'text', text: question }); |
| 647 | } else { |
| 648 | content.push({ type: 'text', text: '请识别这张图片/贴纸的内容' }); |
| 649 | } |
| 650 | content.push({ |
| 651 | type: 'image_url', |
| 652 | image_url: { |
| 653 | url: `data:${imageInfo.mimeType};base64,${imageInfo.base64}`, |
| 654 | }, |
| 655 | }); |
| 656 | messages.push({ role: 'user', content }); |
| 657 | } else { |
| 658 | messages.push({ role: 'user', content: question }); |
| 659 | } |
| 660 | |
| 661 | const response = await client.post('/chat/completions', { |
| 662 | model: this.config.model, |
| 663 | messages, |
| 664 | temperature: 0.7, |
| 665 | }); |
| 666 | |
| 667 | return response.data.choices[0]?.message?.content?.trim() || '无法获取回复'; |
| 668 | } |
| 669 | |
| 670 | private async callGemini(question: string, imageInfo?: MediaInfo): Promise<string> { |
| 671 | const baseUrl = this.config.baseUrl.replace(/\/$/, ''); |
| 672 | const url = `${baseUrl}/models/${encodeURIComponent( |
| 673 | this.config.model |
| 674 | )}:generateContent`; |
| 675 | |
| 676 | // 构建内容部分 |
| 677 | const parts: any[] = []; |
| 678 | if (question) { |