mirror of
https://github.com/open-webui/open-webui
synced 2025-05-31 11:00:49 +00:00
feat: chat action integration
This commit is contained in:
parent
eb10001eb7
commit
14c0efe300
@ -104,6 +104,45 @@ export const chatCompleted = async (token: string, body: ChatCompletedForm) => {
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ChatActionForm = {
|
||||||
|
model: string;
|
||||||
|
messages: string[];
|
||||||
|
chat_id: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const chatAction = async (token: string, action_id: string, body: ChatActionForm) => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${WEBUI_BASE_URL}/api/chat/actions/${action_id}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...(token && { authorization: `Bearer ${token}` })
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
if ('detail' in err) {
|
||||||
|
error = err.detail;
|
||||||
|
} else {
|
||||||
|
error = err;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
export const getTaskConfig = async (token: string = '') => {
|
export const getTaskConfig = async (token: string = '') => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
import { createOpenAITextStream } from '$lib/apis/streaming';
|
import { createOpenAITextStream } from '$lib/apis/streaming';
|
||||||
import { queryMemory } from '$lib/apis/memories';
|
import { queryMemory } from '$lib/apis/memories';
|
||||||
import { getAndUpdateUserLocation, getUserSettings } from '$lib/apis/users';
|
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 Banner from '../common/Banner.svelte';
|
||||||
import MessageInput from '$lib/components/chat/MessageInput.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 = '') => {
|
const getChatEventEmitter = async (modelId: string, chatId: string = '') => {
|
||||||
return setInterval(() => {
|
return setInterval(() => {
|
||||||
$socket?.emit('usage', {
|
$socket?.emit('usage', {
|
||||||
@ -1533,6 +1566,7 @@
|
|||||||
{sendPrompt}
|
{sendPrompt}
|
||||||
{continueGeneration}
|
{continueGeneration}
|
||||||
{regenerateResponse}
|
{regenerateResponse}
|
||||||
|
{chatActionHandler}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
export let sendPrompt: Function;
|
export let sendPrompt: Function;
|
||||||
export let continueGeneration: Function;
|
export let continueGeneration: Function;
|
||||||
export let regenerateResponse: Function;
|
export let regenerateResponse: Function;
|
||||||
|
export let chatActionHandler: Function;
|
||||||
|
|
||||||
export let user = $_user;
|
export let user = $_user;
|
||||||
export let prompt;
|
export let prompt;
|
||||||
@ -335,6 +336,7 @@
|
|||||||
copyToClipboard={copyToClipboardWithToast}
|
copyToClipboard={copyToClipboardWithToast}
|
||||||
{continueGeneration}
|
{continueGeneration}
|
||||||
{regenerateResponse}
|
{regenerateResponse}
|
||||||
|
{chatActionHandler}
|
||||||
on:save={async (e) => {
|
on:save={async (e) => {
|
||||||
console.log('save', e);
|
console.log('save', e);
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
export let copyToClipboard: Function;
|
export let copyToClipboard: Function;
|
||||||
export let continueGeneration: Function;
|
export let continueGeneration: Function;
|
||||||
export let regenerateResponse: Function;
|
export let regenerateResponse: Function;
|
||||||
|
export let chatActionHandler: Function;
|
||||||
|
|
||||||
let model = null;
|
let model = null;
|
||||||
$: model = $models.find((m) => m.id === message.model);
|
$: model = $models.find((m) => m.id === message.model);
|
||||||
@ -1030,6 +1031,7 @@
|
|||||||
? 'visible'
|
? '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"
|
: '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={() => {
|
on:click={() => {
|
||||||
|
chatActionHandler(action.id, message.model, message.id);
|
||||||
console.log('action');
|
console.log('action');
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user