aboutsummaryrefslogtreecommitdiff
path: root/src/ollama.tsx
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2024-02-22 19:12:22 +0200
committeromagdy7 <omar.professional8777@gmail.com>2024-02-22 19:12:22 +0200
commit481ae0c24785a1798a0445a2a982acce6db7e4f2 (patch)
treea196dc99bc09b0ffe6a01a99d45b5efab0bf9e4d /src/ollama.tsx
parent4f1971020d43d0958973712212f17bd9d51a1834 (diff)
downloadollama-logseq-481ae0c24785a1798a0445a2a982acce6db7e4f2.tar.xz
ollama-logseq-481ae0c24785a1798a0445a2a982acce6db7e4f2.zip
Added the ability to Ask in context of the block only instead of the whole page
Diffstat (limited to 'src/ollama.tsx')
-rw-r--r--src/ollama.tsx25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/ollama.tsx b/src/ollama.tsx
index e59c633..c0c27e2 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -134,16 +134,22 @@ async function promptLLM(prompt: string) {
}
export async function defineWord(word: string) {
- askAI(`What's the defintion of ${word}`, "")
+ askAI(`What's the defintion of ${word}?`, "")
}
+type ContextType = 'block' | 'page'
-export async function askWithContext(prompt: string) {
+export async function askWithContext(prompt: string, contextType: ContextType) {
try {
- const currentBlocksTree = await logseq.Editor.getCurrentPageBlocksTree()
let blocksContent = ""
- for (const block of currentBlocksTree) {
- blocksContent += await getTreeContent(block)
+ if (contextType === 'page') {
+ const currentBlocksTree = await logseq.Editor.getCurrentPageBlocksTree()
+ for (const block of currentBlocksTree) {
+ blocksContent += await getTreeContent(block)
+ }
+ } else {
+ const currentBlock = await logseq.Editor.getCurrentBlock()
+ blocksContent += await getTreeContent(currentBlock!)
}
askAI(prompt, `Context: ${blocksContent}`)
} catch (e: any) {
@@ -152,7 +158,7 @@ export async function askWithContext(prompt: string) {
}
}
-export async function summarize() {
+export async function summarizePage() {
await delay(300)
try {
const currentSelectedBlocks = await logseq.Editor.getCurrentPageBlocksTree()
@@ -247,7 +253,12 @@ export async function askAI(prompt: string, context: string) {
await delay(300)
try {
const currentBlock = await logseq.Editor.getCurrentBlock()
- const block = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating....', { before: true })
+ let block = null;
+ if (currentBlock?.content.trim() === '') {
+ block = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating....', { before: true })
+ } else {
+ block = await logseq.Editor.insertBlock(currentBlock!.uuid, '⌛Generating....', { before: false })
+ }
let response = "";
if (context == "") {
response = await promptLLM(prompt)