aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-12-12 13:26:28 +0200
committeromagdy7 <omar.professional8777@gmail.com>2023-12-12 13:26:28 +0200
commit6b872e11c7925df85a2e14f56429c6d4c8b88891 (patch)
tree22b1135d4a0f6cba75a953ab287b5c436d3f72ae /src
parent689af97a41afc5f709c948dbf463287558caca9f (diff)
downloadollama-logseq-6b872e11c7925df85a2e14f56429c6d4c8b88891.tar.xz
ollama-logseq-6b872e11c7925df85a2e14f56429c6d4c8b88891.zip
Added some polish touches before v1.0.9
Diffstat (limited to 'src')
-rw-r--r--src/App.tsx23
-rw-r--r--src/ollama.tsx15
2 files changed, 17 insertions, 21 deletions
diff --git a/src/App.tsx b/src/App.tsx
index b6b6918..0a32968 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -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)
@@ -70,7 +69,7 @@ logseq.Editor.getPageBlocksTree("ollama-logseq-config").then((blocks) => {
logseq.App.registerCommandShortcut(
{ "binding": logseq.settings.shortcut },
ollamaUI
- );
+ );
}, [])
if (visible) {
diff --git a/src/ollama.tsx b/src/ollama.tsx
index 5ba47ab..9d925db 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -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)
}