From fc1d6985c9eb0c31b8ea05244e4a270d9ec8ffaa Mon Sep 17 00:00:00 2001
From: gixita <kris.laermans@gmail.com>
Date: Thu, 8 Feb 2024 17:12:12 +0100
Subject: feat: Add custom prompt functionality to block This commit introduces
 the capability for users to apply custom prompts defined in the configuration
 to a block. Key changes include: - A new configuration string to store the
 custom prompt. - A menu item 'Custom prompt on block'. - Implementation of a
 function to apply the custom prompt to a block, mirroring the existing
 'summarize block' functionality.

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

(limited to 'src/ollama.tsx')

diff --git a/src/ollama.tsx b/src/ollama.tsx
index 9d925db..4fe697f 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -178,6 +178,7 @@ export async function summarizeBlock() {
     const currentBlock = await logseq.Editor.getCurrentBlock()
     let summaryBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, `⌛Summarizing Block...`, { before: false })
     const summary = await promptLLM(`Summarize the following ${currentBlock!.content}`);
+
     await logseq.Editor.updateBlock(summaryBlock!.uuid, `Summary: ${summary}`)
   } catch (e: any) {
     logseq.App.showMsg(e.toString(), 'warning')
@@ -185,6 +186,25 @@ export async function summarizeBlock() {
   }
 }
 
+export async function customPromptBlock() {
+  try {
+    if (!logseq.settings) {
+      throw new Error("Couldn't find ollama-logseq settings")
+    }
+  
+    // TODO: Get contnet of current block and subblocks
+    const currentBlock = await logseq.Editor.getCurrentBlock()
+    let customPromptBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, `⌛Apply custom prompt...`, { before: false })
+    const customPrompt = await promptLLM(`${logseq.settings.custom_prompt_block} ${currentBlock!.content}`);
+     
+    await logseq.Editor.updateBlock(customPromptBlock!.uuid, `${customPrompt}`)
+  } catch (e: any) {
+    logseq.App.showMsg(e.toString(), 'warning')
+    console.error(e)
+  }
+}
+
+
 async function getOllamaParametersFromBlockProperties(b: BlockEntity) {
   const properties = await logseq.Editor.getBlockProperties(b.uuid);
   const ollamaParameters: OllamaGenerateParameters = {}
-- 
cgit v1.2.3

