From 6c7a7bd3db97c0252cf5852355ea95831db2f121 Mon Sep 17 00:00:00 2001 From: David Li 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/App.tsx | 3 ++- src/ollama.tsx | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') 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 { -- cgit v1.2.3