diff options
| author | David Li <taweili@gmail.com> | 2023-11-29 23:33:49 +0800 |
|---|---|---|
| committer | David Li <taweili@gmail.com> | 2023-11-29 23:33:49 +0800 |
| commit | 37c7024b4b4f5afcb00cb0bd6369e2850a4e12c5 (patch) | |
| tree | e1eff225c4dfca76cc5a93522c0eb821483aef8b /src | |
| parent | 6c7a7bd3db97c0252cf5852355ea95831db2f121 (diff) | |
| download | ollama-logseq-37c7024b4b4f5afcb00cb0bd6369e2850a4e12c5.tar.xz ollama-logseq-37c7024b4b4f5afcb00cb0bd6369e2850a4e12c5.zip | |
Expanding the content of the block with AI
Diffstat (limited to 'src')
| -rw-r--r-- | src/App.tsx | 10 | ||||
| -rw-r--r-- | src/ollama.tsx | 19 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/App.tsx b/src/App.tsx index 7366264..b902629 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,11 @@ import React, { useEffect, useRef, useState } from "react"; import { OllamaCommandPallete } from "./components/OllamaCommandPallete"; -import { convertToFlashCardFromEvent, DivideTaskIntoSubTasksFromEvent, ollamaUI, summarizeBlockFromEvent, promptFromBlockEvent } from "./ollama"; +import { convertToFlashCardFromEvent, + DivideTaskIntoSubTasksFromEvent, + ollamaUI, + summarizeBlockFromEvent, + promptFromBlockEvent, + expandBlockEvent } from "./ollama"; import { useAppVisible } from "./utils"; const options = [ @@ -43,7 +48,8 @@ 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.Editor.registerBlockContextMenuItem("Ollama: Prompt from Block", promptFromBlockEvent) + logseq.Editor.registerBlockContextMenuItem("Ollama: Expand Block", expandBlockEvent) logseq.App.registerCommandShortcut( { "binding": logseq.settings.shortcut }, ollamaUI diff --git a/src/ollama.tsx b/src/ollama.tsx index c515574..945d2cb 100644 --- a/src/ollama.tsx +++ b/src/ollama.tsx @@ -152,16 +152,27 @@ 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}`) + const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating ...', { before: false }) + const response = await promptLLM(`${currentBlock!.content}`); + await logseq.Editor.updateBlock(answerBlock!.uuid, `${response}`) } catch (e: any) { logseq.UI.showMsg(e.toString(), 'warning') console.error(e) } } +export async function expandBlockEvent(b: IHookEvent) { + try { + const currentBlock = await logseq.Editor.getBlock(b.uuid) + const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating ...', { before: false }) + const response = await promptLLM(`Expand: ${currentBlock!.content}`); + await logseq.Editor.updateBlock(answerBlock!.uuid, `${response}`) + } catch(e: any) { + logseq.UI.showMsg(e.toString(), 'warning') + console.error(e) + } +} + export async function askAI(prompt: string, context: string) { await delay(300) try { |
