Miemie123 commited on
Commit
b5ea193
·
verified ·
1 Parent(s): 3c1909d

Update app_shared.py

Browse files
Files changed (1) hide show
  1. app_shared.py +11 -3
app_shared.py CHANGED
@@ -559,7 +559,7 @@ class ChatManager:
559
  # st.write(f"❌ Qwen 调用失败:{e}")
560
  # return "调用 Qwen API 出错,请稍后再试。"
561
 
562
- def generate_response(self, messages: list, app_id: str, api_key: str):
563
  client = OpenAI(
564
  api_key=api_key,
565
  base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
@@ -568,19 +568,27 @@ class ChatManager:
568
  completion = client.chat.completions.create(
569
  model="qwen-plus-2025-04-28",
570
  messages=messages,
571
- extra_body={"enable_thinking": True}
 
572
  )
573
 
574
  full_reply = ""
 
 
575
  for chunk in completion:
576
  if chunk.choices:
577
  delta = chunk.choices[0].delta
578
- if hasattr(delta, "content") and delta.content:
 
 
579
  full_reply += delta.content
 
 
580
  return full_reply
581
 
582
 
583
 
 
584
  # =============================================================================
585
  # 页面渲染函数
586
  # =============================================================================
 
559
  # st.write(f"❌ Qwen 调用失败:{e}")
560
  # return "调用 Qwen API 出错,请稍后再试。"
561
 
562
+ def generate_response(self, messages: list, app_id: str, api_key: str) -> str:
563
  client = OpenAI(
564
  api_key=api_key,
565
  base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
 
568
  completion = client.chat.completions.create(
569
  model="qwen-plus-2025-04-28",
570
  messages=messages,
571
+ extra_body={"enable_thinking": True},
572
+ stream=True
573
  )
574
 
575
  full_reply = ""
576
+ reasoning = ""
577
+
578
  for chunk in completion:
579
  if chunk.choices:
580
  delta = chunk.choices[0].delta
581
+ if hasattr(delta, "reasoning_content") and delta.reasoning_content:
582
+ reasoning += delta.reasoning_content
583
+ elif delta.content:
584
  full_reply += delta.content
585
+
586
+ # 可选:你也可以将 reasoning 保存显示
587
  return full_reply
588
 
589
 
590
 
591
+
592
  # =============================================================================
593
  # 页面渲染函数
594
  # =============================================================================