"docs/vscode:/vscode.git/clone" did not exist on "35badc0892275c35818ca39800ec55d9c7342c8f"
Commit e643786c authored by laibao's avatar laibao
Browse files

Update examples/gradio_openai_chatbot_webserver.py

parent 3409b209
......@@ -42,16 +42,24 @@ client = OpenAI(
def predict(message, history):
# Convert chat history to OpenAI format
history_openai_format = [{
"role": "system",
"content": "You are a great ai assistant."
}]
# history_openai_format = [{
# "role": "system",
# "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:
history_openai_format.append({"role": "user", "content": human})
history_openai_format.append({
"role": "assistant",
"content": assistant
})
if human: # 确保user消息存在
history_openai_format.append({"role": "user", "content": human})
if assistant: # 确保assistant消息存在
history_openai_format.append({"role": "assistant", "content": assistant})
history_openai_format.append({"role": "user", "content": message})
# Create a chat completion request and send it to the API server
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment