aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Li <taweili@gmail.com>2023-12-04 14:13:07 +0800
committerDavid Li <taweili@gmail.com>2023-12-04 14:13:07 +0800
commit5edf9a522deaed225d15724fe32d65124a5af590 (patch)
tree69a9106c5af06bbe34260105abfad8247f7cc876 /src
parentec89527bec8727ca8a6f897c449751cd6856d859 (diff)
downloadollama-logseq-5edf9a522deaed225d15724fe32d65124a5af590.tar.xz
ollama-logseq-5edf9a522deaed225d15724fe32d65124a5af590.zip
Use the ollama properties from the parent block
Diffstat (limited to 'src')
-rw-r--r--src/ollama.tsx19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/ollama.tsx b/src/ollama.tsx
index 38cb0f6..c6db897 100644
--- a/src/ollama.tsx
+++ b/src/ollama.tsx
@@ -198,15 +198,26 @@ async function getOllamaParametersFromBlockProperties(b: BlockEntity) {
return ollamaParameters
}
-export async function promptFromBlockEvent(b: IHookEvent) {
+export async function promptFromBlockEvent(event: IHookEvent) {
try {
- const currentBlock = await logseq.Editor.getBlock(b.uuid)
+ const currentBlock = await logseq.Editor.getBlock(event.uuid)
const answerBlock = await logseq.Editor.insertBlock(currentBlock!.uuid, '🦙Generating ...', { before: false })
- const params = await getOllamaParametersFromBlockProperties(currentBlock!)
+ let p_params: OllamaGenerateParameters = {}
+
+ if (currentBlock?.parent) {
+ let parentBlock = await logseq.Editor.getBlock(currentBlock.parent.id)
+ if (parentBlock)
+ p_params = await getOllamaParametersFromBlockProperties(parentBlock)
+ }
+ const c_params = await getOllamaParametersFromBlockProperties(currentBlock!)
+ const params = { ...p_params, ...c_params }
+
+ console.log("params", params)
+
const prompt = currentBlock!.content.replace(/^.*::.*$/gm, '') // nasty hack to remove properties from block content
const result = await ollamaGenerate(prompt, params);
- console.log(result)
+ console.log("result", result)
if (params.usecontext) {
await logseq.Editor.upsertBlockProperty(currentBlock!.uuid, 'ollama-generate-context', result.context)