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 11from dataclasses import dataclass
2+ import json
23import os
34import azure .functions as func
45from openai import AsyncAzureOpenAI
89from model_activity import create_invoke_model_activity
910from azure .identity import DefaultAzureCredential
1011from tools import activity_as_tool
12+ from pydantic import BaseModel
1113
1214
1315#region Regular Azure OpenAI setup
@@ -132,19 +134,25 @@ def weather_expert(context):
132134 result = Runner .run_sync (agent , "What is the weather in Tokio?" )
133135 return result .final_output
134136
135- @dataclass
136- class Weather :
137+ class Weather (BaseModel ):
137138 city : str
138139 temperature_range : str
139140 conditions : str
140141
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+
141149@app .activity_trigger (input_name = "city" )
142- async def get_weather (city : str ) -> str :
150+ async def get_weather (city : str ) -> Weather :
143151 """
144152 Get the weather for a given city.
145153 """
146154 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
148156
149157
150158@function_tool
Original file line number Diff line number Diff line change @@ -7,3 +7,4 @@ azure-functions-durable
77azure-identity
88openai
99openai-agents
10+ pydantic
You can’t perform that action at this time.
0 commit comments