Spaces:
Running
Running
Update core/pipeline_agent.py
Browse files- core/pipeline_agent.py +8 -21
core/pipeline_agent.py
CHANGED
|
@@ -330,6 +330,7 @@ class SSciPipelineAgent:
|
|
| 330 |
if current_model != "deepseek-reasoner":
|
| 331 |
payload["temperature"] = temp
|
| 332 |
|
|
|
|
| 333 |
has_started_reasoning = False
|
| 334 |
start_time = time.time()
|
| 335 |
|
|
@@ -354,13 +355,13 @@ class SSciPipelineAgent:
|
|
| 354 |
if not has_started_reasoning:
|
| 355 |
yield "\n<think>\n"
|
| 356 |
has_started_reasoning = True
|
| 357 |
-
logging.info(f"🤔 [R1 推理启动] 开始
|
| 358 |
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
|
| 365 |
yield reasoning_content
|
| 366 |
continue
|
|
@@ -369,33 +370,19 @@ class SSciPipelineAgent:
|
|
| 369 |
yield "\n</think>\n\n"
|
| 370 |
has_started_reasoning = False
|
| 371 |
elapsed = time.time() - start_time
|
| 372 |
-
|
| 373 |
-
# 思考结束,终端换行,并记录日志
|
| 374 |
-
sys.stdout.write("\n")
|
| 375 |
-
sys.stdout.flush()
|
| 376 |
-
logging.info(f"💡 [R1 推理结束] 耗时 {elapsed:.1f}秒。开始在终端流式输出正文...")
|
| 377 |
|
| 378 |
if content:
|
| 379 |
-
# 🔥 正文内容同样直接推送到终端流并强制刷新
|
| 380 |
-
sys.stdout.write(content)
|
| 381 |
-
sys.stdout.flush()
|
| 382 |
-
|
| 383 |
yield content
|
| 384 |
|
| 385 |
except Exception:
|
| 386 |
pass
|
| 387 |
|
| 388 |
-
# 整个流结束,终端换行
|
| 389 |
-
sys.stdout.write("\n")
|
| 390 |
-
sys.stdout.flush()
|
| 391 |
logging.info(f"🏁 [流式生成结束] 总耗时 {(time.time() - start_time):.1f}秒。")
|
| 392 |
return
|
| 393 |
except GeneratorExit:
|
| 394 |
raise
|
| 395 |
except Exception as e:
|
| 396 |
-
# 异常中断时也要确保换行,防止日志排版错乱
|
| 397 |
-
sys.stdout.write("\n")
|
| 398 |
-
sys.stdout.flush()
|
| 399 |
logging.error(f"❌ [流式中断]: {e}")
|
| 400 |
if attempt == 2:
|
| 401 |
raise
|
|
|
|
| 330 |
if current_model != "deepseek-reasoner":
|
| 331 |
payload["temperature"] = temp
|
| 332 |
|
| 333 |
+
think_heartbeat = 0
|
| 334 |
has_started_reasoning = False
|
| 335 |
start_time = time.time()
|
| 336 |
|
|
|
|
| 355 |
if not has_started_reasoning:
|
| 356 |
yield "\n<think>\n"
|
| 357 |
has_started_reasoning = True
|
| 358 |
+
logging.info(f"🤔 [R1 推理启动] 开始深度思考...")
|
| 359 |
|
| 360 |
+
think_heartbeat += 1
|
| 361 |
+
|
| 362 |
+
if think_heartbeat % 25 == 0:
|
| 363 |
+
elapsed = time.time() - start_time
|
| 364 |
+
logging.info(f"⏳ [DeepSeek 心跳] {current_model} 思考中... ({elapsed:.1f}秒, 接收 {think_heartbeat} 块)")
|
| 365 |
|
| 366 |
yield reasoning_content
|
| 367 |
continue
|
|
|
|
| 370 |
yield "\n</think>\n\n"
|
| 371 |
has_started_reasoning = False
|
| 372 |
elapsed = time.time() - start_time
|
| 373 |
+
logging.info(f"💡 [R1 推理结束] 耗时 {elapsed:.1f}秒。开始流式输出正文...")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
if content:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
yield content
|
| 377 |
|
| 378 |
except Exception:
|
| 379 |
pass
|
| 380 |
|
|
|
|
|
|
|
|
|
|
| 381 |
logging.info(f"🏁 [流式生成结束] 总耗时 {(time.time() - start_time):.1f}秒。")
|
| 382 |
return
|
| 383 |
except GeneratorExit:
|
| 384 |
raise
|
| 385 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
| 386 |
logging.error(f"❌ [流式中断]: {e}")
|
| 387 |
if attempt == 2:
|
| 388 |
raise
|