fix: _estimate_tokens/_summarize 处理 native 的 content=None
This commit is contained in:
parent
0e5368a894
commit
acda8bb7e7
@ -966,7 +966,7 @@ class AgentExecutor:
|
|||||||
"""简单 token 估算(中文 ~1.5 字符/token,英文 ~4 字符/token)"""
|
"""简单 token 估算(中文 ~1.5 字符/token,英文 ~4 字符/token)"""
|
||||||
total = 0
|
total = 0
|
||||||
for m in self._msgs:
|
for m in self._msgs:
|
||||||
content = m.get("content", "")
|
content = m.get("content") or ""
|
||||||
# 简单估算:平均每 2 字符 1 token
|
# 简单估算:平均每 2 字符 1 token
|
||||||
total += len(content) // 2 + 1
|
total += len(content) // 2 + 1
|
||||||
return total
|
return total
|
||||||
@ -974,10 +974,10 @@ class AgentExecutor:
|
|||||||
async def _summarize(self, messages: list) -> str:
|
async def _summarize(self, messages: list) -> str:
|
||||||
"""压缩消息为摘要"""
|
"""压缩消息为摘要"""
|
||||||
if len(messages) <= 2:
|
if len(messages) <= 2:
|
||||||
return "\n".join(m.get("content", "")[:200] for m in messages)
|
return "\n".join((m.get("content") or "")[:200] for m in messages)
|
||||||
|
|
||||||
text = "\n".join(
|
text = "\n".join(
|
||||||
f"[{m['role']}]: {m.get('content', '')[:500]}"
|
f"[{m['role']}]: {(m.get('content') or '')[:500]}"
|
||||||
for m in messages
|
for m in messages
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user