Convert LLMResponse to ChatDocument. Args: response (LLMResponse): LLMResponse to convert. displayed (bool): Whether this response was displayed to the user. recognize_recipient_in_content (bool): Whether to parse message text for
(
response: LLMResponse,
displayed: bool = False,
recognize_recipient_in_content: bool = True,
)
| 330 | |
| 331 | @staticmethod |
| 332 | def from_LLMResponse( |
| 333 | response: LLMResponse, |
| 334 | displayed: bool = False, |
| 335 | recognize_recipient_in_content: bool = True, |
| 336 | ) -> "ChatDocument": |
| 337 | """ |
| 338 | Convert LLMResponse to ChatDocument. |
| 339 | Args: |
| 340 | response (LLMResponse): LLMResponse to convert. |
| 341 | displayed (bool): Whether this response was displayed to the user. |
| 342 | recognize_recipient_in_content (bool): Whether to parse message text |
| 343 | for recipient routing (``TO[<recipient>]:`` and JSON |
| 344 | ``{"recipient": ...}``). Default True. |
| 345 | Returns: |
| 346 | ChatDocument: ChatDocument representation of this LLMResponse. |
| 347 | """ |
| 348 | recipient, message = response.get_recipient_and_message( |
| 349 | recognize_recipient_in_content |
| 350 | ) |
| 351 | message = message.strip() |
| 352 | if message in ["''", '""']: |
| 353 | message = "" |
| 354 | if response.function_call is not None: |
| 355 | ChatDocument._clean_fn_call(response.function_call) |
| 356 | if response.oai_tool_calls is not None: |
| 357 | # there must be at least one if it's not None |
| 358 | for oai_tc in response.oai_tool_calls: |
| 359 | ChatDocument._clean_fn_call(oai_tc.function) |
| 360 | return ChatDocument( |
| 361 | content=message, |
| 362 | reasoning=response.reasoning, |
| 363 | content_with_reasoning=response.message_with_reasoning, |
| 364 | content_any=message, |
| 365 | oai_tool_calls=response.oai_tool_calls, |
| 366 | function_call=response.function_call, |
| 367 | metadata=ChatDocMetaData( |
| 368 | source=Entity.LLM, |
| 369 | sender=Entity.LLM, |
| 370 | usage=response.usage, |
| 371 | displayed=displayed, |
| 372 | cached=response.cached, |
| 373 | recipient=recipient, |
| 374 | ), |
| 375 | ) |
| 376 | |
| 377 | @staticmethod |
| 378 | def from_str(msg: str) -> "ChatDocument": |
no test coverage detected