You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You may want to store the OpenAPI specification in another file and import the content to initialize the tool. Please note the sample code is using `anonymous` as authentication type.
58
+
```python
59
+
withopen('./weather_openapi.json', 'r') as f:
60
+
openapi_spec = jsonref.loads(f.read())
61
+
62
+
# Create Auth object for the OpenApiTool (note that connection or managed identity auth setup requires additional setup in Azure)
63
+
auth = OpenApiAnonymousAuthDetails()
64
+
65
+
# Initialize agent OpenApi tool using the read in OpenAPI spec
66
+
openapi = OpenApiTool(name="get_weather", spec=openapi_spec, description="Retrieve weather information for a location", auth=auth)
67
+
```
39
68
40
69
## Step 3: Create a thread
70
+
```python
71
+
# Create agent with OpenApi tool and process assistant run
72
+
with project_client:
73
+
agent = project_client.agents.create_agent(
74
+
model="gpt-4o-mini",
75
+
name="my-assistant",
76
+
instructions="You are a helpful assistant",
77
+
tools=openapi.definitions
78
+
)
79
+
print(f"Created agent, ID: {agent.id}")
80
+
81
+
# Create thread for communication
82
+
thread = project_client.agents.create_thread()
83
+
print(f"Created thread, ID: {thread.id}")
84
+
```
41
85
42
86
## Step 4: Create a run and check the output
87
+
Create a run and observe that the model uses the OpenAPI Spec tool to provide a response to the user's question.
88
+
```python
89
+
# Create message to thread
90
+
message = project_client.agents.create_message(
91
+
thread_id=thread.id,
92
+
role="user",
93
+
content="What's the weather in Seattle?",
94
+
)
95
+
print(f"Created message, ID: {message.id}")
96
+
97
+
# Create and process agent run in thread with tools
98
+
run = project_client.agents.create_and_process_run(thread_id=thread.id, assistant_id=agent.id)
0 commit comments