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
image_generation_tool = OpenAIImageGenerationToolSpec(
api_key=os.environ["OPENAI_API_KEY"]
)
agent = OpenAIAgent.from_tools(
[*image_generation_tool.to_tool_list()],
verbose=True,
)
response = agent.query(
"A pink and blue llama in a black background with the output"
)
print(response)
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
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
File details
Details for the file llama_index_tools_openai_image_generation-0.4.0.tar.gz
.
File metadata
- Download URL: llama_index_tools_openai_image_generation-0.4.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffb80420e26d55e936eded4ca1bbbc4174216a8fbfad609759833dd6fc17e869 |
|
MD5 | cbd693ff6fdeb2cabf6883e976e391bc |
|
BLAKE2b-256 | 3b470a40292f7f9a98bcf959018b9ca4ef6df1aa52c9cb9812dfbd3f7a11c105 |
File details
Details for the file llama_index_tools_openai_image_generation-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_tools_openai_image_generation-0.4.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdc14c29c232229673f3898d64ecd23bc7c9e9882858fd2e854f7bf3f0ab2fec |
|
MD5 | a97179ce6d8b71cdbc20fc84acce49e9 |
|
BLAKE2b-256 | 48a6de9611742d91ab358093e06d6b14d24e580212bee2063fdbccdd9b969219 |