feat: chat action integration

This commit is contained in:
Timothy J. Baek
2024-07-11 18:47:38 -07:00
parent eb10001eb7
commit 14c0efe300
4 changed files with 78 additions and 1 deletions

View File

@@ -52,7 +52,7 @@
import { createOpenAITextStream } from '$lib/apis/streaming';
import { queryMemory } from '$lib/apis/memories';
import { getAndUpdateUserLocation, getUserSettings } from '$lib/apis/users';
import { chatCompleted, generateTitle, generateSearchQuery } from '$lib/apis';
import { chatCompleted, generateTitle, generateSearchQuery, chatAction } from '$lib/apis';
import Banner from '../common/Banner.svelte';
import MessageInput from '$lib/components/chat/MessageInput.svelte';
@@ -401,6 +401,39 @@
}
};
const chatActionHandler = async (actionId, modelId, responseMessageId) => {
const res = await chatAction(localStorage.token, actionId, {
model: modelId,
messages: messages.map((m) => ({
id: m.id,
role: m.role,
content: m.content,
info: m.info ? m.info : undefined,
timestamp: m.timestamp
})),
chat_id: $chatId,
session_id: $socket?.id,
id: responseMessageId
}).catch((error) => {
toast.error(error);
messages.at(-1).error = { content: error };
return null;
});
if (res !== null) {
// Update chat history with the new messages
for (const message of res.messages) {
history.messages[message.id] = {
...history.messages[message.id],
...(history.messages[message.id].content !== message.content
? { originalContent: history.messages[message.id].content }
: {}),
...message
};
}
}
};
const getChatEventEmitter = async (modelId: string, chatId: string = '') => {
return setInterval(() => {
$socket?.emit('usage', {
@@ -1533,6 +1566,7 @@
{sendPrompt}
{continueGeneration}
{regenerateResponse}
{chatActionHandler}
/>
</div>
</div>

View File

@@ -22,6 +22,7 @@
export let sendPrompt: Function;
export let continueGeneration: Function;
export let regenerateResponse: Function;
export let chatActionHandler: Function;
export let user = $_user;
export let prompt;
@@ -335,6 +336,7 @@
copyToClipboard={copyToClipboardWithToast}
{continueGeneration}
{regenerateResponse}
{chatActionHandler}
on:save={async (e) => {
console.log('save', e);

View File

@@ -55,6 +55,7 @@
export let copyToClipboard: Function;
export let continueGeneration: Function;
export let regenerateResponse: Function;
export let chatActionHandler: Function;
let model = null;
$: model = $models.find((m) => m.id === message.model);
@@ -1030,6 +1031,7 @@
? 'visible'
: 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button"
on:click={() => {
chatActionHandler(action.id, message.model, message.id);
console.log('action');
}}
>