-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
97 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { get } from "svelte/store"; | ||
import { settingsStore, knowledgeStore } from "$lib/store"; | ||
|
||
export interface Knowledge { | ||
id: string; | ||
name: string; | ||
content: string[]; | ||
updated_at: string; | ||
} | ||
|
||
export const loadKnowledge = (id: string): Knowledge => { | ||
let knowledge: Knowledge | null = null; | ||
|
||
// Retrieve the current sessions | ||
const currentKnowledges = get(knowledgeStore); | ||
|
||
// Find the session with the given id | ||
if (currentKnowledges) { | ||
const existingKnowledge = currentKnowledges.find(s => s.id === id); | ||
existingKnowledge && (knowledge = existingKnowledge); | ||
} | ||
|
||
if (!knowledge) { | ||
// Get the current model | ||
const model = get(settingsStore)?.ollamaModel || ""; | ||
|
||
// Create a new session | ||
knowledge = { id, name: "", content: [], updated_at: new Date().toISOString() }; | ||
} | ||
|
||
return knowledge; | ||
}; | ||
|
||
export const saveKnowledge = (Knowledge: Knowledge): void => { | ||
// Retrieve the current sessions | ||
const currentKnowledges = get(knowledgeStore) || []; | ||
|
||
// Find the index of the session with the same id, if it exists | ||
const existingKnowledge = currentKnowledges.findIndex(s => s.id === Knowledge.id); | ||
|
||
if (existingKnowledge !== -1) { | ||
// Update the existing session | ||
currentKnowledges[existingKnowledge] = Knowledge; | ||
} else { | ||
// Add the new session if it doesn't exist | ||
currentKnowledges.push(Knowledge); | ||
} | ||
|
||
// Update the store, which will trigger the localStorage update | ||
knowledgeStore.set(currentKnowledges); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script lang="ts"> | ||
import type { PageData } from '../$types'; | ||
import { loadKnowledge, saveKnowledge } from '$lib/knowledge'; | ||
import Button from '$lib/components/Button.svelte'; | ||
import { getUpdatedAtDate } from '$lib/utils'; | ||
export let data: PageData; | ||
let knowledge = loadKnowledge(data.id); | ||
let { id, name, content, updated_at } = knowledge; | ||
function handleSubmit() { | ||
saveKnowledge({ id, name, content, updated_at: getUpdatedAtDate() }); | ||
} | ||
</script> | ||
|
||
{#if knowledge} | ||
<ul> | ||
<li>id: {id}</li> | ||
<li>created_at: {updated_at}</li> | ||
<li>name: <input class="border border-neutral-500" bind:value={name} /></li> | ||
<li> | ||
content: | ||
<textarea class="border border-neutral-500" bind:value={content}></textarea> | ||
</li> | ||
<li> | ||
<Button class="w-full" on:click={handleSubmit} disabled={!name && !content}>Save</Button> | ||
</li> | ||
</ul> | ||
{/if} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.