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
2e0fa1c6
"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "797ed9ac7f5590bd0358e55f632ec5f729873d21"
Commit
2e0fa1c6
authored
Jul 31, 2024
by
Michael Poluektov
Browse files
refac: rename stream_message_template
parent
f8726719
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
backend/apps/webui/main.py
backend/apps/webui/main.py
+8
-4
backend/utils/misc.py
backend/utils/misc.py
+1
-1
No files found.
backend/apps/webui/main.py
View file @
2e0fa1c6
...
@@ -20,7 +20,7 @@ from apps.webui.models.models import Models
...
@@ -20,7 +20,7 @@ from apps.webui.models.models import Models
from
apps.webui.utils
import
load_function_module_by_id
from
apps.webui.utils
import
load_function_module_by_id
from
utils.misc
import
(
from
utils.misc
import
(
stream
_message_template
,
openai_chat_chunk
_message_template
,
openai_chat_completion_message_template
,
openai_chat_completion_message_template
,
add_or_update_system_message
,
add_or_update_system_message
,
)
)
...
@@ -227,7 +227,7 @@ def process_line(form_data: dict, line):
...
@@ -227,7 +227,7 @@ def process_line(form_data: dict, line):
if
line
.
startswith
(
"data:"
):
if
line
.
startswith
(
"data:"
):
return
f
"
{
line
}
\n\n
"
return
f
"
{
line
}
\n\n
"
else
:
else
:
line
=
stream
_message_template
(
form_data
[
"model"
],
line
)
line
=
openai_chat_chunk
_message_template
(
form_data
[
"model"
],
line
)
return
f
"data:
{
json
.
dumps
(
line
)
}
\n\n
"
return
f
"data:
{
json
.
dumps
(
line
)
}
\n\n
"
...
@@ -371,7 +371,9 @@ async def generate_function_chat_completion(form_data, user):
...
@@ -371,7 +371,9 @@ async def generate_function_chat_completion(form_data, user):
return
return
if
isinstance
(
res
,
str
):
if
isinstance
(
res
,
str
):
message
=
stream_message_template
(
form_data
[
"model"
],
res
)
message
=
openai_chat_chunk_message_template
(
form_data
[
"model"
],
res
)
yield
f
"data:
{
json
.
dumps
(
message
)
}
\n\n
"
yield
f
"data:
{
json
.
dumps
(
message
)
}
\n\n
"
if
isinstance
(
res
,
Iterator
):
if
isinstance
(
res
,
Iterator
):
...
@@ -383,7 +385,9 @@ async def generate_function_chat_completion(form_data, user):
...
@@ -383,7 +385,9 @@ async def generate_function_chat_completion(form_data, user):
yield
process_line
(
form_data
,
line
)
yield
process_line
(
form_data
,
line
)
if
isinstance
(
res
,
str
)
or
isinstance
(
res
,
Generator
):
if
isinstance
(
res
,
str
)
or
isinstance
(
res
,
Generator
):
finish_message
=
stream_message_template
(
form_data
[
"model"
],
""
)
finish_message
=
openai_chat_chunk_message_template
(
form_data
[
"model"
],
""
)
finish_message
[
"choices"
][
0
][
"finish_reason"
]
=
"stop"
finish_message
[
"choices"
][
0
][
"finish_reason"
]
=
"stop"
yield
f
"data:
{
json
.
dumps
(
finish_message
)
}
\n\n
"
yield
f
"data:
{
json
.
dumps
(
finish_message
)
}
\n\n
"
yield
"data: [DONE]"
yield
"data: [DONE]"
...
...
backend/utils/misc.py
View file @
2e0fa1c6
...
@@ -97,7 +97,7 @@ def message_template(model: str):
...
@@ -97,7 +97,7 @@ def message_template(model: str):
}
}
def
stream
_message_template
(
model
:
str
,
message
:
str
):
def
openai_chat_chunk
_message_template
(
model
:
str
,
message
:
str
):
template
=
message_template
(
model
)
template
=
message_template
(
model
)
template
[
"object"
]
=
"chat.completion.chunk"
template
[
"object"
]
=
"chat.completion.chunk"
template
[
"choices"
][
0
][
"delta"
]
=
{
"content"
:
message
}
template
[
"choices"
][
0
][
"delta"
]
=
{
"content"
:
message
}
...
...
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