Return text from the final assistant message only.
(
text_by_part: OrderedDict[str, str], msg_by_part: dict[str, str]
)
| 404 | |
| 405 | |
| 406 | def _final_answer( |
| 407 | text_by_part: OrderedDict[str, str], msg_by_part: dict[str, str] |
| 408 | ) -> str: |
| 409 | """Return text from the final assistant message only.""" |
| 410 | if not text_by_part: |
| 411 | return "" |
| 412 | last_msg = None |
| 413 | for part_id in text_by_part: |
| 414 | last_msg = msg_by_part.get(part_id, part_id) |
| 415 | answer = "".join( |
| 416 | text |
| 417 | for part_id, text in text_by_part.items() |
| 418 | if msg_by_part.get(part_id, part_id) == last_msg |
| 419 | ) |
| 420 | return _visible_text(answer) |
| 421 | |
| 422 | |
| 423 | def _build_trajectory_from_events( |
no test coverage detected