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
ModelZoo
Mixtral_vllm
Commits
e643786c
Commit
e643786c
authored
Jan 03, 2025
by
laibao
Browse files
Update examples/gradio_openai_chatbot_webserver.py
parent
3409b209
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
examples/gradio_openai_chatbot_webserver.py
examples/gradio_openai_chatbot_webserver.py
+17
-9
No files found.
examples/gradio_openai_chatbot_webserver.py
View file @
e643786c
...
@@ -42,16 +42,24 @@ client = OpenAI(
...
@@ -42,16 +42,24 @@ client = OpenAI(
def
predict
(
message
,
history
):
def
predict
(
message
,
history
):
# Convert chat history to OpenAI format
# Convert chat history to OpenAI format
history_openai_format
=
[{
# history_openai_format = [{
"role"
:
"system"
,
# "role": "system",
"content"
:
"You are a great ai assistant."
# "content": "You are a great ai assistant."
}]
# }]
# for human, assistant in history:
# history_openai_format.append({"role": "user", "content": human})
# history_openai_format.append({
# "role": "assistant",
# "content": assistant
# })
history_openai_format
=
[]
# 添加历史消息
for
human
,
assistant
in
history
:
for
human
,
assistant
in
history
:
history_openai_format
.
append
({
"role"
:
"user"
,
"content"
:
human
})
if
human
:
# 确保user消息存在
history_openai_format
.
append
({
history_openai_format
.
append
({
"role"
:
"user"
,
"content"
:
human
})
"role"
:
"assistant"
,
if
assistant
:
# 确保assistant消息存在
"content"
:
assistant
history_openai_format
.
append
({
"role"
:
"assistant"
,
"content"
:
assistant
})
})
history_openai_format
.
append
({
"role"
:
"user"
,
"content"
:
message
})
history_openai_format
.
append
({
"role"
:
"user"
,
"content"
:
message
})
# Create a chat completion request and send it to the API server
# Create a chat completion request and send it to the API server
...
...
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