- src/doc/ 拆分为 src/core/extraction/, matching/, validation/(核心业务逻辑) - src/bot/ 重命名为 src/infra/browser/(浏览器自动化基础设施) - fill_consumable_doc.py → src/infra/documents/consumable.py - 新增 Agent 调度模块:coordinator.py, events.py, session.py,重构 orchestrator.py - 更新 AGENTS.md、README.md 及所有子目录 README
70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
"""诊断脚本:检查 stream_chat 返回对象的字段结构"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
# 加载 .env
|
|
from dotenv import load_dotenv # noqa: E402
|
|
from llama_index.core.llms import ChatMessage # noqa: E402
|
|
|
|
from src.config import get_llm_config # noqa: E402
|
|
from src.core.extraction import _create_llm # noqa: E402
|
|
|
|
load_dotenv(Path(__file__).parent / ".env")
|
|
|
|
llm_config = get_llm_config()
|
|
print(f"LLM config: model={llm_config['model']}, api_base={llm_config['api_base']}")
|
|
|
|
llm = _create_llm()
|
|
messages = [
|
|
ChatMessage(role="system", content="你是一个助手"),
|
|
ChatMessage(role="user", content="1+1 等于几?"),
|
|
]
|
|
|
|
print("\n=== 检查 stream_chat 返回对象的字段 ===")
|
|
count = 0
|
|
try:
|
|
for resp in llm.stream_chat(messages, temperature=0.1):
|
|
count += 1
|
|
if count <= 3:
|
|
print(f"\n--- chunk #{count} ---")
|
|
print(f" type: {type(resp).__name__}")
|
|
print(f" delta: {repr(resp.delta)[:200]}")
|
|
if hasattr(resp, "additional_kwargs") and resp.additional_kwargs:
|
|
print(f" additional_kwargs keys: {list(resp.additional_kwargs.keys())}")
|
|
for k, v in resp.additional_kwargs.items():
|
|
val_preview = str(v)[:200]
|
|
print(f" additional_kwargs['{k}']: {val_preview}")
|
|
if hasattr(resp, "raw"):
|
|
raw = resp.raw
|
|
if isinstance(raw, dict):
|
|
print(f" raw keys: {list(raw.keys())}")
|
|
for k, v in raw.items():
|
|
val_preview = str(v)[:200]
|
|
print(f" raw['{k}']: {val_preview}")
|
|
else:
|
|
print(f" raw type: {type(raw)}")
|
|
if hasattr(resp, "message") and resp.message:
|
|
msg = resp.message
|
|
print(f" message type: {type(msg).__name__}")
|
|
if hasattr(msg, "additional_kwargs") and msg.additional_kwargs:
|
|
print(f" message.additional_kwargs keys: {list(msg.additional_kwargs.keys())}")
|
|
for k, v in msg.additional_kwargs.items():
|
|
val_preview = str(v)[:200]
|
|
print(f" message.additional_kwargs['{k}']: {val_preview}")
|
|
if hasattr(msg, "reasoning_content"):
|
|
rc = msg.reasoning_content
|
|
print(f" message.reasoning_content: {repr(rc)[:200]}")
|
|
elif count == 4:
|
|
print("\n... (更多 chunk 省略)")
|
|
if count >= 10:
|
|
break
|
|
print(f"\n=== 共收到 {count} 个 chunk ===")
|
|
except Exception as e:
|
|
print(f"\n错误: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|