Dango233 commited on
Commit
c27421f
·
1 Parent(s): 1b1a947

Response waiting state handling

Browse files
Files changed (2) hide show
  1. app.py +27 -11
  2. lang.py +2 -0
app.py CHANGED
@@ -33,31 +33,38 @@ class DynamicState:
33
  self.stream_completed = False
34
  self.in_cot = True
35
  self.current_language = "en"
 
36
 
37
  def control_button_handler(self):
38
- """切换流式传输状态"""
39
- if self.should_stream:
40
- self.should_stream = False
41
- else:
 
 
42
  self.stream_completed = False
43
- self.should_stream = True
44
  return self.ui_state_controller()
45
 
46
  def ui_state_controller(self):
47
  """生成动态UI组件状态"""
48
- print("UPDATE UI!!")
49
  # [control_button, thought_editor, reset_button]
50
  lang_data = LANGUAGE_CONFIG[self.current_language]
51
  control_value = (
52
  lang_data["pause_btn"] if self.should_stream else lang_data["generate_btn"]
53
  )
54
  control_variant = "secondary" if self.should_stream else "primary"
55
- status_suffix = (
56
- lang_data["completed"]
57
- if self.stream_completed
58
- else lang_data["interrupted"]
59
- )
 
 
 
 
60
  editor_label = f"{lang_data['editor_label']} - {status_suffix}"
 
61
  return (
62
  gr.update(value=control_value, variant=control_variant),
63
  gr.update(label=editor_label),
@@ -143,6 +150,14 @@ class ConvoState:
143
  coordinator = CoordinationManager(self.sync_threshold, current_content)
144
 
145
  try:
 
 
 
 
 
 
 
 
146
  messages = [
147
  {"role": "user", "content": user_prompt},
148
  {
@@ -166,6 +181,7 @@ class ConvoState:
166
  break
167
 
168
  if chunk_content:
 
169
  full_response += chunk_content
170
  # Update Convo State
171
  think_complete = "</think>" in full_response
 
33
  self.stream_completed = False
34
  self.in_cot = True
35
  self.current_language = "en"
36
+ self.waiting_api = False # 新增等待状态标志
37
 
38
  def control_button_handler(self):
39
+ original_state = self.should_stream
40
+ self.should_stream = not self.should_stream
41
+
42
+ # 当从暂停->生成时激活等待状态
43
+ if not original_state and self.should_stream:
44
+ self.waiting_api = True
45
  self.stream_completed = False
46
+
47
  return self.ui_state_controller()
48
 
49
  def ui_state_controller(self):
50
  """生成动态UI组件状态"""
 
51
  # [control_button, thought_editor, reset_button]
52
  lang_data = LANGUAGE_CONFIG[self.current_language]
53
  control_value = (
54
  lang_data["pause_btn"] if self.should_stream else lang_data["generate_btn"]
55
  )
56
  control_variant = "secondary" if self.should_stream else "primary"
57
+ # 处理等待状态显示
58
+ if self.waiting_api:
59
+ status_suffix = lang_data["waiting_api"]
60
+ else:
61
+ status_suffix = (
62
+ lang_data["completed"]
63
+ if self.stream_completed
64
+ else lang_data["interrupted"]
65
+ )
66
  editor_label = f"{lang_data['editor_label']} - {status_suffix}"
67
+
68
  return (
69
  gr.update(value=control_value, variant=control_variant),
70
  gr.update(label=editor_label),
 
150
  coordinator = CoordinationManager(self.sync_threshold, current_content)
151
 
152
  try:
153
+
154
+ # 初始等待状态更新
155
+ if dynamic_state.waiting_api:
156
+ status = lang_data["waiting_api"]
157
+ editor_label = f"{lang_data['editor_label']} - {status}"
158
+ yield full_response, gr.update(label=editor_label), self.flatten_output()
159
+
160
+ coordinator = CoordinationManager(self.sync_threshold, current_content)
161
  messages = [
162
  {"role": "user", "content": user_prompt},
163
  {
 
181
  break
182
 
183
  if chunk_content:
184
+ dynamic_state.waiting_api = False
185
  full_response += chunk_content
186
  # Update Convo State
187
  think_complete = "</think>" in full_response
lang.py CHANGED
@@ -33,6 +33,7 @@ LANGUAGE_CONFIG = {
33
  },
34
  ],
35
  "editor_default": "AI thought will start with this, leave blank to think freely",
 
36
  },
37
  "zh": {
38
  "title": "CoT-Lab: 人机协同思维实验室\n在一轮对话中跟随、学习、迭代思维链",
@@ -68,5 +69,6 @@ LANGUAGE_CONFIG = {
68
  {"role": "assistant", "content": "**Shift+Enter** 可以暂停/继续AI生成"},
69
  ],
70
  "editor_default": "AI思维会以此开头,留空即为默认思考",
 
71
  },
72
  }
 
33
  },
34
  ],
35
  "editor_default": "AI thought will start with this, leave blank to think freely",
36
+ "waiting_api": "⏳ Waiting for Deepseek API response",
37
  },
38
  "zh": {
39
  "title": "CoT-Lab: 人机协同思维实验室\n在一轮对话中跟随、学习、迭代思维链",
 
69
  {"role": "assistant", "content": "**Shift+Enter** 可以暂停/继续AI生成"},
70
  ],
71
  "editor_default": "AI思维会以此开头,留空即为默认思考",
72
+ "waiting_api": "⏳ 等待Deepseek API响应",
73
  },
74
  }