-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathimage_tool_output.py
More file actions
43 lines (32 loc) · 1.13 KB
/
image_tool_output.py
File metadata and controls
43 lines (32 loc) · 1.13 KB
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
import asyncio
from agents import Agent, Runner, ToolOutputImage, ToolOutputImageDict, function_tool
return_typed_dict = True
@function_tool
def fetch_random_image() -> ToolOutputImage | ToolOutputImageDict:
"""Fetch a random image."""
print("Image tool called")
if return_typed_dict:
return {
"type": "image",
"image_url": "https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
"detail": "auto",
}
return ToolOutputImage(
image_url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg",
detail="auto",
)
async def main():
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
tools=[fetch_random_image],
)
result = await Runner.run(
agent,
input="Fetch an image using the random_image tool, then describe it",
)
print(result.final_output)
"""The image shows the iconic Golden Gate Bridge, a large suspension bridge painted in a
bright reddish-orange color..."""
if __name__ == "__main__":
asyncio.run(main())