| 578 | yield "data: [DONE]\n\n" |
| 579 | |
| 580 | def extract_contents(response_obj): |
| 581 | contents = [] |
| 582 | # Handle both single response and list of responses |
| 583 | responses = response_obj if isinstance(response_obj, list) else [response_obj] |
| 584 | |
| 585 | for response in responses: |
| 586 | # Extract content from first choice if it exists |
| 587 | if (response.get('choices') and |
| 588 | len(response['choices']) > 0 and |
| 589 | response['choices'][0].get('message') and |
| 590 | response['choices'][0]['message'].get('content')): |
| 591 | contents.append(response['choices'][0]['message']['content']) |
| 592 | |
| 593 | return contents |
| 594 | |
| 595 | def parse_conversation(messages): |
| 596 | system_prompt = "" |