Skip to content

Commit

Permalink
Added some polish touches before v1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
omagdy7 committed Dec 12, 2023
1 parent 689af97 commit 6b872e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 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.0.8",
"version": "1.0.9",
"main": "dist/index.html",
"scripts": {
"dev": "vite",
Expand Down
23 changes: 11 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,19 @@ function App() {
return
}

logseq.Editor.getPageBlocksTree("ollama-logseq-config").then((blocks) => {
blocks!.forEach((block) => {
logseq.Editor.getBlockProperty(block.uuid, "ollama-context-menu-title").then((title) => {
logseq.Editor.getBlockProperty(block.uuid, "ollama-prompt-prefix").then((prompt_prefix) => {
logseq.Editor.registerBlockContextMenuItem(title, promptFromBlockEventClosure(prompt_prefix))
logseq.Editor.getPageBlocksTree("ollama-logseq-config").then((blocks) => {
blocks!.forEach((block) => {
logseq.Editor.getBlockProperty(block.uuid, "ollama-context-menu-title").then((title) => {
logseq.Editor.getBlockProperty(block.uuid, "ollama-prompt-prefix").then((prompt_prefix) => {
logseq.Editor.registerBlockContextMenuItem(title, promptFromBlockEventClosure(prompt_prefix))
})
}).catch((reason) => {
})
})
}).catch((reason) => {
console.error("Can not find the configuration page named 'ollama-logseq-config'", reason)
})
})
}).catch((reason) => {
console.log("Can not find the configuration page named 'ollama-logseq-config'")
console.log(reason)
})



logseq.Editor.registerSlashCommand("ollama", ollamaUI)
logseq.Editor.registerBlockContextMenuItem("Ollama: Create a flash card", convertToFlashCardFromEvent)
Expand All @@ -70,7 +69,7 @@ logseq.Editor.getPageBlocksTree("ollama-logseq-config").then((blocks) => {
logseq.App.registerCommandShortcut(
{ "binding": logseq.settings.shortcut },
ollamaUI
);
);
}, [])

if (visible) {
Expand Down
15 changes: 6 additions & 9 deletions src/ollama.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,32 +199,29 @@ async function getOllamaParametersFromBlockProperties(b: BlockEntity) {
}

async function getOllamaParametersFromBlockAndParentProperties(b: BlockEntity) {
let p_params: OllamaGenerateParameters = {}
let ollamaParentProperties: OllamaGenerateParameters = {}
if (b.parent) {
let parentBlock = await logseq.Editor.getBlock(b.parent.id)
if (parentBlock)
p_params = await getOllamaParametersFromBlockProperties(parentBlock)
ollamaParentProperties = await getOllamaParametersFromBlockProperties(parentBlock)
}
const b_params = await getOllamaParametersFromBlockProperties(b)
return {...p_params, ...b_params}
const ollamaBlockProperties = await getOllamaParametersFromBlockProperties(b)
return { ...ollamaParentProperties, ...ollamaBlockProperties }
}

async function promptFromBlock(block: BlockEntity, prefix?: string) {
const answerBlock = await logseq.Editor.insertBlock(block!.uuid, '🦙Generating ...', { before: false })
const params = await getOllamaParametersFromBlockAndParentProperties(block!)
console.log("ollama params", params)

let prompt = block!.content.replace(/^.*::.*$/gm, '') // hack to remove properties from block content
if (prefix) {
prompt = prefix + " " + prompt
}
console.log("prompt", prompt)

const result = await ollamaGenerate(prompt, params);

console.log("ollama response", result)

if (params.usecontext) { //FIXME: work out the best way to story context
//FIXME: work out the best way to story context
if (params.usecontext) {
await logseq.Editor.upsertBlockProperty(block!.uuid, 'ollama-generate-context', result.context)
}

Expand Down

0 comments on commit 6b872e1

Please sign in to comment.