(messages)
| 593 | return contents |
| 594 | |
| 595 | def parse_conversation(messages): |
| 596 | system_prompt = "" |
| 597 | conversation = [] |
| 598 | optillm_approach = None |
| 599 | |
| 600 | for message in messages: |
| 601 | role = message['role'] |
| 602 | content = message['content'] |
| 603 | |
| 604 | # Handle content that could be a list or string |
| 605 | if isinstance(content, list): |
| 606 | # Extract text content from the list |
| 607 | text_content = ' '.join( |
| 608 | item['text'] for item in content |
| 609 | if isinstance(item, dict) and item.get('type') == 'text' |
| 610 | ) |
| 611 | else: |
| 612 | text_content = content |
| 613 | |
| 614 | if role == 'system': |
| 615 | system_prompt, optillm_approach = extract_optillm_approach(text_content) |
| 616 | elif role == 'user': |
| 617 | if not optillm_approach: |
| 618 | text_content, optillm_approach = extract_optillm_approach(text_content) |
| 619 | conversation.append(f"User: {text_content}") |
| 620 | elif role == 'assistant': |
| 621 | conversation.append(f"Assistant: {text_content}") |
| 622 | |
| 623 | initial_query = "\n".join(conversation) |
| 624 | return system_prompt, initial_query, optillm_approach |
| 625 | |
| 626 | def tagged_conversation_to_messages(response_text): |
| 627 | """Convert a tagged conversation string or list of strings into a list of messages. |
no test coverage detected