Work on AI related.
This commit is contained in:
@@ -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(() => {
|
||||
<span class="text-sm">
|
||||
Show</span>
|
||||
</button>
|
||||
{:else if !$journals_sess?.entry?.show__ai_summary && $lq__journal_entry_obj?.summary}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
$journals_sess.entry.ai_summary = $lq__journal_entry_obj?.summary;
|
||||
$journals_sess.entry.show__ai_summary = true;
|
||||
}}
|
||||
class="
|
||||
btn btn-sm
|
||||
preset-outlined-warning-200-800
|
||||
transition-all
|
||||
"
|
||||
title="Show saved summary of this journal entry"
|
||||
>
|
||||
<FileText strokeWidth="1" class="inline-block mr-1" />
|
||||
Use Saved Summary
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -2105,68 +2123,84 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} -->
|
||||
{/if}
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
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,
|
||||
{#if !$journals_sess?.entry?.show__ai_summary && $journals_sess?.entry?.ai_summary}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
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;
|
||||
});
|
||||
|
||||
// let resp__models = ai_client.models.list();
|
||||
// console.log('AI API Response (models)', resp__models);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error from chat completion:', err);
|
||||
alert('Error from chat completion: ' + (err?.message || err));
|
||||
}
|
||||
// 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;
|
||||
|
||||
}}
|
||||
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}
|
||||
<Loader class="inline-block mr-1 animate-spin" />
|
||||
<span class="text-sm">Summarizing...</span>
|
||||
{:then}
|
||||
<BotMessageSquare class="inline-block mr-1" />
|
||||
<span class="text-sm">Summarize</span>
|
||||
{:catch error}
|
||||
<span class="text-sm">Error</span>
|
||||
{/await}
|
||||
</button>
|
||||
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}
|
||||
<Loader class="inline-block mr-1 animate-spin" />
|
||||
<span class="text-sm">Summarizing...</span>
|
||||
{:then}
|
||||
<BotMessageSquare class="inline-block mr-1" />
|
||||
<span class="text-sm">Summarize</span>
|
||||
{:catch error}
|
||||
<span class="text-sm">Error</span>
|
||||
{/await}
|
||||
</button>
|
||||
{:else if !$journals_sess?.entry?.show__ai_summary && $lq__journal_entry_obj?.summary}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
$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"
|
||||
>
|
||||
<FileText strokeWidth="1" class="inline-block mr-1" />
|
||||
Use Saved Summary
|
||||
</button>
|
||||
{/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"
|
||||
>
|
||||
<div class="modal-box flex flex-col gap-2 items-center justify-center">
|
||||
<div class="flex flex-row flex-wrap gap-1 items-center justify-center w-full mb-2">
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm preset-tonal-success hover:preset-filled-success-500 transition-all"
|
||||
onclick={() => {
|
||||
tmp_entry_obj.summary = $journals_sess?.entry?.ai_summary || '';
|
||||
update_journal_entry();
|
||||
}}
|
||||
title="Save AI summary as Journal Entry summary"
|
||||
>
|
||||
<Save strokeWidth="1" class="inline-block mr-1" />
|
||||
Save
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
$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 *:hover:inline"
|
||||
class="btn btn-sm preset-tonal-primary hover:preset-filled-primary-500 transition-all"
|
||||
title="Toggle AI Summary"
|
||||
>
|
||||
<Bot class="inline-block mr-1" />
|
||||
@@ -2703,13 +2752,117 @@ zzzz
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onclick={async () => {
|
||||
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-outlined-warning-200-800
|
||||
transition-all
|
||||
"
|
||||
title="Generate AI summary of this journal entry"
|
||||
>
|
||||
{#await ae_promises}
|
||||
<Loader class="inline-block mr-1 animate-spin" />
|
||||
<span class="text-sm">Summarizing...</span>
|
||||
{:then}
|
||||
<BotMessageSquare class="inline-block mr-1" />
|
||||
<span class="text-sm">Re-Summarize</span>
|
||||
{:catch error}
|
||||
<span class="text-sm">Error</span>
|
||||
{/await}
|
||||
</button>
|
||||
|
||||
<!-- Change System Prompt: -->
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm preset-outlined-primary-400-600 hover:preset-filled-secondary-500 transition"
|
||||
onclick={() => {
|
||||
$journals_sess.entry.hide__ai_summary = !$journals_sess.entry.hide__ai_summary;
|
||||
}}
|
||||
>
|
||||
<FilePenLine strokeWidth="1.5" class="inline-block mr-1" />
|
||||
Prompt
|
||||
</button>
|
||||
|
||||
<label
|
||||
class:hidden={!$journals_sess.entry.hide__ai_summary}
|
||||
class="flex flex-col items-start justify-start gap-1 h-24"
|
||||
>
|
||||
LLM System Prompt for Journal Entry summarization:
|
||||
<E_app_codemirror_v5
|
||||
editable={true}
|
||||
readonly={false}
|
||||
content={$journals_loc?.entry?.llm__system_prompt}
|
||||
bind:new_content={$journals_loc.entry.llm__system_prompt}
|
||||
show_line_numbers={false}
|
||||
placeholder="LLM System Prompt"
|
||||
class="
|
||||
p-1
|
||||
preset-outlined-success-400-600
|
||||
shadow-lg rounded-lg
|
||||
"
|
||||
on:change={(e) => {
|
||||
$journals_loc.entry.llm__system_prompt = e.detail;
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- <pre class="text-wrap">
|
||||
{@html $journals_sess.entry.ai_summary}
|
||||
</pre> -->
|
||||
|
||||
<E_app_codemirror_v5
|
||||
editable={false}
|
||||
readonly={true}
|
||||
editable={true}
|
||||
readonly={false}
|
||||
content={$journals_sess.entry.ai_summary ?? ''}
|
||||
bind:new_content={$journals_sess.entry.ai_summary}
|
||||
bind:theme_mode={$ae_loc.theme_mode}
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
MessageSquareWarning, Minus,
|
||||
Notebook,
|
||||
Pencil, Plus,
|
||||
RemoveFormatting,
|
||||
RefreshCcw, RemoveFormatting,
|
||||
SquareLibrary,
|
||||
Shapes, Share2, ShieldCheck, ShieldMinus, Siren, Skull,
|
||||
Tags, Target, ToggleLeft, ToggleRight, Trash2, TypeOutline,
|
||||
@@ -31,8 +31,9 @@ import {
|
||||
} from '@lucide/svelte';
|
||||
import { Modal } from 'flowbite-svelte';
|
||||
|
||||
import E_app_codemirror_v5 from '$lib/e_app_codemirror_v5.svelte';
|
||||
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
|
||||
import { journals_loc, journals_sess, journals_slct, journals_prom, journals_trig } from '$lib/ae_journals/ae_journals_stores';
|
||||
import E_app_codemirror_v5 from '$lib/e_app_codemirror_v5.svelte';
|
||||
|
||||
</script>
|
||||
|
||||
@@ -208,6 +209,23 @@ import { journals_loc, journals_sess, journals_slct, journals_prom, journals_tri
|
||||
|
||||
<h3 class="font-semibold">LLM AI:</h3>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm preset-outlined-primary-400-600"
|
||||
onclick={() => {
|
||||
$journals_loc.llm__api_base_url = $ae_loc.site_cfg_json?.llm__api_base_url ?? 'https://ai.dgrzone.com/api';
|
||||
$journals_loc.llm__api_model = $ae_loc.site_cfg_json?.llm__api_model ?? 'dgrzone-deepseek-8b-quick';
|
||||
$journals_loc.llm__api_token = $ae_loc.site_cfg_json?.llm__api_token ?? '';
|
||||
$journals_loc.llm__api_dangerous_browser = $ae_loc.site_cfg_json?.llm__api_dangerous_browser ?? false;
|
||||
$journals_loc.entry.llm__system_prompt = $ae_loc.site_cfg_json?.llm__system_prompt ?? '';
|
||||
|
||||
|
||||
}}
|
||||
>
|
||||
<Copy class="inline-block mr-1" />
|
||||
LLM from Site Cfg
|
||||
</button>
|
||||
|
||||
<!-- llm__api_base_url - default 'https://ai.dgrzone.com/api'; input url -->
|
||||
<label class="flex items-center justify-start gap-1">
|
||||
LLM API Base URL:
|
||||
@@ -288,7 +306,7 @@ import { journals_loc, journals_sess, journals_slct, journals_prom, journals_tri
|
||||
</label>
|
||||
|
||||
<label class="flex flex-col items-start justify-start gap-1 h-24">
|
||||
LLM System Prompt:
|
||||
LLM System Prompt for Journal Entry summarization:
|
||||
<E_app_codemirror_v5
|
||||
editable={true}
|
||||
readonly={false}
|
||||
@@ -307,6 +325,18 @@ import { journals_loc, journals_sess, journals_slct, journals_prom, journals_tri
|
||||
/>
|
||||
</label>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm preset-outlined-primary-400-600"
|
||||
onclick={() => {
|
||||
let default_system_prompt = 'Summarize the following journal entry content in a concise manner, focusing on key points and insights.';
|
||||
$journals_loc.entry.llm__system_prompt = default_system_prompt;
|
||||
}}
|
||||
>
|
||||
<RefreshCcw class="inline-block mr-1" />
|
||||
Reset to Journal Entry System Prompt
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user