mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-24 00:45:57 +00:00
fix: use AIMessage content for summarization response parsing
Agent-Logs-Url: https://github.com/bytedance/deer-flow/sessions/0b34cccd-f69a-4f68-bfa6-9a41256b63b5 Co-authored-by: WillemJiang <219644+WillemJiang@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
c995c3a394
commit
6ffe267d20
@@ -201,7 +201,7 @@ class DeerFlowSummarizationMiddleware(SummarizationMiddleware):
|
|||||||
"callbacks": [],
|
"callbacks": [],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return response.text.strip()
|
return self._extract_summary_text(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error generating summary: {e!s}"
|
return f"Error generating summary: {e!s}"
|
||||||
|
|
||||||
@@ -230,10 +230,16 @@ class DeerFlowSummarizationMiddleware(SummarizationMiddleware):
|
|||||||
"callbacks": [],
|
"callbacks": [],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return response.text.strip()
|
return self._extract_summary_text(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error generating summary: {e!s}"
|
return f"Error generating summary: {e!s}"
|
||||||
|
|
||||||
|
def _extract_summary_text(self, response: Any) -> str:
|
||||||
|
summary_text = getattr(response, "content", None)
|
||||||
|
if summary_text is None:
|
||||||
|
summary_text = getattr(response, "text", "")
|
||||||
|
return summary_text.strip() if isinstance(summary_text, str) else str(summary_text).strip()
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def _build_new_messages(self, summary: str) -> list[HumanMessage]:
|
def _build_new_messages(self, summary: str) -> list[HumanMessage]:
|
||||||
"""Override the base implementation to let the human message with the special name 'summary'.
|
"""Override the base implementation to let the human message with the special name 'summary'.
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ def _middleware(
|
|||||||
preserve_recent_skill_tokens_per_skill: int = 0,
|
preserve_recent_skill_tokens_per_skill: int = 0,
|
||||||
) -> DeerFlowSummarizationMiddleware:
|
) -> DeerFlowSummarizationMiddleware:
|
||||||
model = MagicMock()
|
model = MagicMock()
|
||||||
model.invoke.return_value = SimpleNamespace(text="compressed summary")
|
model.invoke.return_value = AIMessage(content="compressed summary")
|
||||||
return DeerFlowSummarizationMiddleware(
|
return DeerFlowSummarizationMiddleware(
|
||||||
model=model,
|
model=model,
|
||||||
trigger=trigger,
|
trigger=trigger,
|
||||||
@@ -672,7 +672,7 @@ async def test_acreate_summary_suppresses_callbacks() -> None:
|
|||||||
"""_acreate_summary must pass callbacks=[] to prevent the internal LLM call
|
"""_acreate_summary must pass callbacks=[] to prevent the internal LLM call
|
||||||
from producing visible streaming events in the frontend (issue #2804)."""
|
from producing visible streaming events in the frontend (issue #2804)."""
|
||||||
middleware = _middleware()
|
middleware = _middleware()
|
||||||
middleware.model.ainvoke = mock.AsyncMock(return_value=SimpleNamespace(text="async summary"))
|
middleware.model.ainvoke = mock.AsyncMock(return_value=AIMessage(content="async summary"))
|
||||||
|
|
||||||
await middleware._acreate_summary(_messages())
|
await middleware._acreate_summary(_messages())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user