aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmar Magdy <99906646+omagdy7@users.noreply.github.com>2023-11-23 18:30:38 +0200
committerGitHub <noreply@github.com>2023-11-23 18:30:38 +0200
commit13b20a208205f5682f50b6ea1f5d010aea7a7e7c (patch)
tree5e7e735899f84c5a7b9288bcc7030eaf4d256df0 /src
parentf3d8e7abd1d23f744a94b672d50b03ec83ae37df (diff)
parent24d83897baa959c7dca5ed746a9beb9aff044f68 (diff)
downloadollama-logseq-13b20a208205f5682f50b6ea1f5d010aea7a7e7c.tar.xz
ollama-logseq-13b20a208205f5682f50b6ea1f5d010aea7a7e7c.zip
Merge pull request #7 from taweili/master
Adding a "Summarize Block" command
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx1
-rw-r--r--src/components/OllamaCommandPallete.tsx6
-rw-r--r--src/ollama.tsx18
3 files changed, 24 insertions, 1 deletions
diff --git a/src/App.tsx b/src/App.tsx
index c88108d..bd6aaa0 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -10,6 +10,7 @@ const options = [
'Define',
'Divide into subtasks',
'Summarize',
+ 'Summarize Block',
'Convert to flash card',
];
diff --git a/src/components/OllamaCommandPallete.tsx b/src/components/OllamaCommandPallete.tsx
index 0ee8097..b251318 100644
--- a/src/components/OllamaCommandPallete.tsx
+++ b/src/components/OllamaCommandPallete.tsx
@@ -6,7 +6,7 @@ import {
CommandItem,
CommandList,
} from "@/components/ui/command"
-import { convertToFlashCard, DivideTaskIntoSubTasks, summarize } from "@/ollama";
+import { convertToFlashCard, DivideTaskIntoSubTasks, summarize, summarizeBlock } from "@/ollama";
import { PromptAI } from "./PromptAI";
export function OllamaCommandPallete({ options, theme }: { options: string[], theme: string }) {
@@ -24,6 +24,10 @@ export function OllamaCommandPallete({ options, theme }: { options: string[], th
logseq.hideMainUI()
summarize()
break;
+ case "summarize block":
+ logseq.hideMainUI()
+ summarizeBlock()
+ break;
case "convert to flash card":
logseq.hideMainUI()
convertToFlashCard()
diff --git a/src/ollama.tsx b/src/ollama.tsx
index 07d3f04..a2a078d 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -144,6 +144,22 @@ export async function summarize() {
}
}
+export async function summarizeBlock() {
+ try {
+ const currentBlock = await logseq.Editor.getCurrentBlock()
+ if (currentBlock) {
+ let summaryBlock = await logseq.Editor.insertBlock(currentBlock.uuid, `⌛Summarizing Block...`, { before: true })
+ if (summaryBlock) {
+ 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')
+ console.error(e)
+ }
+}
+
export async function askAI(prompt: string) {
await delay(300)
try {
@@ -253,3 +269,5 @@ export async function DivideTaskIntoSubTasks() {
console.error(e)
}
}
+
+