This file was moved I think/hope
This commit is contained in:
@@ -1,129 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
/**
|
|
||||||
* JournalEntry_AITools.svelte
|
|
||||||
* Extracted 2026-01-08 to modularize the Journal Entry view.
|
|
||||||
* Encapsulates OpenAI logic and the Summary Modal.
|
|
||||||
*/
|
|
||||||
import OpenAI from 'openai';
|
|
||||||
import { Modal } from 'flowbite-svelte';
|
|
||||||
import {
|
|
||||||
Bot, BotMessageSquare, Loader, FileText,
|
|
||||||
Save, FilePenLine
|
|
||||||
} from '@lucide/svelte';
|
|
||||||
import {
|
|
||||||
journals_loc,
|
|
||||||
journals_sess
|
|
||||||
} from '$lib/ae_journals/ae_journals_stores';
|
|
||||||
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
|
|
||||||
import type { ae_JournalEntry } from '$lib/types/ae_types';
|
|
||||||
import E_app_codemirror_v5 from '$lib/app_components/e_app_codemirror_v5.svelte';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
entry: ae_JournalEntry;
|
|
||||||
onSave: () => void;
|
|
||||||
log_lvl?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { entry, onSave, log_lvl = 0 }: Props = $props();
|
|
||||||
let ae_promises: any = $state(null);
|
|
||||||
|
|
||||||
async function generate_summary() {
|
|
||||||
if (!entry.content) return;
|
|
||||||
|
|
||||||
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
|
|
||||||
});
|
|
||||||
|
|
||||||
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.'
|
|
||||||
},
|
|
||||||
{ role: 'user', content: entry.content }
|
|
||||||
]
|
|
||||||
}).then((resp) => {
|
|
||||||
$journals_sess.entry.ai_summary = resp?.choices?.[0]?.message?.content || 'No summary available';
|
|
||||||
$journals_sess.entry.show__ai_summary = true;
|
|
||||||
});
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error('AI Error:', err);
|
|
||||||
alert('AI Error: ' + err.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Summary Trigger Button -->
|
|
||||||
{#if !$journals_sess?.entry?.show__ai_summary}
|
|
||||||
{#if entry.content && entry.content.length > 50}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={generate_summary}
|
|
||||||
class="btn btn-sm preset-tonal-primary hover:preset-filled-primary-500 absolute top-2 right-2 z-10"
|
|
||||||
>
|
|
||||||
{#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}
|
|
||||||
<span class="text-sm text-red-500">Error</span>
|
|
||||||
{/await}
|
|
||||||
</button>
|
|
||||||
{:else if entry.summary}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={() => {
|
|
||||||
$journals_sess.entry.ai_summary = entry.summary;
|
|
||||||
$journals_sess.entry.show__ai_summary = true;
|
|
||||||
}}
|
|
||||||
class="btn btn-sm preset-tonal-primary absolute top-2 right-2 z-10"
|
|
||||||
>
|
|
||||||
<FileText size="1.25em" class="mr-1" /> Use Saved
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<!-- AI Summary Modal -->
|
|
||||||
{#if $journals_sess?.entry?.show__ai_summary && $journals_sess?.entry?.ai_summary}
|
|
||||||
<Modal
|
|
||||||
title="AI Summary"
|
|
||||||
bind:open={$journals_sess.entry.show__ai_summary}
|
|
||||||
size="md"
|
|
||||||
class="bg-white dark:bg-gray-800"
|
|
||||||
>
|
|
||||||
<div class="space-y-4">
|
|
||||||
<div class="flex gap-2 justify-center">
|
|
||||||
<button
|
|
||||||
class="btn btn-sm variant-filled-success"
|
|
||||||
onclick={() => {
|
|
||||||
entry.summary = $journals_sess.entry.ai_summary;
|
|
||||||
onSave();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Save size="1.2em" class="mr-1" /> Save to Entry
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="btn btn-sm variant-filled-primary"
|
|
||||||
onclick={generate_summary}
|
|
||||||
>
|
|
||||||
<BotMessageSquare size="1.2em" class="mr-1" /> Re-Summarize
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<E_app_codemirror_v5
|
|
||||||
editable={true}
|
|
||||||
content={$journals_sess.entry.ai_summary}
|
|
||||||
bind:new_content={$journals_sess.entry.ai_summary}
|
|
||||||
bind:theme_mode={$ae_loc.theme_mode}
|
|
||||||
class="p-2 border rounded-lg h-64"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Modal>
|
|
||||||
{/if}
|
|
||||||
Reference in New Issue
Block a user