|
| 1 | +import json |
1 | 2 | import os |
2 | 3 | import uuid |
3 | 4 | from dataclasses import dataclass |
|
45 | 46 | ) |
46 | 47 | from openai.types.responses.response_function_web_search import ActionSearch |
47 | 48 | from openai.types.responses.response_prompt_param import ResponsePromptParam |
48 | | -from pydantic import ConfigDict, Field |
| 49 | +from pydantic import ConfigDict, Field, TypeAdapter |
49 | 50 |
|
50 | 51 | from temporalio import activity, workflow |
51 | 52 | from temporalio.client import Client, WorkflowFailureError, WorkflowHandle |
|
55 | 56 | TestModel, |
56 | 57 | TestModelProvider, |
57 | 58 | ) |
| 59 | +from temporalio.contrib.pydantic import pydantic_data_converter |
58 | 60 | from temporalio.exceptions import CancelledError |
59 | 61 | from temporalio.testing import WorkflowEnvironment |
60 | 62 | from tests.contrib.openai_agents.research_agents.research_manager import ( |
@@ -1757,3 +1759,21 @@ async def test_workflow_method_tools(client: Client): |
1757 | 1759 | execution_timeout=timedelta(seconds=10), |
1758 | 1760 | ) |
1759 | 1761 | await workflow_handle.result() |
| 1762 | + |
| 1763 | + |
| 1764 | +async def test_response_serialization(): |
| 1765 | + # This should not be used in another test, or this test needs to change to use another unloaded type |
| 1766 | + from openai.types.responses.response_output_item import ImageGenerationCall |
| 1767 | + |
| 1768 | + data = json.loads( |
| 1769 | + b'{"id": "msg_68757ec43348819d86709f0fcb70316301a1194a3e05b38c","type": "image_generation_call","status": "completed"}' |
| 1770 | + ) |
| 1771 | + call = TypeAdapter(ImageGenerationCall).validate_python(data) |
| 1772 | + model_response = ModelResponse( |
| 1773 | + output=[ |
| 1774 | + call, |
| 1775 | + ], |
| 1776 | + usage=Usage(), |
| 1777 | + response_id="", |
| 1778 | + ) |
| 1779 | + encoded = await pydantic_data_converter.encode([model_response]) |
0 commit comments