Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a "Summarize Block" command #7

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const options = [
'Define',
'Divide into subtasks',
'Summarize',
'Summarize Block',
'Convert to flash card',
];

Expand Down
6 changes: 5 additions & 1 deletion src/components/OllamaCommandPallete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions src/ollama.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -253,3 +269,5 @@ export async function DivideTaskIntoSubTasks() {
console.error(e)
}
}