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
c7a9b5cc
Commit
c7a9b5cc
authored
Jul 01, 2024
by
Timothy J. Baek
Browse files
refac: chat completion middleware
parent
b62d2a9b
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
304 additions
and
223 deletions
+304
-223
backend/apps/rag/utils.py
backend/apps/rag/utils.py
+7
-7
backend/main.py
backend/main.py
+291
-210
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+6
-6
No files found.
backend/apps/rag/utils.py
View file @
c7a9b5cc
...
...
@@ -294,14 +294,16 @@ def get_rag_context(
extracted_collections
.
extend
(
collection_names
)
context_string
=
""
contexts
=
[]
citations
=
[]
for
context
in
relevant_contexts
:
try
:
if
"documents"
in
context
:
context_string
+=
"
\n\n
"
.
join
(
[
text
for
text
in
context
[
"documents"
][
0
]
if
text
is
not
None
]
contexts
.
append
(
"
\n\n
"
.
join
(
[
text
for
text
in
context
[
"documents"
][
0
]
if
text
is
not
None
]
)
)
if
"metadatas"
in
context
:
...
...
@@ -315,9 +317,7 @@ def get_rag_context(
except
Exception
as
e
:
log
.
exception
(
e
)
context_string
=
context_string
.
strip
()
return
context_string
,
citations
return
contexts
,
citations
def
get_model_path
(
model
:
str
,
update_model
:
bool
=
False
):
...
...
backend/main.py
View file @
c7a9b5cc
This diff is collapsed.
Click to expand it.
src/lib/components/chat/Chat.svelte
View file @
c7a9b5cc
...
...
@@ -665,6 +665,7 @@
await tick();
const [res, controller] = await generateChatCompletion(localStorage.token, {
stream: true,
model: model.id,
messages: messagesBody,
options: {
...
...
@@ -682,8 +683,8 @@
keep_alive: $settings.keepAlive ?? undefined,
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
files: files.length > 0 ? files : undefined,
c
itations: files.length > 0 ? true : undefine
d,
chat_id: $chat
Id
c
hat_id: $chatI
d,
id: responseMessage
Id
});
if (res && res.ok) {
...
...
@@ -912,8 +913,8 @@
const [res, controller] = await generateOpenAIChatCompletion(
localStorage.token,
{
model: model.id,
stream: true,
model: model.id,
stream_options:
model.info?.meta?.capabilities?.usage ?? false
? {
...
...
@@ -983,9 +984,8 @@
max_tokens: $settings?.params?.max_tokens ?? undefined,
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
files: files.length > 0 ? files : undefined,
citations: files.length > 0 ? true : undefined,
chat_id: $chatId
chat_id: $chatId,
id: responseMessageId
},
`${WEBUI_BASE_URL}/api`
);
...
...
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