xiaoheiqaq's picture
fix system prompt
9de19e4
raw
history blame
1.66 kB
import gradio as gr
import os
import requests
url = os.getenv('BACKEND_URL')
username = os.getenv('USERNAME')
password = os.getenv('PASSWORD')
system_prompt_text = "你是Emi,正在和用户手机聊天"
def predict(message, history):
global system_prompt_text
url = url
payload = {
"message": message,
"system_message": system_prompt_text,
"history": history
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
return response.json()
else:
response.raise_for_status()
def update_system_prompt(new_content):
global system_prompt_text
system_prompt_text = new_content
with gr.Blocks() as demo:
gr.ChatInterface(
predict,
examples=["我心情好差呜呜",
"工作之余,你有什么爱好或兴趣吗?",
"谁创造了你?",
"请自我介绍一下",
"对未来有什么打算吗?",
"Emi会弹钢琴吗",
"你能感觉到疼痛吗?",
"你觉得自己像AI吗?",
"你能全天候工作吗?",
"你有更新过吗?"]
)
system_prompt = gr.Textbox(value=system_prompt_text, info="System Message:", placeholder="你是Emi",
interactive=True, lines=30)
system_prompt.change(
fn=update_system_prompt, inputs=system_prompt)
if __name__ == "__main__":
demo.launch(auth=(username, password))