From fc1d6985c9eb0c31b8ea05244e4a270d9ec8ffaa Mon Sep 17 00:00:00 2001 From: gixita 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/App.tsx | 1 + src/components/OllamaCommandPallete.tsx | 6 +++++- src/main.tsx | 7 +++++++ src/ollama.tsx | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/App.tsx b/src/App.tsx index 0a32968..0fb9984 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,6 +15,7 @@ const options = [ 'Divide into subtasks', 'Summarize', 'Summarize Block', + 'Custom prompt on block', 'Convert to flash card', ]; diff --git a/src/components/OllamaCommandPallete.tsx b/src/components/OllamaCommandPallete.tsx index e8e9c42..d721892 100644 --- a/src/components/OllamaCommandPallete.tsx +++ b/src/components/OllamaCommandPallete.tsx @@ -6,7 +6,7 @@ import { CommandItem, CommandList, } from "@/components/ui/command" -import { convertToFlashCardCurrentBlock, DivideTaskIntoSubTasksCurrentBlock, summarize, summarizeBlock } from "@/ollama"; +import { convertToFlashCardCurrentBlock, DivideTaskIntoSubTasksCurrentBlock, summarize, summarizeBlock, customPromptBlock } from "@/ollama"; import { PromptAI } from "./PromptAI"; export function OllamaCommandPallete({ options, theme }: { options: string[], theme: string }) { @@ -28,6 +28,10 @@ export function OllamaCommandPallete({ options, theme }: { options: string[], th logseq.hideMainUI() summarizeBlock() break; + case "custom prompt on block": + logseq.hideMainUI() + customPromptBlock() + break; case "convert to flash card": logseq.hideMainUI() convertToFlashCardCurrentBlock() diff --git a/src/main.tsx b/src/main.tsx index a78d85d..a544760 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -36,6 +36,13 @@ let settings: SettingSchemaDesc[] = [ description: "Shortcut to open plugin command pallete", default: "mod+shift+o" }, + { + key: "custom_prompt_block", + type: "string", + title: "Custom prompt block", + description: "Define your custom prompt and use a block as context", + default: "Translate in French : " + }, ] 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 From fe8403156aa664c8fb203bddc243eb6fc4448b1a Mon Sep 17 00:00:00 2001 From: gixita Date: Sat, 10 Feb 2024 15:03:39 +0100 Subject: Move the custom prompt trigger on the block command --- src/App.tsx | 2 +- src/components/OllamaCommandPallete.tsx | 6 +----- src/main.tsx | 7 ------- src/ollama.tsx | 17 ----------------- 4 files changed, 2 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/App.tsx b/src/App.tsx index 0fb9984..230bc80 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,7 +15,6 @@ const options = [ 'Divide into subtasks', 'Summarize', 'Summarize Block', - 'Custom prompt on block', 'Convert to flash card', ]; @@ -64,6 +63,7 @@ function App() { logseq.Editor.registerBlockContextMenuItem("Ollama: Create a flash card", convertToFlashCardFromEvent) logseq.Editor.registerBlockContextMenuItem("Ollama: Divide into subtasks", DivideTaskIntoSubTasksFromEvent) logseq.Editor.registerBlockContextMenuItem("Ollama: Prompt from Block", promptFromBlockEventClosure()) + logseq.Editor.registerBlockContextMenuItem("Ollama: Custom prompt on Block", promptFromBlockEventClosure(logseq.settings.custom_prompt_block)) logseq.Editor.registerBlockContextMenuItem("Ollama: Summarize block", promptFromBlockEventClosure("Summarize: ")) logseq.Editor.registerBlockContextMenuItem("Ollama: Expand Block", promptFromBlockEventClosure("Expand: ")) diff --git a/src/components/OllamaCommandPallete.tsx b/src/components/OllamaCommandPallete.tsx index d721892..e8e9c42 100644 --- a/src/components/OllamaCommandPallete.tsx +++ b/src/components/OllamaCommandPallete.tsx @@ -6,7 +6,7 @@ import { CommandItem, CommandList, } from "@/components/ui/command" -import { convertToFlashCardCurrentBlock, DivideTaskIntoSubTasksCurrentBlock, summarize, summarizeBlock, customPromptBlock } from "@/ollama"; +import { convertToFlashCardCurrentBlock, DivideTaskIntoSubTasksCurrentBlock, summarize, summarizeBlock } from "@/ollama"; import { PromptAI } from "./PromptAI"; export function OllamaCommandPallete({ options, theme }: { options: string[], theme: string }) { @@ -28,10 +28,6 @@ export function OllamaCommandPallete({ options, theme }: { options: string[], th logseq.hideMainUI() summarizeBlock() break; - case "custom prompt on block": - logseq.hideMainUI() - customPromptBlock() - break; case "convert to flash card": logseq.hideMainUI() convertToFlashCardCurrentBlock() diff --git a/src/main.tsx b/src/main.tsx index a544760..a78d85d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -36,13 +36,6 @@ let settings: SettingSchemaDesc[] = [ description: "Shortcut to open plugin command pallete", default: "mod+shift+o" }, - { - key: "custom_prompt_block", - type: "string", - title: "Custom prompt block", - description: "Define your custom prompt and use a block as context", - default: "Translate in French : " - }, ] diff --git a/src/ollama.tsx b/src/ollama.tsx index 4fe697f..e59c633 100644 --- a/src/ollama.tsx +++ b/src/ollama.tsx @@ -186,23 +186,6 @@ 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) { -- cgit v1.2.3 From f07b00c527db2947f49d4ea592018902d391d55f Mon Sep 17 00:00:00 2001 From: gixita Date: Sat, 10 Feb 2024 15:11:39 +0100 Subject: Add a custom prompt configuration field in the plugin settings --- src/main.tsx | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/main.tsx b/src/main.tsx index a78d85d..a544760 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -36,6 +36,13 @@ let settings: SettingSchemaDesc[] = [ description: "Shortcut to open plugin command pallete", default: "mod+shift+o" }, + { + key: "custom_prompt_block", + type: "string", + title: "Custom prompt block", + description: "Define your custom prompt and use a block as context", + default: "Translate in French : " + }, ] -- cgit v1.2.3