Skip to content

Commit

Permalink
Merge pull request #8 from taweili/master
Browse files Browse the repository at this point in the history
Add Prompt from Block Context Menu Command
  • Loading branch information
omagdy7 authored Nov 29, 2023
2 parents e579a11 + 37c7024 commit bce51cc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/ollama.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bce51cc

Please sign in to comment.