OpenAI Dall-E는 OpenAI에서 개발한 text-to-image 모델로, 딥러닝 방법론을 사용하여 “prompts”라고 불리는 자연어 설명으로부터 디지털 이미지를 생성합니다.
이 노트북은 OpenAI LLM을 사용하여 합성된 prompt로부터 이미지를 생성하는 방법을 보여줍니다. 이미지는 LLM과 동일한 OpenAI API key를 사용하는 Dall-E를 통해 생성됩니다.
# Needed if you would like to display images in the notebook
pip install -qU  opencv-python scikit-image langchain-community
import os

from langchain_openai import OpenAI

os.environ["OPENAI_API_KEY"] = "insertapikey"

chain으로 실행하기

from langchain.chains import LLMChain
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI

llm = OpenAI(temperature=0.9)
prompt = PromptTemplate(
    input_variables=["image_desc"],
    template="Generate a detailed prompt to generate an image based on the following description: {image_desc}",
)
chain = LLMChain(llm=llm, prompt=prompt)
image_url = DallEAPIWrapper().run(chain.run("halloween night at a haunted museum"))
image_url
# You can click on the link above to display the image
# Or you can try the options below to display the image inline in this notebook

try:
    import google.colab

    IN_COLAB = True
except ImportError:
    IN_COLAB = False

if IN_COLAB:
    from google.colab.patches import cv2_imshow  # for image display
    from skimage import io

    image = io.imread(image_url)
    cv2_imshow(image)
else:
    import cv2
    from skimage import io

    image = io.imread(image_url)
    cv2.imshow("image", image)
    cv2.waitKey(0)  # wait for a keyboard input
    cv2.destroyAllWindows()

agent와 함께 tool로 실행하기

from langchain_community.tools.openai_dalle_image_generation import (
    OpenAIDALLEImageGenerationTool,
)
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
from langchain_openai import ChatOpenAI
from langchain.agents import create_agent


llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
api_wrapper = DallEAPIWrapper()
dalle_tool = OpenAIDALLEImageGenerationTool(api_wrapper=api_wrapper)

tools = [dalle_tool]

agent = create_agent(llm, tools, debug=True)

# User prompt
prompt = "Create an image of a halloween night at a haunted museum"

messages = [
    # "role": "user" Indicates message is coming from user
    # "content": prompt is where the user's input is placed
    {"role": "user", "content": prompt}
]

# Sending the message to be processed and adjusted by ChatGPT, after which is sent through DALL-E
response = agent.invoke({"messages": messages})

print(response)

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I