It’s important to craft good prompts that will give best results.
lib/
├─ llm/
│ ├─ prompts/
│ │ ├─ format-lyrics.ts // 👈 This is the prompt I used for formatting the lyrics
│ │ └─ translate-lyrics.ts // 👈 This is the prompt I used for translating the lyrics
│ └─ llm.ts
I also created an abstract layer for talking to the model. This is a good practice in case you may want to switch between different modals by hiding implementation details and keeping the public interface intact.
// Location: src\lib\llm\llm.ts
// FILE. import statements
const ai = new GoogleGenAI({
apiKey: "",
});
const llmModal = {
async formatLyrics(lyrics: string) {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: lyrics,
config: {
systemInstruction: {
text: formatLyrics,
},
},
});
return response.text;
},
async translateLyrics(lyrics: Lyrics, targetLanguage: string) {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: JSON.stringify(lyrics),
config: {
systemInstruction: {
text: translateLyrics.replace("{{targetLanguage}}", targetLanguage),
},
},
});
return response.text;
},
};
export default llmModal;