Azure AI Foundry에서의 텍스트 생성

Azure AI Foundry에서의 텍스트 생성

이 페이지는 Cohere SDK를 사용해 Azure AI Foundry에서 Cohere의 텍스트 생성(Command) 모델을 사용하는 방법을 설명해요. Azure Messages API를 활용한 챗봇 구축 예시를 살펴볼게요.

출처: 문서

본문

이 페이지는 Cohere SDK를 사용해 Azure AI Foundry에서 Cohere의 텍스트 생성(Command) 모델을 사용하는 방법을 설명해요.

Azure Messages API

Cohere 네이티브 API를 사용하는 것처럼 코드를 작성해요. 나머지는 Azure가 처리해줘요. Azure AI Foundry 챗봇을 만들려면 아래 코드를 사용할 수 있어요.

Azure Messages API (V2)

Cohere 네이티브 V2 API를 사용하는 것처럼 코드를 작성해요. 다음 코드는 Azure의 V2 API를 사용해 Azure AI Foundry에서 챗봇을 만드는 방법을 보여줘요.

PYTHON (Python) Cohere V2 SDK

import cohere

co = cohere.ClientV2(
    api_key="key",
    base_url="https://your-endpoint.inference.ai.azure.com/v1/chat",
}

response = co.chat(
    model="command-a-03-2025",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who owns the phone company Bluestone?"},
    ],
)

print(response.message.content[0].text)

Python 패키지 (Python Packages)

다음 패키지가 설치되어 있는지 확인하세요:

  • azure-ai-inference
  • cohere

Azure AI Foundry 예시 (Azure AI Foundry Example)

Azure Messages API를 사용해 채팅 완료 요청을 만드는 예시는 다음과 같아요:

PYTHON

import os

import cohere

# Import the azure-ai-inference package
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential

# Set up the Azure AI Foundry client
CHAT_API_BASE = os.getenv("AZURE_OPENAI_ENDPOINT", "")
CHAT_API_KEY = os.getenv("AZURE_OPENAI_KEY", "")

chat_client = cohere.Client(
    api_key=CHAT_API_KEY,
    base_url=CHAT_API_BASE,
)

# Make the request
response = chat_client.chat(
    message="Hello! Who are you?"
)

print(response.text)

텍스트 생성에 Cohere Chat 사용하기 (Using Cohere Chat for Text Generation)

Azure 호스팅과 함께 경험을 향상시켜 보세요: Cohere SDK는 플랫폼을 완전히 지원하며, 전체 사용 사례 예시는 Cohere SDK with Azure AI Foundry에서 확인할 수 있어요:

텍스트 생성과 Cohere Rerank 사용하기 (Using Cohere Rerank with Text Generation)

텍스트 생성과 Rerank를 결합해 먼저 검색하고 나중에 생성하는 워크플로를 만들 수도 있어요.

예시 노트북은 Cohere와 Azure AI Foundry로 RAG 시스템을 구축하는 방법을 보여줘요.

다음 단계 (Next Steps)

계속 탐색해 보세요:

더 알아보기 (Learn more)