Cohere 통합
Cohere 통합
LangChain JavaScript로 Cohere LLM과 통합하는 방법을 알아봅니다.
LangChain으로 Cohere 완성 모델(LLM)을 시작하는 데 도움을 주는 가이드예요. Cohere 기능과 구성 옵션에 대한 자세한 문서는 API reference를 참조하세요.
출처: 문서
본문
레거시(Legacy)
Cohere는 LLM용
generate엔드포인트를 더 이상 사용하지 않는다고 표시했어요. 그들의 마이그레이션 가이드를 따라ChatCohere통합을 통해 Chat API를 사용하기 시작하세요.
개요
통합 세부 정보
| 클래스(Class) | 패키지(Package) | 로컬(Local) | 직렬화(Serializable) | PY 지원 | 다운로드(Downloads) | 버전(Version) |
|---|---|---|---|---|---|---|
Cohere |
@langchain/cohere |
❌ | ✅ | ✅ |
설정
Cohere 모델에 접근하려면 Cohere 계정을 만들고 API 키를 발급받은 뒤 @langchain/cohere 통합 패키지를 설치해야 합니다.
자격 증명(Credentials)
cohere.com에 방문해 Cohere에 가입하고 API 키를 생성하세요. 완료되면 COHERE_API_KEY 환경 변수를 설정하세요:
export COHERE_API_KEY="your-api-key"
모델 호출에 대한 자동 추적을 받으려면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있습니다:
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
설치
LangChain Cohere 통합은 @langchain/cohere 패키지에 있습니다:
npm install @langchain/cohere @langchain/core
yarn add @langchain/cohere @langchain/core
pnpm add @langchain/cohere @langchain/core
인스턴스화(Instantiation)
이제 모델 객체를 인스턴스화하고 텍스트 완성을 생성할 수 있습니다:
import { Cohere } from "@langchain/cohere"
const llm = new Cohere({
model: "command",
temperature: 0,
maxTokens: undefined,
maxRetries: 2,
// other params...
})
Azure의 Cohere, AWS Bedrock의 Cohere, 독립형 Cohere 인스턴스를 위한 커스텀 클라이언트
커스텀 CohereClient를 인스턴스화해 Cohere 생성자에 전달할 수 있습니다.
참고: 커스텀 클라이언트가 제공되면 COHERE_API_KEY 환경 변수와 생성자의 apiKey 파라미터는 모두 무시됩니다.
import { Cohere } from "@langchain/cohere";
import { CohereClient } from "cohere-ai";
const client = new CohereClient({
token: "<your-api-key>",
environment: "<your-cohere-deployment-url>", //optional
// other params
});
const llmWithCustomClient = new Cohere({
client,
// other params...
});
호출(Invocation)
const inputText = "Cohere is an AI company that "
const completion = await llm.invoke(inputText)
completion
Cohere is a company that provides natural language processing models that help companies improve human-machine interactions. Cohere was founded in 2019 by Aidan Gomez, Ivan Zhang, and Nick Frosst.
API reference
모든 Cohere 기능과 구성에 대한 자세한 문서는 API reference를 참조하세요.
더 알아보기 (Learn more)
- 이 문서를 MCP로 연결하면 Claude, VSCode 등에서 실시간 답변을 받을 수 있어요.
- GitHub에서 이 페이지 편집하기 또는 이슈 제출하기.