-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
fix(responses): extract system content blocks into instructions #23698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,17 +164,19 @@ def convert_chat_completion_messages_to_responses_api( | |
| instructions = f"{instructions} {content}" | ||
| else: | ||
| instructions = content | ||
| else: | ||
| input_items.append( | ||
| { | ||
| "type": "message", | ||
| "role": role, | ||
| "content": self._convert_content_to_responses_format( | ||
| content, # type: ignore[arg-type] | ||
| role, # type: ignore | ||
| ), | ||
| } | ||
| ) | ||
| elif isinstance(content, list): | ||
| # Extract text from content blocks (e.g. [{"type": "text", "text": "..."}]) | ||
| text_parts = [] | ||
| for block in content: | ||
| if isinstance(block, dict) and block.get("type") == "text": | ||
| text_parts.append(block.get("text", "")) | ||
| elif isinstance(block, str): | ||
| text_parts.append(block) | ||
| extracted = " ".join(text_parts) | ||
| if instructions: | ||
| instructions = f"{instructions} {extracted}" | ||
| else: | ||
| instructions = extracted | ||
|
Comment on lines
+167
to
+179
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-text content blocks in system messages are silently discarded The previous |
||
| elif role == "tool": | ||
| # Convert tool message to function call output format | ||
| # The Responses API expects 'output' to be a list with input_text/input_image types | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty
extractedsilently setsinstructionsto""When
contentis a list where no block is oftype == "text"(e.g. a system message containing only image blocks),text_partswill be empty andextractedwill be"". The subsequent assignment then overwritesinstructionswith an empty string rather than leaving it asNone, which changes the downstream behaviour — callers that checkif instructions:orif instructions is not None:will now get different results.Additionally, if
instructionsalready has content and this code path runs, the resulting value has a trailing space:f"{instructions} ".Consider guarding the assignment so it only fires when there is actually extracted text: