File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1
1
from dataclasses import dataclass
2
+ import json
2
3
import os
3
4
import azure .functions as func
4
5
from openai import AsyncAzureOpenAI
8
9
from model_activity import create_invoke_model_activity
9
10
from azure .identity import DefaultAzureCredential
10
11
from tools import activity_as_tool
12
+ from pydantic import BaseModel
11
13
12
14
13
15
#region Regular Azure OpenAI setup
@@ -132,19 +134,25 @@ def weather_expert(context):
132
134
result = Runner .run_sync (agent , "What is the weather in Tokio?" )
133
135
return result .final_output
134
136
135
- @dataclass
136
- class Weather :
137
+ class Weather (BaseModel ):
137
138
city : str
138
139
temperature_range : str
139
140
conditions : str
140
141
142
+ def to_json (self ) -> str :
143
+ return self .model_dump_json ()
144
+
145
+ @staticmethod
146
+ def from_json (data : str ) -> "Weather" :
147
+ return Weather (** json .loads (data ))
148
+
141
149
@app .activity_trigger (input_name = "city" )
142
- async def get_weather (city : str ) -> str :
150
+ async def get_weather (city : str ) -> Weather :
143
151
"""
144
152
Get the weather for a given city.
145
153
"""
146
154
weather = Weather (city = city , temperature_range = "14-20C" , conditions = "Sunny with wind." )
147
- return f"Weather in { weather . city } : { weather . temperature_range } , { weather . conditions } "
155
+ return weather
148
156
149
157
150
158
@function_tool
Original file line number Diff line number Diff line change @@ -7,3 +7,4 @@ azure-functions-durable
7
7
azure-identity
8
8
openai
9
9
openai-agents
10
+ pydantic
You can’t perform that action at this time.
0 commit comments