MCPcopy Index your code
hub / github.com/algorithmicsuperintelligence/optillm / parse_conversation

Function parse_conversation

optillm/server.py:595–624  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

593 return contents
594
595def 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
626def tagged_conversation_to_messages(response_text):
627 """Convert a tagged conversation string or list of strings into a list of messages.

Callers 1

proxyFunction · 0.85

Calls 1

extract_optillm_approachFunction · 0.85

Tested by

no test coverage detected