From c6b9988e027f186262a1b65700edbec1ed6ed7d1 Mon Sep 17 00:00:00 2001
From: David Li <taweili@gmail.com>
Date: Sat, 2 Dec 2023 21:12:59 +0800
Subject: Testing out ideas with context

---
 src/ollama.tsx | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src/ollama.tsx')

diff --git a/src/ollama.tsx b/src/ollama.tsx
index f792613..a59b03b 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -101,10 +101,8 @@ async function ollamaGenerate(prompt: string, parameters?: OllamaGenerateParamet
       throw new Error("Error in Ollama request: " + response.statusText)
     }
     const data = await response.json()
-
-    console.log(data)
     
-    return data.response
+    return data
   } catch (e: any) {
     console.log(e)
     logseq.UI.showMsg("Error in Ollama request")
@@ -212,9 +210,14 @@ export async function promptFromBlockEvent(b: IHookEvent) {
     const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, '🦙Generating ...', { before: false })
     const params = await getOllamaParametersFromBlockProperties(currentBlock!)
     const prompt = currentBlock!.content.replace(/^.*::.*$/gm, '') // nasty hack to remove properties from block content
-    const response = await ollamaGenerate(prompt, params);
+    const result = await ollamaGenerate(prompt, params);
     
-    await logseq.Editor.updateBlock(answerBlock!.uuid, `${response}`)
+    console.log(result)
+
+    if (params.usecontext) {
+      await logseq.Editor.upsertBlockProperty(currentBlock!.uuid, 'ollama-generate-context', result.context)
+    }
+    await logseq.Editor.updateBlock(answerBlock!.uuid, `${result.response}`)
   } catch (e: any) {
     logseq.UI.showMsg(e.toString(), 'warning')
     console.error(e)
-- 
cgit v1.2.3

