diff options
| author | David Li <taweili@gmail.com> | 2023-11-29 21:32:21 +0800 |
|---|---|---|
| committer | David Li <taweili@gmail.com> | 2023-11-29 21:32:21 +0800 |
| commit | 6c7a7bd3db97c0252cf5852355ea95831db2f121 (patch) | |
| tree | a1756ad3f5e2e9914c45f8227ec397ce9159167a | |
| parent | ae5393ca00d4c81e22ff4fb2d68174b57347155f (diff) | |
| download | ollama-logseq-6c7a7bd3db97c0252cf5852355ea95831db2f121.tar.xz ollama-logseq-6c7a7bd3db97c0252cf5852355ea95831db2f121.zip | |
Add Prompt from Block Context Menu Command and put
the Ollama response in the subblock.
| -rw-r--r-- | src/App.tsx | 3 | ||||
| -rw-r--r-- | src/ollama.tsx | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/App.tsx b/src/App.tsx index f9592a3..7366264 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef, useState } from "react"; import { OllamaCommandPallete } from "./components/OllamaCommandPallete"; -import { convertToFlashCardFromEvent, DivideTaskIntoSubTasksFromEvent, ollamaUI, summarizeBlockFromEvent } from "./ollama"; +import { convertToFlashCardFromEvent, DivideTaskIntoSubTasksFromEvent, ollamaUI, summarizeBlockFromEvent, promptFromBlockEvent } from "./ollama"; import { useAppVisible } from "./utils"; const options = [ @@ -43,6 +43,7 @@ function App() { logseq.Editor.registerBlockContextMenuItem("Create a flash card", convertToFlashCardFromEvent) logseq.Editor.registerBlockContextMenuItem("Summarize block", summarizeBlockFromEvent) logseq.Editor.registerBlockContextMenuItem("Divide into subtasks", DivideTaskIntoSubTasksFromEvent) + logseq.Editor.registerBlockContextMenuItem("Prompt from Block", promptFromBlockEvent) logseq.App.registerCommandShortcut( { "binding": logseq.settings.shortcut }, ollamaUI 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 { |
