Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
856845e5
Commit
856845e5
authored
Jul 11, 2024
by
Timothy J. Baek
Browse files
refac
parent
14c0efe3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
10 deletions
+35
-10
backend/main.py
backend/main.py
+1
-1
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+30
-6
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+3
-1
src/lib/components/chat/Messages/ResponseMessage.svelte
src/lib/components/chat/Messages/ResponseMessage.svelte
+1
-2
No files found.
backend/main.py
View file @
856845e5
...
@@ -1285,7 +1285,7 @@ async def chat_completed(
...
@@ -1285,7 +1285,7 @@ async def chat_completed(
status_code
=
status
.
HTTP_404_NOT_FOUND
,
status_code
=
status
.
HTTP_404_NOT_FOUND
,
detail
=
"Action not found"
,
detail
=
"Action not found"
,
)
)
data
=
form_data
data
=
form_data
model_id
=
data
[
"model"
]
model_id
=
data
[
"model"
]
if
model_id
not
in
app
.
state
.
MODELS
:
if
model_id
not
in
app
.
state
.
MODELS
:
...
...
src/lib/components/chat/Chat.svelte
View file @
856845e5
...
@@ -363,7 +363,7 @@
...
@@ -363,7 +363,7 @@
}
}
};
};
const chatCompletedHandler = async (modelId, responseMessageId, messages) => {
const chatCompletedHandler = async (
chatId,
modelId, responseMessageId, messages) => {
await mermaid.run({
await mermaid.run({
querySelector: '.mermaid'
querySelector: '.mermaid'
});
});
...
@@ -377,7 +377,7 @@
...
@@ -377,7 +377,7 @@
info: m.info ? m.info : undefined,
info: m.info ? m.info : undefined,
timestamp: m.timestamp
timestamp: m.timestamp
})),
})),
chat_id:
$
chatId,
chat_id: chatId,
session_id: $socket?.id,
session_id: $socket?.id,
id: responseMessageId
id: responseMessageId
}).catch((error) => {
}).catch((error) => {
...
@@ -399,9 +399,21 @@
...
@@ -399,9 +399,21 @@
};
};
}
}
}
}
if ($chatId == chatId) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, chatId, {
models: selectedModels,
messages: messages,
history: history,
params: params
});
await chats.set(await getChatList(localStorage.token));
}
}
};
};
const chatActionHandler = async (actionId, modelId, responseMessageId) => {
const chatActionHandler = async (
chatId,
actionId, modelId, responseMessageId) => {
const res = await chatAction(localStorage.token, actionId, {
const res = await chatAction(localStorage.token, actionId, {
model: modelId,
model: modelId,
messages: messages.map((m) => ({
messages: messages.map((m) => ({
...
@@ -411,7 +423,7 @@
...
@@ -411,7 +423,7 @@
info: m.info ? m.info : undefined,
info: m.info ? m.info : undefined,
timestamp: m.timestamp
timestamp: m.timestamp
})),
})),
chat_id:
$
chatId,
chat_id: chatId,
session_id: $socket?.id,
session_id: $socket?.id,
id: responseMessageId
id: responseMessageId
}).catch((error) => {
}).catch((error) => {
...
@@ -432,6 +444,18 @@
...
@@ -432,6 +444,18 @@
};
};
}
}
}
}
if ($chatId == chatId) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, chatId, {
models: selectedModels,
messages: messages,
history: history,
params: params
});
await chats.set(await getChatList(localStorage.token));
}
}
};
};
const getChatEventEmitter = async (modelId: string, chatId: string = '') => {
const getChatEventEmitter = async (modelId: string, chatId: string = '') => {
...
@@ -801,7 +825,7 @@
...
@@ -801,7 +825,7 @@
controller.abort('User: Stop Response');
controller.abort('User: Stop Response');
} else {
} else {
const messages = createMessagesList(responseMessageId);
const messages = createMessagesList(responseMessageId);
await chatCompletedHandler(model.id, responseMessageId, messages);
await chatCompletedHandler(
_chatId,
model.id, responseMessageId, messages);
}
}
_response = responseMessage.content;
_response = responseMessage.content;
...
@@ -1113,7 +1137,7 @@
...
@@ -1113,7 +1137,7 @@
} else {
} else {
const messages = createMessagesList(responseMessageId);
const messages = createMessagesList(responseMessageId);
await chatCompletedHandler(model.id, responseMessageId, messages);
await chatCompletedHandler(
_chatId,
model.id, responseMessageId, messages);
}
}
_response = responseMessage.content;
_response = responseMessage.content;
...
...
src/lib/components/chat/Messages.svelte
View file @
856845e5
...
@@ -336,7 +336,9 @@
...
@@ -336,7 +336,9 @@
copyToClipboard={copyToClipboardWithToast}
copyToClipboard={copyToClipboardWithToast}
{continueGeneration}
{continueGeneration}
{regenerateResponse}
{regenerateResponse}
{chatActionHandler}
on:action={async (e) => {
await chatActionHandler(chatId, e.detail, message.model, message.id);
}}
on:save={async (e) => {
on:save={async (e) => {
console.log('save', e);
console.log('save', e);
...
...
src/lib/components/chat/Messages/ResponseMessage.svelte
View file @
856845e5
...
@@ -1031,8 +1031,7 @@
...
@@ -1031,8 +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);
dispatch('action', action.id);
console.log('action');
}}
}}
>
>
<Sparkles strokeWidth="2.1" className="size-4" />
<Sparkles strokeWidth="2.1" className="size-4" />
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment