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( ...@@ -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
......
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