Skip to main content

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.2.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_tools_openai_image_generation-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e551c06934850745cdcaf163c9c211744d063e92160d3ee9e2ba9bb11ff80a05
MD5 35578b6025f790a2ea018800fbab14cc
BLAKE2b-256 829383510e886d799e2605b7f167340895f1ce5505e2294152a0982b29e0715d

See more details on using hashes here.

File details

Details for the file llama_index_tools_openai_image_generation-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_tools_openai_image_generation-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 580a52074a7e0d888dd72b1e25416e3d87c7bb9735089e8878e0b08de90b49c6
MD5 d86442d4d6d154a627f0420be88ed510
BLAKE2b-256 c6d9efe333f2ad0d6b0e5f4e80fef3fed8659992b6f3943cff19b36f07ea3cb5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page