Skip to content

Commit 476719c

Browse files
authored
Merge pull request #88 from femto/fix_msg
fix msg
2 parents 0ab9f8c + 3cfe9f3 commit 476719c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

optillm.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,24 @@ def parse_conversation(messages):
271271
role = message['role']
272272
content = message['content']
273273

274+
# Handle content that could be a list or string
275+
if isinstance(content, list):
276+
# Extract text content from the list
277+
text_content = ' '.join(
278+
item['text'] for item in content
279+
if isinstance(item, dict) and item.get('type') == 'text'
280+
)
281+
else:
282+
text_content = content
283+
274284
if role == 'system':
275-
system_prompt, optillm_approach = extract_optillm_approach(content)
285+
system_prompt, optillm_approach = extract_optillm_approach(text_content)
276286
elif role == 'user':
277287
if not optillm_approach:
278-
content, optillm_approach = extract_optillm_approach(content)
279-
conversation.append(f"User: {content}")
288+
text_content, optillm_approach = extract_optillm_approach(text_content)
289+
conversation.append(f"User: {text_content}")
280290
elif role == 'assistant':
281-
conversation.append(f"Assistant: {content}")
291+
conversation.append(f"Assistant: {text_content}")
282292

283293
initial_query = "\n".join(conversation)
284294
return system_prompt, initial_query, optillm_approach

0 commit comments

Comments
 (0)