Returns the assistant message object from common response envelope shapes.
| 562 | |
| 563 | // Returns the assistant message object from common response envelope shapes. |
| 564 | static const Value* FindAssistantMessageInResponse(const Document& response_doc) { |
| 565 | if (response_doc.HasMember(JSON_KEY_ROLE) && response_doc[JSON_KEY_ROLE].IsString()) { |
| 566 | return &response_doc; |
| 567 | } |
| 568 | if (response_doc.HasMember(JSON_KEY_TOOL_CALLS) |
| 569 | || response_doc.HasMember(JSON_KEY_CONTENT)) { |
| 570 | return &response_doc; |
| 571 | } |
| 572 | if (response_doc.HasMember(JSON_KEY_MESSAGE) |
| 573 | && response_doc[JSON_KEY_MESSAGE].IsObject()) { |
| 574 | return &response_doc[JSON_KEY_MESSAGE]; |
| 575 | } |
| 576 | if (response_doc.HasMember(JSON_KEY_CHOICES) |
| 577 | && response_doc[JSON_KEY_CHOICES].IsArray()) { |
| 578 | const Value& choices = response_doc[JSON_KEY_CHOICES]; |
| 579 | if (!choices.Empty() && choices[0].IsObject() |
| 580 | && choices[0].HasMember(JSON_KEY_MESSAGE) |
| 581 | && choices[0][JSON_KEY_MESSAGE].IsObject()) { |
| 582 | return &choices[0][JSON_KEY_MESSAGE]; |
| 583 | } |
| 584 | } |
| 585 | return nullptr; |
| 586 | } |
| 587 | |
| 588 | // Extracts assistant content text from string or content-part array formats. |
| 589 | static bool TryExtractAssistantContentText( |