Skip to content

Commit

Permalink
fix: fixed a bug where custom prompts on block doesn't take into cont…
Browse files Browse the repository at this point in the history
…ext all children of the block
  • Loading branch information
omagdy7 committed Feb 27, 2024
1 parent a81ae99 commit e24c87f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ollama-logseq",
"version": "1.1.2",
"version": "1.1.3",
"main": "dist/index.html",
"scripts": {
"dev": "vite",
Expand Down
17 changes: 10 additions & 7 deletions src/ollama.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function getTreeContent(b: BlockEntity) {
includeChildren: true,
});
if (childBlock) {
content += await getTreeContent(childBlock);
content += "\n" + await getTreeContent(childBlock);
}
}
}
Expand Down Expand Up @@ -93,14 +93,14 @@ async function ollamaGenerate(prompt: string, parameters?: OllamaGenerateParamet
body: JSON.stringify(params)
})
if (!response.ok) {
logseq.UI.showMsg("Coudln't fulfull request make sure that ollama service is running and make sure there is no typo in host or model name")
logseq.UI.showMsg("Coudln't fulfill request make sure that ollama service is running and make sure there is no typo in host or model name")
throw new Error("Error in Ollama request: " + response.statusText)
}
const data = await response.json()
return data
} catch (e: any) {
console.error("ERROR: ", e)
logseq.App.showMsg("Coudln't fulfull request make sure that ollama service is running and make sure there is no typo in host or model name")
logseq.App.showMsg("Coudln't fulfill request make sure that ollama service is running and make sure there is no typo in host or model name")
}
}

Expand All @@ -121,15 +121,15 @@ async function promptLLM(prompt: string) {
}),
})
if (!response.ok) {
logseq.App.showMsg("Coudln't fulfull request make sure that ollama service is running and make sure there is no typo in host or model name")
logseq.App.showMsg("Coudln't fulfill request make sure that ollama service is running and make sure there is no typo in host or model name")
throw new Error("Error in Ollama request: " + response.statusText)
}
const data = await response.json();

return data.response;
} catch (e: any) {
console.error("ERROR: ", e)
logseq.App.showMsg("Coudln't fulfull request make sure that ollama service is running and make sure there is no typo in host or model name")
logseq.App.showMsg("Coudln't fulfill request make sure that ollama service is running and make sure there is no typo in host or model name")
}
}

Expand Down Expand Up @@ -221,10 +221,13 @@ async function getOllamaParametersFromBlockAndParentProperties(b: BlockEntity) {
async function promptFromBlock(block: BlockEntity, prefix?: string) {
const answerBlock = await logseq.Editor.insertBlock(block!.uuid, '🦙Generating ...', { before: false })
const params = await getOllamaParametersFromBlockAndParentProperties(block!)
const blockContent = await getTreeContent(block);

let prompt = block!.content.replace(/^.*::.*$/gm, '') // hack to remove properties from block content
// let prompt = block!.content.replace(/^.*::.*$/gm, '') // hack to remove properties from block content

let prompt = blockContent;
if (prefix) {
prompt = prefix + " " + prompt
prompt = prefix + "\n" + prompt
}

const result = await ollamaGenerate(prompt, params);
Expand Down

0 comments on commit e24c87f

Please sign in to comment.