Zenith Wang commited on
Commit
fa16180
·
1 Parent(s): f988bdc

Revert "Change Step-3 to Step3 throughout the application"

Browse files

This reverts commit ed348ef33c276c67aec185519cf3c04861eae0d1.

Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -71,7 +71,7 @@ def bot_response(history, saved_message, saved_images, system_prompt, temperatur
71
  yield history
72
 
73
  def process_message(message, history, images, system_prompt, temperature, max_tokens, top_p):
74
- """处理消息并调用Step3 API"""
75
 
76
  print(f"[DEBUG] Processing message: {message[:100] if message else 'None'}")
77
  print(f"[DEBUG] Has images: {images is not None}")
@@ -115,11 +115,11 @@ def process_message(message, history, images, system_prompt, temperature, max_to
115
  base64_image = image_to_base64(image_path)
116
  if base64_image:
117
  content.append({
118
- "type": "image_url",
119
- "image_url": {
120
  "url": f"data:image/jpeg;base64,{base64_image}",
121
- "detail": "high"
122
- }
123
  })
124
  print(f"[DEBUG] Successfully added image to content")
125
  else:
@@ -128,7 +128,7 @@ def process_message(message, history, images, system_prompt, temperature, max_to
128
  # 添加文本消息
129
  if message:
130
  content.append({
131
- "type": "text",
132
  "text": message
133
  })
134
  print(f"[DEBUG] Added text to content: {message[:100]}")
@@ -191,39 +191,39 @@ def process_message(message, history, images, system_prompt, temperature, max_to
191
  print(f"[DEBUG] Making API call to {BASE_URL}")
192
 
193
  # 调用API
194
- response = client.chat.completions.create(
195
  model="step-3",
196
- messages=messages,
197
- temperature=temperature,
198
- max_tokens=max_tokens,
199
  top_p=top_p,
200
- stream=True
201
- )
202
-
203
  print("[DEBUG] API call successful, processing stream...")
204
 
205
  # 流式输出
206
- full_response = ""
207
  chunk_count = 0
208
  in_reasoning = False
209
  reasoning_content = ""
210
  final_content = ""
211
  has_reasoning_field = False # 标记是否通过 delta.reasoning 字段获取 CoT
212
 
213
- for chunk in response:
214
  chunk_count += 1
215
  if chunk.choices and len(chunk.choices) > 0:
216
- delta = chunk.choices[0].delta
217
-
218
- # 检查 delta.reasoning 字段(Step3 API 的 CoT 内容)
219
  if hasattr(delta, 'reasoning') and delta.reasoning:
220
  has_reasoning_field = True
221
  reasoning_content += delta.reasoning
222
  print(f"[DEBUG] CoT chunk: {delta.reasoning[:50] if len(delta.reasoning) > 50 else delta.reasoning}")
223
 
224
  # 处理常规 content 字段
225
- if hasattr(delta, 'content') and delta.content:
226
- content = delta.content
227
 
228
  # 如果通过 reasoning 字段获取了 CoT,content 就是最终答案
229
  if has_reasoning_field:
@@ -298,7 +298,7 @@ def process_message(message, history, images, system_prompt, temperature, max_to
298
  print("[DEBUG] No response content received")
299
  history[-1][1] = "⚠️ No response received from API"
300
  yield history
301
-
302
  except Exception as e:
303
  print(f"[DEBUG] API error: {e}")
304
  import traceback
@@ -410,11 +410,11 @@ css = """
410
  }
411
  """
412
 
413
- with gr.Blocks(title="Step3", theme=gr.themes.Soft(), css=css) as demo:
414
  gr.Markdown("""
415
- # <img src="https://huggingface.co/stepfun-ai/step3/resolve/main/figures/stepfun-logo.png" alt="StepFun Logo" style="height: 30px; vertical-align: middle; margin-right: 8px;"> Step3
416
 
417
- Welcome to Step3, an advanced multimodal AI assistant by <a href="https://stepfun.com/" target="_blank" style="color: #0969da;">StepFun</a>.
418
  """)
419
 
420
  # 创建状态变量来保存消息和图片
@@ -467,7 +467,7 @@ with gr.Blocks(title="Step3", theme=gr.themes.Soft(), css=css) as demo:
467
  with gr.Accordion("⚙️ Settings", open=False):
468
  system_prompt = gr.Textbox(
469
  label="System Prompt",
470
- value="You are Step3, an advanced multimodal AI assistant developed by StepFun. You have strong capabilities in image understanding, reasoning, and providing detailed, helpful responses. You can analyze images, answer questions, and assist with various tasks while showing your reasoning process.",
471
  lines=4
472
  )
473
  temperature_slider = gr.Slider(
 
71
  yield history
72
 
73
  def process_message(message, history, images, system_prompt, temperature, max_tokens, top_p):
74
+ """处理消息并调用Step-3 API"""
75
 
76
  print(f"[DEBUG] Processing message: {message[:100] if message else 'None'}")
77
  print(f"[DEBUG] Has images: {images is not None}")
 
115
  base64_image = image_to_base64(image_path)
116
  if base64_image:
117
  content.append({
118
+ "type": "image_url",
119
+ "image_url": {
120
  "url": f"data:image/jpeg;base64,{base64_image}",
121
+ "detail": "high"
122
+ }
123
  })
124
  print(f"[DEBUG] Successfully added image to content")
125
  else:
 
128
  # 添加文本消息
129
  if message:
130
  content.append({
131
+ "type": "text",
132
  "text": message
133
  })
134
  print(f"[DEBUG] Added text to content: {message[:100]}")
 
191
  print(f"[DEBUG] Making API call to {BASE_URL}")
192
 
193
  # 调用API
194
+ response = client.chat.completions.create(
195
  model="step-3",
196
+ messages=messages,
197
+ temperature=temperature,
198
+ max_tokens=max_tokens,
199
  top_p=top_p,
200
+ stream=True
201
+ )
202
+
203
  print("[DEBUG] API call successful, processing stream...")
204
 
205
  # 流式输出
206
+ full_response = ""
207
  chunk_count = 0
208
  in_reasoning = False
209
  reasoning_content = ""
210
  final_content = ""
211
  has_reasoning_field = False # 标记是否通过 delta.reasoning 字段获取 CoT
212
 
213
+ for chunk in response:
214
  chunk_count += 1
215
  if chunk.choices and len(chunk.choices) > 0:
216
+ delta = chunk.choices[0].delta
217
+
218
+ # 检查 delta.reasoning 字段(Step-3 API 的 CoT 内容)
219
  if hasattr(delta, 'reasoning') and delta.reasoning:
220
  has_reasoning_field = True
221
  reasoning_content += delta.reasoning
222
  print(f"[DEBUG] CoT chunk: {delta.reasoning[:50] if len(delta.reasoning) > 50 else delta.reasoning}")
223
 
224
  # 处理常规 content 字段
225
+ if hasattr(delta, 'content') and delta.content:
226
+ content = delta.content
227
 
228
  # 如果通过 reasoning 字段获取了 CoT,content 就是最终答案
229
  if has_reasoning_field:
 
298
  print("[DEBUG] No response content received")
299
  history[-1][1] = "⚠️ No response received from API"
300
  yield history
301
+
302
  except Exception as e:
303
  print(f"[DEBUG] API error: {e}")
304
  import traceback
 
410
  }
411
  """
412
 
413
+ with gr.Blocks(title="Step-3", theme=gr.themes.Soft(), css=css) as demo:
414
  gr.Markdown("""
415
+ # <img src="https://huggingface.co/stepfun-ai/step3/resolve/main/figures/stepfun-logo.png" alt="StepFun Logo" style="height: 30px; vertical-align: middle; margin-right: 8px;"> Step-3
416
 
417
+ Welcome to Step-3, an advanced multimodal AI assistant by <a href="https://stepfun.com/" target="_blank" style="color: #0969da;">StepFun</a>.
418
  """)
419
 
420
  # 创建状态变量来保存消息和图片
 
467
  with gr.Accordion("⚙️ Settings", open=False):
468
  system_prompt = gr.Textbox(
469
  label="System Prompt",
470
+ value="You are Step-3, an advanced multimodal AI assistant developed by StepFun. You have strong capabilities in image understanding, reasoning, and providing detailed, helpful responses. You can analyze images, answer questions, and assist with various tasks while showing your reasoning process.",
471
  lines=4
472
  )
473
  temperature_slider = gr.Slider(