Spaces:
Running
Running
File size: 2,625 Bytes
df3243b d433b55 df3243b 4f1e27f a8a9533 4f1e27f a1a6daf 4f1e27f a1a6daf 4f1e27f d433b55 4f1e27f df3243b 4f1e27f df3243b 4f1e27f df3243b 4f1e27f df3243b 4f1e27f df3243b 4f1e27f d433b55 4f1e27f df3243b a8a9533 df3243b a8a9533 df3243b d433b55 a8a9533 df3243b d433b55 df3243b 4f1e27f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
<script lang="ts">
import { page } from "$app/state";
import { base } from "$app/paths";
import { goto } from "$app/navigation";
import { onMount } from "svelte";
import { env as envPublic } from "$env/dynamic/public";
import ChatWindow from "$lib/components/chat/ChatWindow.svelte";
import { findCurrentModel } from "$lib/utils/models";
import { useSettingsStore } from "$lib/stores/settings";
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
import { pendingMessage } from "$lib/stores/pendingMessage";
let { data } = $props();
let loading = $state(false);
let files: File[] = $state([]);
const settings = useSettingsStore();
const modelId = page.params.model;
async function createConversation(message: string) {
try {
loading = true;
const res = await fetch(`${base}/conversation`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
model: data.assistant.modelId,
assistantId: data.assistant._id,
}),
});
if (!res.ok) {
error.set("Error while creating conversation, try again.");
console.error("Error while creating conversation: " + (await res.text()));
return;
}
const { conversationId } = await res.json();
// Ugly hack to use a store as temp storage, feel free to improve ^^
pendingMessage.set({
content: message,
files,
});
// invalidateAll to update list of conversations
await goto(`${base}/conversation/${conversationId}`, { invalidateAll: true });
} catch (err) {
error.set(ERROR_MESSAGES.default);
console.error(err);
} finally {
loading = false;
}
}
onMount(async () => {
settings.instantSet({
activeModel: modelId,
});
const query = page.url.searchParams.get("q");
if (query) createConversation(query);
});
</script>
<svelte:head>
<meta property="og:title" content={data.assistant.name + " - " + envPublic.PUBLIC_APP_NAME} />
<meta property="og:type" content="link" />
<meta
property="og:description"
content={`Use the ${data.assistant.name} assistant inside of ${envPublic.PUBLIC_APP_NAME}`}
/>
<meta
property="og:image"
content="{envPublic.PUBLIC_ORIGIN || page.url.origin}{base}/assistant/{data.assistant
._id}/thumbnail.png"
/>
<meta property="og:url" content={page.url.href} />
<meta name="twitter:card" content="summary_large_image" />
</svelte:head>
<ChatWindow
on:message={(ev) => createConversation(ev.detail)}
{loading}
currentModel={findCurrentModel([...data.models, ...data.oldModels], data.assistant.modelId)}
assistant={data.assistant}
models={data.models}
bind:files
/>
|