xiaoheiqaq commited on
Commit
9de19e4
1 Parent(s): 6cbb12f

fix system prompt

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +26 -18
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv
app.py CHANGED
@@ -5,12 +5,14 @@ import requests
5
  url = os.getenv('BACKEND_URL')
6
  username = os.getenv('USERNAME')
7
  password = os.getenv('PASSWORD')
 
8
 
9
- def predict(message, history, system_message):
 
10
  url = url
11
  payload = {
12
  "message": message,
13
- "system_message": system_message,
14
  "history": history
15
  }
16
  headers = {
@@ -24,23 +26,29 @@ def predict(message, history, system_message):
24
  else:
25
  response.raise_for_status()
26
 
27
- demo = gr.ChatInterface(
28
- predict,
29
- additional_inputs=[
30
- gr.Textbox(value="你是Emi,正在和用户手机聊天", label="System message"),
31
- ],
32
- examples=["我心情好差呜呜",
33
- "工作之余,你有什么爱好或兴趣吗?",
34
- "谁创造了你?",
35
- "请自我介绍一下",
36
- "对未来有什么打算吗?",
37
- "Emi会弹钢琴吗",
38
- "你能感觉到疼痛吗?",
39
- "你觉得自己像AI吗?",
40
- "你能全天候工作吗?",
41
- "你有更新过吗?"]
42
- )
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  if __name__ == "__main__":
46
  demo.launch(auth=(username, password))
 
5
  url = os.getenv('BACKEND_URL')
6
  username = os.getenv('USERNAME')
7
  password = os.getenv('PASSWORD')
8
+ system_prompt_text = "你是Emi,正在和用户手机聊天"
9
 
10
+ def predict(message, history):
11
+ global system_prompt_text
12
  url = url
13
  payload = {
14
  "message": message,
15
+ "system_message": system_prompt_text,
16
  "history": history
17
  }
18
  headers = {
 
26
  else:
27
  response.raise_for_status()
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ def update_system_prompt(new_content):
31
+ global system_prompt_text
32
+ system_prompt_text = new_content
33
+
34
+ with gr.Blocks() as demo:
35
+ gr.ChatInterface(
36
+ predict,
37
+ examples=["我心情好差呜呜",
38
+ "工作之余,你有什么爱好或兴趣吗?",
39
+ "谁创造了你?",
40
+ "请自我介绍一下",
41
+ "对未来有什么打算吗?",
42
+ "Emi会弹钢琴吗",
43
+ "你能感觉到疼痛吗?",
44
+ "你觉得自己像AI吗?",
45
+ "你能全天候工作吗?",
46
+ "你有更新过吗?"]
47
+ )
48
+ system_prompt = gr.Textbox(value=system_prompt_text, info="System Message:", placeholder="你是Emi",
49
+ interactive=True, lines=30)
50
+ system_prompt.change(
51
+ fn=update_system_prompt, inputs=system_prompt)
52
 
53
  if __name__ == "__main__":
54
  demo.launch(auth=(username, password))