Skip to content

Commit

Permalink
Merge pull request #88 from femto/fix_msg
Browse files Browse the repository at this point in the history
fix msg
  • Loading branch information
codelion authored Nov 7, 2024
2 parents 0ab9f8c + 3cfe9f3 commit 476719c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions optillm.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,24 @@ def parse_conversation(messages):
role = message['role']
content = message['content']

# Handle content that could be a list or string
if isinstance(content, list):
# Extract text content from the list
text_content = ' '.join(
item['text'] for item in content
if isinstance(item, dict) and item.get('type') == 'text'
)
else:
text_content = content

if role == 'system':
system_prompt, optillm_approach = extract_optillm_approach(content)
system_prompt, optillm_approach = extract_optillm_approach(text_content)
elif role == 'user':
if not optillm_approach:
content, optillm_approach = extract_optillm_approach(content)
conversation.append(f"User: {content}")
text_content, optillm_approach = extract_optillm_approach(text_content)
conversation.append(f"User: {text_content}")
elif role == 'assistant':
conversation.append(f"Assistant: {content}")
conversation.append(f"Assistant: {text_content}")

initial_query = "\n".join(conversation)
return system_prompt, initial_query, optillm_approach
Expand Down

0 comments on commit 476719c

Please sign in to comment.