From b6823909532bdc727a51b8bda266cf62dd5dff6d Mon Sep 17 00:00:00 2001 From: aaravkumar Date: Fri, 4 Apr 2025 21:43:40 -0400 Subject: predictive question replaced from mock text to GPT (actual prediction) --- src/client/views/nodes/formattedText/DailyJournal.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx index f308d45a8..26a86bc6e 100644 --- a/src/client/views/nodes/formattedText/DailyJournal.tsx +++ b/src/client/views/nodes/formattedText/DailyJournal.tsx @@ -103,7 +103,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() * Inserts predictive text at the end of what the user is typing */ - @action insertPredictiveQuestion = () => { + @action insertPredictiveQuestion = async () => { const editorView = this._ref.current?.EditorView; if (!editorView) return; @@ -133,8 +133,15 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() const fontColorMark = schema.marks.pFontColor.create({ fontColor: 'lightgray' }); const fontItalicsMark = schema.marks.em.create(); + this.predictiveText = ' ...'; // placeholder for now + + const fullTextUpToCursor = state.doc.textBetween(0, state.selection.to, '\n', '\n'); + const gptPrompt = `Given the following incomplete journal entry, generate a single 2-5 word question that continues the user's thought:\n\n"${fullTextUpToCursor}"`; + const res = await gptAPICall(gptPrompt, GPTCallType.COMPLETION); + if (!res) return; + // styled text node - const text = ' ... why?'; + const text = ` ... ${res.trim()}`; const predictedText = schema.text(text, [fontSizeMark, fontColorMark, fontItalicsMark]); // Insert styled text at cursor position -- cgit v1.2.3-70-g09d2