Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 127
Add StructuredInputItem; patch version bump to 1.6.4#125
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -66,6 +66,7 @@ | ||
| GeneratedImageUpdated, | ||
| HiddenContextItem, | ||
| SDKHiddenContextItem, | ||
| StructuredInputItem, | ||
| Task, | ||
| TaskItem, | ||
| ThoughtTask, | ||
| @@ -552,14 +553,19 @@ def end_workflow(item: WorkflowItem): | ||
| if event.type == "run_item_stream_event": | ||
| event = event.item | ||
| if ( | ||
| event.type == "tool_call_item" | ||
| and event.raw_item.type == "function_call" | ||
| ): | ||
| current_tool_call = event.raw_item.call_id | ||
| current_item_id = event.raw_item.id | ||
| assert current_item_id | ||
| produced_items.add(current_item_id) | ||
| if event.type == "tool_call_item": | ||
| raw_item = event.raw_item | ||
| if isinstance(raw_item, dict): | ||
| if raw_item.get("type") == "function_call": | ||
| current_tool_call = event.call_id | ||
| current_item_id = raw_item.get("id") | ||
| assert current_item_id | ||
| produced_items.add(current_item_id) | ||
| elif raw_item.type == "function_call": | ||
| current_tool_call = event.call_id | ||
| current_item_id = raw_item.id | ||
| assert current_item_id | ||
| produced_items.add(current_item_id) | ||
Comment on lines
+556
to
+568
CollaboratorAuthor 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. Newer versions of openai-agents allow the raw item to be a dict, so handling that here (pyright caught it). | ||
| continue | ||
| if event.type != "raw_response_event": | ||
| @@ -964,6 +970,39 @@ async def task_to_input( | ||
| role="user", | ||
| ) | ||
| async def structured_input_to_input( | ||
| self, item: StructuredInputItem | ||
| ) -> TResponseInputItem | list[TResponseInputItem] | None: | ||
| """ | ||
| Convert a StructuredInputItem into input item(s) to send to the model. | ||
| """ | ||
| lines = [] | ||
| for question in item.inputs: | ||
| answer = question.answer | ||
| if answer is None: | ||
| lines.append(f"- {question.question}: unanswered") | ||
| elif answer.skipped: | ||
| lines.append(f"- {question.question}: skipped") | ||
| else: | ||
| lines.append(f"- {question.question}: {', '.join(answer.values)}") | ||
| text = ( | ||
| "A structured input request was displayed to the user with the following " | ||
| f"status: {item.status}\n<StructuredInput>\n" | ||
| + "\n".join(lines) | ||
| + "\n</StructuredInput>" | ||
| ) | ||
| return Message( | ||
| type="message", | ||
| content=[ | ||
| ResponseInputTextParam( | ||
| type="input_text", | ||
| text=text, | ||
| ), | ||
| ], | ||
| role="user", | ||
| ) | ||
| async def workflow_to_input( | ||
| self, item: WorkflowItem | ||
| ) -> TResponseInputItem | list[TResponseInputItem] | None: | ||
| @@ -1172,6 +1211,9 @@ async def _thread_item_to_input_item( | ||
| case TaskItem(): | ||
| out = await self.task_to_input(item) or [] | ||
| return out if isinstance(out, list) else [out] | ||
| case StructuredInputItem(): | ||
| out = await self.structured_input_to_input(item) or [] | ||
| return out if isinstance(out, list) else [out] | ||
| case HiddenContextItem(): | ||
| out = await self.hidden_context_to_input(item) or [] | ||
| return out if isinstance(out, list) else [out] | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
why these changes?
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.
Newer versions of openai-agents allow the raw item to be a dict, so handling that here (pyright caught it)!