async ask()

in src/app/journal.component.ts [215:249]


    async ask(question_to_ask: string) {
        this.question = question_to_ask

        if(this.api_key.length == 0) {
            this.error_message = "Please enter an API KEY for Gemini first."
            return
        }

        this.loading = true

        const today = new Date();
        const formattedDate = today.toLocaleDateString('en-US');
        
        let prompt = `This is today's date: ${formattedDate}. I'm passing you a list of journal entries at the end of this prompt. Here is a question the author just asked about all of the entries: ${question_to_ask}. Please pay attention to dates. The author might have said something like 'what did I do last month?'. Please use the current date I provided, and use the dates on each entry to look at the correct ones. Please answer the author's question. Be brief. If they ask about 1 entrey, 2-3 sentences is ok. If they ask about 2-3 entries, 1 sentence each, or a 3-5 sentence summary is ok. If they ask about more entires, just do 1-2 sentences each, like a bulleted list. Please try your best to answer the author's question. Here are the entries:\n`;

        for(let entry of this.journalEntries.getEntries(this.selected_journal)) {
            prompt += `${entry.date}\n${entry.entry}\n\n`
        }
        const geminiOutput = await this.callGemini(prompt)

        this.loading = false

        if(geminiOutput == "-1") {
            // Error with gemini output
            this.answer = "I cannot answer that question, please ask it in a different way."
            this.valid_answer = false
        } else if(geminiOutput == "-2") {
            this.answer = "API key is invalid. Please go back and enter a valid API key."
            this.valid_answer = false
        } else {
            this.answer = geminiOutput
            this.valid_answer = true
        }

    }