이 문서는 DigitalOcean Gradient chat models 시작하기를 도와드립니다.

Overview

Integration details

ClassPackageDownloadsVersion
ChatGradientlangchain-gradientPyPI - DownloadsPyPI - Version

Setup

langchain-gradient는 DigitalOcean Gradient Platform을 사용합니다. DigitalOcean에 계정을 생성하고, Gradient Platform에서 DIGITALOCEAN_INFERENCE_KEY API key를 획득한 후, langchain-gradient integration package를 설치하세요.

Credentials

DigitalOcean Gradient로 이동하세요
  1. DigitalOcean Cloud Console에 가입/로그인합니다
  2. Gradient Platform으로 이동하여 Serverless Inference로 이동합니다.
  3. Create model access key를 클릭하고, 이름을 입력한 후 key를 생성합니다.
완료되면 DIGITALOCEAN_INFERENCE_KEY environment variable을 설정하세요:
import os
os.environ["DIGITALOCEAN_INFERENCE_KEY"] = "your-api-key"

Installation

LangChain Gradient integration은 langchain-gradient package에 있습니다:
pip install -qU langchain-gradient

Instantiation

from langchain_gradient import ChatGradient

llm = ChatGradient(
    model="llama3.3-70b-instruct",
    api_key=os.environ.get("DIGITALOCEAN_INFERENCE_KEY")
)

Invocation

messages = [
    (
        "system",
        "You are a creative storyteller. Continue any story prompt you receive in an engaging and imaginative way.",
    ),
    ("human", "Once upon a time, in a village at the edge of a mysterious forest, a young girl named Mira found a glowing stone..."),
]
ai_msg = llm.invoke(messages)
ai_msg
print(ai_msg.content)

Chaining

from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate(
    [
        (
            "system",
            "You are a knowledgeable assistant. Carefully read the provided context and answer the user's question. If the answer is present in the context, cite the relevant sentence. If not, reply with \"Not found in context.\"",
        ),
        ("human", "Context: {context}\nQuestion: {question}"),
    ]
)

chain = prompt | llm
chain.invoke(
    {
        "context": (
            "The Eiffel Tower is located in Paris and was completed in 1889. "
            "It was designed by Gustave Eiffel's engineering company. "
            "The tower is one of the most recognizable structures in the world. "
            "The Statue of Liberty was a gift from France to the United States."
        ),
        "question": "Who designed the Eiffel Tower and when was it completed?"
    }
)

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