update the code with review comments

This commit is contained in:
Willem Jiang
2026-05-16 17:07:53 +08:00
parent ba99a23814
commit 7752e74e2b
2 changed files with 34 additions and 13 deletions
@@ -194,7 +194,7 @@ class DeerFlowSummarizationMiddleware(SummarizationMiddleware):
formatted = get_buffer_string(trimmed)
try:
response = self.model.invoke(
response = self.model.with_config(callbacks=[]).invoke(
self.summary_prompt.format(messages=formatted).rstrip(),
config={
"metadata": {"lc_source": "summarization"},
@@ -223,7 +223,7 @@ class DeerFlowSummarizationMiddleware(SummarizationMiddleware):
formatted = get_buffer_string(trimmed)
try:
response = await self.model.ainvoke(
response = await self.model.with_config(callbacks=[]).ainvoke(
self.summary_prompt.format(messages=formatted).rstrip(),
config={
"metadata": {"lc_source": "summarization"},
@@ -235,9 +235,11 @@ class DeerFlowSummarizationMiddleware(SummarizationMiddleware):
return f"Error generating summary: {e!s}"
def _extract_summary_text(self, response: Any) -> str:
summary_text = getattr(response, "content", None)
# Prefer .text which normalizes list content blocks (e.g. [{"type": "text", "text": "..."}]).
# Fall back to .content for non-LangChain responses.
summary_text = getattr(response, "text", None)
if summary_text is None:
summary_text = getattr(response, "text", "")
summary_text = getattr(response, "content", "")
return summary_text.strip() if isinstance(summary_text, str) else str(summary_text).strip()
@override