Back to Llama Index

Import and initialize our tool spec

llama-index-integrations/tools/llama-index-tools-text-to-image/examples/text_to_image.ipynb

0.14.21752 B
Original Source
python
import os

os.environ["OPENAI_API_KEY"] = "sk-..."

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
python
# Import and initialize our tool spec
from llama_index.tools.text_to_image.base import TextToImageToolSpec

text_to_image_spec = TextToImageToolSpec()
tools = text_to_image_spec.to_tool_list()

# Create the Agent with our tools
agent = FunctionAgent(
    tools=tools,
    llm=OpenAI(model="gpt-4.1"),
)

from llama_index.core.workflow import Context

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