thomas-yanxin commited on
Commit
3c1485b
·
verified ·
1 Parent(s): 4def39b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -21,7 +21,6 @@ client = OpenAI(
21
 
22
  model = "xinyuan-32b-v0609"
23
 
24
-
25
  def prompt_select(e: gr.EventData):
26
  return gr.update(value=e._data["payload"][0]["value"]["description"])
27
 
@@ -83,12 +82,12 @@ def submit(sender_value, chatbot_value):
83
 
84
  try:
85
  response = client.chat.completions.create(model=model,
86
- messages=history_messages,
87
- stream=True,
88
- max_tokens=2048,
89
- temperature=0.6,
90
- top_p=0.95,
91
- )
92
  thought_done = False
93
  start_time = time.time()
94
  message_content = chatbot_value[-1]["content"]
@@ -108,8 +107,14 @@ def submit(sender_value, chatbot_value):
108
  "content": "",
109
  })
110
  for chunk in response:
111
- reasoning_content = chunk.choices[0].delta.reasoning_content
112
- content = chunk.choices[0].delta.content
 
 
 
 
 
 
113
  chatbot_value[-1]["loading"] = False
114
  message_content[-2]["content"] += reasoning_content or ""
115
  message_content[-1]["content"] += content or ""
@@ -124,7 +129,7 @@ def submit(sender_value, chatbot_value):
124
  yield {chatbot: gr.update(value=chatbot_value)}
125
 
126
  chatbot_value[-1]["footer"] = "{:.2f}".format(time.time() -
127
- start_time) + 's'
128
  chatbot_value[-1]["status"] = "done"
129
  yield {
130
  clear_btn: gr.update(disabled=False),
@@ -194,7 +199,7 @@ with gr.Blocks() as demo, ms.Application(), antdx.XProvider():
194
  avatar="https://api.dicebear.com/7.x/miniavs/svg?seed=3",
195
  variant="shadow"),
196
  bot_config=ChatbotBotConfig(
197
- header=model,
198
  avatar=
199
  "./xinyuan.png",
200
  actions=["copy", "retry"],
@@ -222,4 +227,6 @@ with gr.Blocks() as demo, ms.Application(), antdx.XProvider():
222
  chatbot.welcome_prompt_select(fn=prompt_select, outputs=[sender])
223
 
224
  if __name__ == "__main__":
225
- demo.queue().launch()
 
 
 
21
 
22
  model = "xinyuan-32b-v0609"
23
 
 
24
  def prompt_select(e: gr.EventData):
25
  return gr.update(value=e._data["payload"][0]["value"]["description"])
26
 
 
82
 
83
  try:
84
  response = client.chat.completions.create(model=model,
85
+ messages=history_messages,
86
+ stream=True,
87
+ max_tokens=32768,
88
+ temperature=0.6,
89
+ top_p=0.95,
90
+ )
91
  thought_done = False
92
  start_time = time.time()
93
  message_content = chatbot_value[-1]["content"]
 
107
  "content": "",
108
  })
109
  for chunk in response:
110
+ try:
111
+ reasoning_content = chunk.choices[0].delta.reasoning_content
112
+ except:
113
+ reasoning_content = ""
114
+ try:
115
+ content = chunk.choices[0].delta.content
116
+ except:
117
+ content = ""
118
  chatbot_value[-1]["loading"] = False
119
  message_content[-2]["content"] += reasoning_content or ""
120
  message_content[-1]["content"] += content or ""
 
129
  yield {chatbot: gr.update(value=chatbot_value)}
130
 
131
  chatbot_value[-1]["footer"] = "{:.2f}".format(time.time() -
132
+ start_time) + 's'
133
  chatbot_value[-1]["status"] = "done"
134
  yield {
135
  clear_btn: gr.update(disabled=False),
 
199
  avatar="https://api.dicebear.com/7.x/miniavs/svg?seed=3",
200
  variant="shadow"),
201
  bot_config=ChatbotBotConfig(
202
+ header='Xinyuan',
203
  avatar=
204
  "./xinyuan.png",
205
  actions=["copy", "retry"],
 
227
  chatbot.welcome_prompt_select(fn=prompt_select, outputs=[sender])
228
 
229
  if __name__ == "__main__":
230
+ demo.queue().launch()
231
+
232
+