(query: string)
| 93 | const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`; |
| 94 | |
| 95 | const systemPrompt = toSimplified(`You are a music information expert. Return information in the following format ONLY, without any other text: |
| 96 | |
| 97 | 歌曲名: [Song Title] |
| 98 | 歌手: [Artist Name] |
| 99 | 专辑: [Album Name] |
| 100 | |
| 101 | If info is unknown, use "未知".`); |
| 102 | |
| 103 | const userPrompt = toSimplified(`Find precise info for this song: '${query}'. Correct typos and find the most famous version. If not found, use user's query '${query}' as the song title.`); |
| 104 | |
| 105 | const requestData = { |
| 106 | contents: [{ role: "user", parts: [{ text: userPrompt }] }], |
| 107 | systemInstruction: { parts: [{ text: systemPrompt }] }, |
| 108 | tools: [{ "google_search": {} }], |
| 109 | }; |
| 110 | |
| 111 | try { |
| 112 | const response = await axios.post(url, requestData, { |
| 113 | headers: { "x-goog-api-key": this.apiKey, "Content-Type": "application/json" }, |
| 114 | timeout: 30000, |
| 115 | }); |
| 116 | return response.data?.candidates?.[0]?.content?.parts?.[0]?.text || ''; |
| 117 | } catch (error: any) { |
| 118 | const errorMsg = error.response?.data?.error?.message || error.message; |
| 119 | throw new Error(`Gemini API Error: ${errorMsg}`); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // --- Helper Functions --- |
| 125 | interface SongInfo { |
| 126 | title: string; |
| 127 | artist: string; |
| 128 | album: string; |
no outgoing calls
no test coverage detected