Skip to content

Commit 0765007

Browse files
committed
Fix model response serialization
1 parent b460110 commit 0765007

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

samples-v2/openai_agents/activity_call_tracker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from azure.durable_functions.models.DurableOrchestrationContext import DurableOrchestrationContext
23
from yield_exception import YieldException
34

@@ -20,4 +21,7 @@ def call_activity(self, activity_name, input: str):
2021
else:
2122
# yield later
2223
self.tasks_to_yield.append(task)
23-
return completed_tasks[self.activities_called - 1].Result
24+
25+
result_json = completed_tasks[self.activities_called - 1].Result
26+
result = json.loads(result_json)
27+
return result

samples-v2/openai_agents/durable_model_stub.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ def make_tool_info(tool: Tool) -> ToolInput:
131131

132132
activity_input_json = activity_input.to_json()
133133

134-
result = self.activity_call_tracker.call_activity("invoke_model_activity", activity_input_json)
135-
return result
134+
response = self.activity_call_tracker.call_activity("invoke_model_activity", activity_input_json)
135+
json_response = json.loads(response)
136+
model_response = ModelResponse(**json_response)
137+
return model_response
136138

137139
def stream_response(
138140
self,

samples-v2/openai_agents/function_app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,5 @@ async def invoke_model_activity(input: str):
7070
model_activity = ModelActivity()
7171
result = await model_activity.invoke_model_activity(activity_input)
7272

73-
result_json = to_json(result).decode('utf-8')
74-
return result_json
75-
73+
json_obj = ModelResponse.__pydantic_serializer__.to_json(result)
74+
return json_obj.decode()

0 commit comments

Comments
 (0)