llama-index tools openai_image_generation integration
Project description
OpenAI Image Generation Tool
This tool allows Agents to generate images using OpenAI's DALL-E model. To see more and get started, visit https://openai.com/blog/dall-e/
Usage
This tool has a more extensive example usage documented in a Jupyter notebook here.
Usage with Agent
from llama_index.tools.openai import OpenAIImageGenerationToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
image_generation_tool = OpenAIImageGenerationToolSpec(
api_key=os.environ["OPENAI_API_KEY"]
)
agent = FunctionAgent(
tools=[*image_generation_tool.to_tool_list()],
llm=OpenAI(model="gpt-4.1"),
)
print(
await agent.run(
"A pink and blue llama in a black background with the output"
)
)
Usage directly
from llama_index.tools.openai import OpenAIImageGenerationToolSpec
image_generation_tool = OpenAIImageGenerationToolSpec(
api_key=os.environ["OPENAI_API_KEY"]
)
image_data = image_generation_tool.image_generation(
text="A pink and blue llama with a black background",
response_format="b64_json",
)
image_bytes = base64.b64decode(image_data)
img = Image.open(BytesIO(image_bytes))
display(img)
image_generation: Takes an text input and generates an image
This loader is designed to be used as a way to load data as a Tool in a Agent.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_tools_openai_image_generation-0.6.0.tar.gz.
File metadata
- Download URL: llama_index_tools_openai_image_generation-0.6.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b64e3a46727f784f42ec90f11c5045f492964639d352a301488276ed06d6c25f
|
|
| MD5 |
509914381dae432981a1ac1cff4e64ad
|
|
| BLAKE2b-256 |
c0f6114cd85edd30324d6f0a9d51b93cc68bd37b9ff910a39152b357509f0dc1
|
File details
Details for the file llama_index_tools_openai_image_generation-0.6.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_tools_openai_image_generation-0.6.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfeece6560f362202ccb5c1598c8d13d0dee2241e451a1dc06fdba4aac365c74
|
|
| MD5 |
6b2f4d95b3ad0a47ada19beed7fd1416
|
|
| BLAKE2b-256 |
6c2091eb564b7104d0b0308396e5d63799dcfddcdf6a0219787dbf9e0f66420c
|