|
| 1 | +from dataclasses import dataclass |
1 | 2 | import os
|
2 | 3 | import azure.functions as func
|
3 | 4 | from openai import AsyncAzureOpenAI
|
4 | 5 | from agents import Agent, Runner, set_default_openai_client
|
5 | 6 | from durable_decorators import durable_openai_agent_orchestrator
|
6 | 7 | from model_activity import create_invoke_model_activity
|
7 | 8 | from azure.identity import DefaultAzureCredential
|
| 9 | +from tools import activity_as_tool |
8 | 10 |
|
9 | 11 |
|
10 | 12 | #region Regular Azure OpenAI setup
|
@@ -115,6 +117,34 @@ async def hello(name: str):
|
115 | 117 | return f"Hello {name}!"
|
116 | 118 |
|
117 | 119 |
|
| 120 | +@app.orchestration_trigger(context_name="context") |
| 121 | +@durable_openai_agent_orchestrator |
| 122 | +def weather_expert(context): |
| 123 | + agent = Agent( |
| 124 | + name="Hello world", |
| 125 | + instructions="You are a helpful agent.", |
| 126 | + tools=[ |
| 127 | + activity_as_tool(get_weather) |
| 128 | + ], |
| 129 | + ) |
| 130 | + |
| 131 | + result = Runner.run_sync(agent, "What is the weather in Tokio?") |
| 132 | + return result.final_output |
| 133 | + |
| 134 | +@dataclass |
| 135 | +class Weather: |
| 136 | + city: str |
| 137 | + temperature_range: str |
| 138 | + conditions: str |
| 139 | + |
| 140 | +@app.activity_trigger(input_name="city") |
| 141 | +async def get_weather(city: str) -> Weather: |
| 142 | + """ |
| 143 | + Get the weather for a given city. |
| 144 | + """ |
| 145 | + return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.") |
| 146 | + |
| 147 | + |
118 | 148 | #region Implementation details
|
119 | 149 |
|
120 | 150 | create_invoke_model_activity(app) # TODO: Can we hide this line?
|
|
0 commit comments