aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx1
-rw-r--r--src/components/OllamaCommandPallete.tsx6
-rw-r--r--src/main.tsx7
-rw-r--r--src/ollama.tsx20
4 files changed, 33 insertions, 1 deletions
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 = {}