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 fea2222c..ff62af75 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 @@ -90,6 +90,7 @@ import { journals_func } from '$lib/ae_journals/ae_journals_functions'; import Comp_journal_entry_file_li from './ae_comp__journal_entry_obj_file_li.svelte'; import Comp_hosted_files_download_button from '$lib/ae_core/ae_comp__hosted_files_download_button.svelte'; + import JournalEntry_AITools from './JournalEntry_AITools.svelte'; // *** Configuration let llm_api_token = @@ -1865,108 +1866,7 @@ $lq__journal_entry_obj?.journal_entry_id ] == 'current'} > - {#if $journals_sess?.entry?.ai_summary} - { - $journals_sess.entry.show__ai_summary = - !$journals_sess.entry.show__ai_summary; - }} - class="btn btn-sm preset-tonal-primary hover:preset-filled-primary-500 transition-all absolute top-2 right-2 z-10" - title="Toggle AI Summary" - > - - AI Summary - {#if $journals_sess?.entry?.ai_summary} - - {$journals_sess?.entry?.ai_summary.split(' ').length} words - - {/if} - - {:else if !$journals_sess?.entry?.show__ai_summary && $journals_sess?.entry?.ai_summary} - { - const ai_client = new OpenAI({ - apiKey: $journals_loc?.llm__api_token, - baseURL: $journals_loc?.llm__api_base_url, - dangerouslyAllowBrowser: $journals_loc?.llm__api_dangerous_browser - }); - - // let resp__models = ai_client.models.list(); - // console.log('AI API Response (models)', resp__models); - - // let msg_role_system_content = $journals_loc?.entry?.llm__system_prompt || 'You are a helpful assistant that helps people find information.'; - // let msg_role_user_content = 'Why is the sky blue?'; - let msg_role_user_content = tmp_entry_obj?.content; - - 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} - { - $journals_sess.entry.ai_summary = $lq__journal_entry_obj?.summary; - $journals_sess.entry.show__ai_summary = true; - }} - class=" - btn btn-sm preset-tonal-primary hover:preset-filled-primary-500 transition-all absolute top-2 right-2 z-10 - " - title="Show saved summary of this journal entry" - > - - Use Saved Summary - - {/if} + {#if !$journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id]} {#if $lq__journal_obj?.cfg_json?.pref_viewer == 'codemirror'} @@ -2346,169 +2246,7 @@ - {#if $journals_sess?.entry?.show__ai_summary && $journals_sess?.entry?.ai_summary} - - - - { - tmp_entry_obj.summary = $journals_sess?.entry?.ai_summary || ''; - update_journal_entry(); - }} - title="Save AI summary as Journal Entry summary" - > - - Save - - - { - $journals_sess.entry.show__ai_summary = - !$journals_sess.entry.show__ai_summary; - }} - class="btn btn-sm preset-tonal-primary hover:preset-filled-primary-500 transition-all" - title="Toggle AI Summary" - > - - AI Summary - {#if $journals_sess?.entry?.ai_summary} - - {$journals_sess?.entry?.ai_summary.split(' ').length} words - - {/if} - - - { - const ai_client = new OpenAI({ - apiKey: $journals_loc?.llm__api_token, - baseURL: $journals_loc?.llm__api_base_url, - dangerouslyAllowBrowser: - $journals_loc?.llm__api_dangerous_browser - }); - - let msg_role_user_content = tmp_entry_obj?.content; - - 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-outlined-warning-200-800 - transition-all - " - title="Generate AI summary of this journal entry" - > - {#await ae_promises} - - Summarizing... - {:then} - - Re-Summarize - {:catch error} - Error - {/await} - - - - { - $journals_sess.entry.hide__ai_summary = - !$journals_sess.entry.hide__ai_summary; - }} - > - - Prompt - - - - LLM System Prompt for Journal Entry summarization: - - - - - - - - {/if} + {:else}