Skip to main content

llama-index tools text_to_image integration

Project description

Text to Image Tool

This tool allows Agents to use the OpenAI Image endpoint to generate and create variations of images.

Usage

This tool has more extensive example usage documented in a Jupyter notebook here

Another example showcases retrieval augmentation over a knowledge corpus with text-to-image. Notebook.

from llama_index.tools.text_to_image import TextToImageToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

openai.api_key = "sk-your-key"
tool_spec = TextToImageToolSpec()
# OR
tool_spec = TextToImageToolSpec(api_key="sk-your-key")

agent = FunctionAgent(
    tools=tool_spec.to_tool_list(),
    llm=OpenAI(model="gpt-4.1"),
)

# Context to store chat history
from llama_index.core.workflow import Context

ctx = Context(agent)


print(
    await agent.run(
        "show 2 images of a beautiful beach with a palm tree at sunset",
        ctx=ctx,
    )
)
print(await agent.run("make the second image higher quality", ctx=ctx))

generate_images: Generate images from a prompt, specifying the number of images and resolution show_images: Show the images using matplot, useful for Jupyter notebooks generate_image_variation: Generate a variation of an image given a URL.

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

llama_index_tools_text_to_image-0.4.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_tools_text_to_image-0.4.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_tools_text_to_image-0.4.1.tar.gz
Algorithm Hash digest
SHA256 5996f4797e2c876e09001c91233c6d5d61feb70b6e3bd1249142d636445144ed
MD5 64c6d664b23e1da1486d15ad2ec10dd4
BLAKE2b-256 33b82a7e9d9b655a6b7c467b5c44091002a9b0132d9cd45b403513ef2665dc8c

See more details on using hashes here.

File details

Details for the file llama_index_tools_text_to_image-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_tools_text_to_image-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24a4df2874f79c3c87310276ff72bac5db1265a041e8b2565dd9756ebb72d0c4
MD5 55d12c0c11326de9153eeb82da17ab77
BLAKE2b-256 200f10bf9d720f4935a33b40d962f49f28ab91f28dd42039139833bd149010bf

See more details on using hashes here.

Supported by

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