fix(message_summary): format workflow token usage
This commit is contained in:
@@ -305,10 +305,28 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
||||
if not usage:
|
||||
return answer
|
||||
|
||||
prompt_tokens = usage.get("prompt_tokens", 0)
|
||||
completion_tokens = usage.get("completion_tokens", 0)
|
||||
total_tokens = usage.get("total_tokens", 0)
|
||||
tokens_info = f"\n\n【tokens】输入: {prompt_tokens} 生成: {completion_tokens} 总: {total_tokens}"
|
||||
prompt_tokens = usage.get("prompt_tokens")
|
||||
completion_tokens = usage.get("completion_tokens")
|
||||
total_tokens = usage.get("total_tokens")
|
||||
latency = usage.get("latency")
|
||||
|
||||
info_parts = []
|
||||
# chat-messages 风格的明细
|
||||
if prompt_tokens is not None and completion_tokens is not None:
|
||||
info_parts.append(f"输入: {prompt_tokens}")
|
||||
info_parts.append(f"生成: {completion_tokens}")
|
||||
|
||||
# workflow 常见只有 total_tokens
|
||||
if total_tokens is not None:
|
||||
info_parts.append(f"总: {total_tokens}")
|
||||
|
||||
if latency is not None:
|
||||
info_parts.append(f"耗时: {latency}s")
|
||||
|
||||
if not info_parts:
|
||||
return answer
|
||||
|
||||
tokens_info = "\n\n【tokens】" + " ".join(info_parts)
|
||||
return answer + tokens_info
|
||||
|
||||
def _clean_summary_output(self, answer: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user