From c530ff86834f9a3f284f88384692136cf7a06eb1 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Mon, 15 Sep 2025 18:09:37 -0400 Subject: [PATCH] Work on AI related. --- .../ae_comp__journal_entry_obj_id_view.svelte | 275 ++++++++++++++---- .../journals/modal_journals_config.svelte | 36 ++- 2 files changed, 247 insertions(+), 64 deletions(-) diff --git a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte index 0dda9db5..d6c2a6f4 100644 --- a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte +++ b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte @@ -10,7 +10,7 @@ import { BookHeart, Bot, BotMessageSquare, BriefcaseBusiness, CalendarClock, CalendarOff, Clock, CodeXml, Copy, Eye, EyeOff, - Flag, FlagOff, FileDown, FileX, Fingerprint, + Flag, FlagOff, FileDown, FilePenLine, FileText, FileX, Fingerprint, Globe, Group, Hash, History, Loader, LockKeyhole, LockKeyholeOpen, @@ -333,6 +333,7 @@ async function update_journal_entry() { // alert_msg: $lq__journal_entry_obj?.alert_msg ? false : true alert_msg: tmp_entry_obj?.alert_msg, category_code: tmp_entry_obj?.category_code, + summary: tmp_entry_obj?.summary, content: tmp_entry_obj?.content, content_encrypted: null, // This should only be generated below. history: tmp_entry_obj?.history, @@ -1780,6 +1781,23 @@ $effect(() => { Show + {:else if !$journals_sess?.entry?.show__ai_summary && $lq__journal_entry_obj?.summary} + {/if} @@ -2105,68 +2123,84 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} --> {/if} {:else} - + try { + ae_promises = ai_client.chat.completions.create( + { + model: $journals_loc?.llm__api_model, + messages: [ + { role: 'system', content: $journals_loc?.entry?.llm__system_prompt || 'You are a helpful assistant that helps people find information.' }, + { role: "user", content: msg_role_user_content } + ], + // max_tokens: 512, + // temperature: 0.7, + // stream: true, + } + ) + .then ((resp__chat) => { + console.log('AI API Response (chat)', resp__chat); + console.log('AI API Response (chat)', resp__chat); + + console.log('resp msg 0 = ', resp__chat?.choices?.[0]?.message?.content); + + $journals_sess.entry.ai_summary = resp__chat?.choices?.[0]?.message?.content || 'No summary available'; + + $journals_sess.entry.show__ai_summary = true; + return; + }); + + + } catch (err) { + console.error('Error from chat completion:', err); + alert('Error from chat completion: ' + (err?.message || err)); + } + }} + class="btn btn-sm preset-tonal-primary hover:preset-filled-primary-500 transition-all absolute top-2 right-2 z-10" + title="Generate AI summary of this journal entry" + > + {#await ae_promises} + + Summarizing... + {:then} + + Summarize + {:catch error} + Error + {/await} + + {:else if !$journals_sess?.entry?.show__ai_summary && $lq__journal_entry_obj?.summary} + + {/if} {/if} @@ -2686,12 +2720,27 @@ zzzz class="top-center bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 rounded-lg border-gray-200 dark:border-gray-700 divide-gray-200 dark:divide-gray-700 shadow-md relative mx-auto w-full divide-y" >