async generateTune()

in src/app/app.component.ts [78:106]


  async generateTune(prompt: string) {
    prompt = basePrompt + prompt;

    /**
     * For production apps, make sure you use the Gemini API key **only**
     * on the server. Find more at https://ai.google.dev/gemini-api/docs/get-started/web
     */
    const genAI = new GoogleGenerativeAI(this.apiKey().nativeElement.value);

    const model = genAI.getGenerativeModel({
      model: 'gemini-1.5-pro-latest'
    });
    model.generationConfig.responseMimeType = 'application/json';
    
    this.loading = true;

    try {
      const result = await model.generateContent(prompt);
      const response = result.response;
      const text = response.text();
      const tune = JSON.parse(text);

      this.keyboard().playMelody(tune);
    } catch (e: unknown) {
      this.error = <string>e;
    } finally {
      this.loading = false;
    }
  }