1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import asyncio from agents import Agent, Runner, function_tool
MODEL = "gpt-4o-mini"
@function_tool() def query_weather(city: str, date: str): """ 查询城市的天气信息 :param city: 城市 :param date: 日期 :return: """ print(f"查询[{date}] [{city}]的天气信息 ...")
return { "code": 0, "data": { "city": city, "data": date, "weather": "sunny", "temperature": "18°C", "humidity": "80%", } }
@function_tool() def query_stock(stock_code: str, date: str): """ 查询股票信息 :param stock_code: 股票代码 :param date: 日期 :return: """ print(f"查询[{date}] [{stock_code}]的涨跌信息 ...")
return { "code": 0, "data": { "stock_code": stock_code, "data": date, "max": "10.05", "min": "8,02" } }
smarter = Agent( name="smart_man", instructions="你是一个无所不知无所不晓的人,上知天文下知地理.", model=MODEL, tools=[query_weather, query_stock] )
async def main(): result = await Runner.run(smarter, input="你好,请帮我查询武汉2025年3月20日的天气信息") print(result.final_output)
if __name__ == "__main__": asyncio.run(main())
|