From 6c7a7bd3db97c0252cf5852355ea95831db2f121 Mon Sep 17 00:00:00 2001
From: David Li <taweili@gmail.com>
Date: Wed, 29 Nov 2023 21:32:21 +0800
Subject: Add Prompt from Block Context Menu Command and put the Ollama
 response in the subblock.

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

(limited to 'src/ollama.tsx')

diff --git a/src/ollama.tsx b/src/ollama.tsx
index f5eaae7..c515574 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -149,6 +149,19 @@ export async function summarizeBlock() {
   }
 }
 
+export async function promptFromBlockEvent(b: IHookEvent) {
+  try {
+    const currentBlock = await logseq.Editor.getBlock(b.uuid)
+    const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, 'Generating....', { before: false })
+    let response = "";
+    const prompt = await promptLLM(`${currentBlock!.content}`);
+    await logseq.Editor.updateBlock(answerBlock!.uuid, `${prompt}`)
+  } catch (e: any) {
+    logseq.UI.showMsg(e.toString(), 'warning')
+    console.error(e)
+  }
+}
+
 export async function askAI(prompt: string, context: string) {
   await delay(300)
   try {
-- 
cgit v1.2.3


From 37c7024b4b4f5afcb00cb0bd6369e2850a4e12c5 Mon Sep 17 00:00:00 2001
From: David Li <taweili@gmail.com>
Date: Wed, 29 Nov 2023 23:33:49 +0800
Subject: Expanding the content of the block with AI

---
 src/ollama.tsx | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

(limited to 'src/ollama.tsx')

diff --git a/src/ollama.tsx b/src/ollama.tsx
index c515574..945d2cb 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -152,16 +152,27 @@ export async function summarizeBlock() {
 export async function promptFromBlockEvent(b: IHookEvent) {
   try {
     const currentBlock = await logseq.Editor.getBlock(b.uuid)
-    const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, 'Generating....', { before: false })
-    let response = "";
-    const prompt = await promptLLM(`${currentBlock!.content}`);
-    await logseq.Editor.updateBlock(answerBlock!.uuid, `${prompt}`)
+    const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating ...', { before: false })
+    const response = await promptLLM(`${currentBlock!.content}`);
+    await logseq.Editor.updateBlock(answerBlock!.uuid, `${response}`)
   } catch (e: any) {
     logseq.UI.showMsg(e.toString(), 'warning')
     console.error(e)
   }
 }
 
+export async function expandBlockEvent(b: IHookEvent) {
+  try {
+    const currentBlock = await logseq.Editor.getBlock(b.uuid)
+    const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating ...', { before: false })
+    const response = await promptLLM(`Expand: ${currentBlock!.content}`);
+    await logseq.Editor.updateBlock(answerBlock!.uuid, `${response}`)
+  } catch(e: any) {
+    logseq.UI.showMsg(e.toString(), 'warning')
+    console.error(e)
+  }
+}
+
 export async function askAI(prompt: string, context: string) {
   await delay(300)
   try {
-- 
cgit v1.2.3

