aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmar Magdy <99906646+omagdy7@users.noreply.github.com>2023-11-29 20:26:25 +0200
committerGitHub <noreply@github.com>2023-11-29 20:26:25 +0200
commitbce51cc3288da8cdded68c87eb9ee2553df08286 (patch)
tree18226e2e5f4ecbd13eb9dc65c509dee9ded94fe7 /src
parente579a114f7e17bbebe3aa185b23e7437a79b5813 (diff)
parent37c7024b4b4f5afcb00cb0bd6369e2850a4e12c5 (diff)
downloadollama-logseq-bce51cc3288da8cdded68c87eb9ee2553df08286.tar.xz
ollama-logseq-bce51cc3288da8cdded68c87eb9ee2553df08286.zip
Merge pull request #8 from taweili/master
Add Prompt from Block Context Menu Command
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx9
-rw-r--r--src/ollama.tsx24
2 files changed, 32 insertions, 1 deletions
diff --git a/src/App.tsx b/src/App.tsx
index f9592a3..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 } from "./ollama";
+import { convertToFlashCardFromEvent,
+ DivideTaskIntoSubTasksFromEvent,
+ ollamaUI,
+ summarizeBlockFromEvent,
+ promptFromBlockEvent,
+ expandBlockEvent } from "./ollama";
import { useAppVisible } from "./utils";
const options = [
@@ -43,6 +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("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 f5eaae7..945d2cb 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -149,6 +149,30 @@ 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 })
+ 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 {