Eden AI는 최고의 AI 제공업체들을 통합하여 AI 환경을 혁신하고 있으며, 사용자들이 무한한 가능성을 열고 인공지능의 진정한 잠재력을 활용할 수 있도록 지원합니다. 올인원 종합 플랫폼을 통해 사용자는 AI 기능을 프로덕션에 매우 빠르게 배포할 수 있으며, 단일 API를 통해 AI 기능의 전체 범위에 손쉽게 액세스할 수 있습니다. (웹사이트: edenai.co/) 이 예제는 LangChain을 사용하여 Eden AI 모델과 상호작용하는 방법을 다룹니다
EDENAI의 API에 액세스하려면 API key가 필요합니다. 계정을 생성하여 app.edenai.run/user/register에서 API key를 얻을 수 있으며, app.edenai.run/admin/account/settings로 이동하면 됩니다 key를 얻은 후에는 다음을 실행하여 환경 변수로 설정해야 합니다:
export EDENAI_API_KEY="..."
환경 변수를 설정하지 않으려면 EdenAI LLM class를 초기화할 때 edenai_api_key라는 named parameter를 통해 key를 직접 전달할 수 있습니다:
from langchain_community.llms import EdenAI
llm = EdenAI(edenai_api_key="...", provider="openai", temperature=0.2, max_tokens=250)

model 호출하기

EdenAI API는 다양한 provider들을 통합하며, 각 provider는 여러 model을 제공합니다. 특정 model에 액세스하려면 인스턴스화 중에 ‘model’을 추가하기만 하면 됩니다. 예를 들어, GPT3.5와 같은 OpenAI에서 제공하는 model들을 살펴보겠습니다

text generation

from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate

llm = EdenAI(
    feature="text",
    provider="openai",
    model="gpt-3.5-turbo-instruct",
    temperature=0.2,
    max_tokens=250,
)

prompt = """
User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?
Assistant:
"""

llm(prompt)

image generation

import base64
from io import BytesIO

from PIL import Image


def print_base64_image(base64_string):
    # Decode the base64 string into binary data
    decoded_data = base64.b64decode(base64_string)

    # Create an in-memory stream to read the binary data
    image_stream = BytesIO(decoded_data)

    # Open the image using PIL
    image = Image.open(image_stream)

    # Display the image
    image.show()
text2image = EdenAI(feature="image", provider="openai", resolution="512x512")
image_output = text2image("A cat riding a motorcycle by Picasso")
print_base64_image(image_output)

callback을 사용한 text generation

from langchain_community.llms import EdenAI
from langchain_core.callbacks import StreamingStdOutCallbackHandler

llm = EdenAI(
    callbacks=[StreamingStdOutCallbackHandler()],
    feature="text",
    provider="openai",
    temperature=0.2,
    max_tokens=250,
)
prompt = """
User: Answer the following yes/no question by reasoning step by step. Can a dog drive a car?
Assistant:
"""
print(llm.invoke(prompt))

Chaining Calls

from langchain.chains import LLMChain, SimpleSequentialChain
from langchain_core.prompts import PromptTemplate
llm = EdenAI(feature="text", provider="openai", temperature=0.2, max_tokens=250)
text2image = EdenAI(feature="image", provider="openai", resolution="512x512")
prompt = PromptTemplate(
    input_variables=["product"],
    template="What is a good name for a company that makes {product}?",
)

chain = LLMChain(llm=llm, prompt=prompt)
second_prompt = PromptTemplate(
    input_variables=["company_name"],
    template="Write a description of a logo for this company: {company_name}, the logo should not contain text at all ",
)
chain_two = LLMChain(llm=llm, prompt=second_prompt)
third_prompt = PromptTemplate(
    input_variables=["company_logo_description"],
    template="{company_logo_description}",
)
chain_three = LLMChain(llm=text2image, prompt=third_prompt)
# Run the chain specifying only the input variable for the first chain.
overall_chain = SimpleSequentialChain(
    chains=[chain, chain_two, chain_three], verbose=True
)
output = overall_chain.run("hats")
# print the image
print_base64_image(output)

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