Cohere SDK 클라우드 플랫폼 호환성
Cohere SDK 클라우드 플랫폼 호환성 (Cohere SDK Cloud Platform Compatibility)
Cohere의 SDK를 사용할 수 있는 다양한 위치에 대해 알아볼 거예요.
Cohere 지원 환경 위에서 구축하고 그 사이를 전환하는 편의를 극대화하기 위해, 우리는 선택한 백엔드를 원활하게 지원하는 SDK를 개발했어요. 이를 통해 한 백엔드로 프로젝트 개발을 시작하면서, 필요해지면 전환할 수 있는 유연성을 유지할 수 있어요.
이 문서에 제시된 코드 스니펫은 시작하기에 충분하지만, 한 환경에서 다른 환경으로 전환하게 되면 SDK를 임포트하고 초기화하는 방식에 약간의 변경을 해야 한다는 점에 유의하세요.
출처: 문서
지원 환경 (Supported environments)
아래 표는 Cohere 모델을 배포할 수 있는 환경을 요약해요. 링크가 많이 포함되어 있는데, "sdk" 열의 링크는 Cohere의 언어별 SDK에 대한 자세한 정보가 있는 Github 페이지로 연결되고, 나머지는 모두 이 문서의 관련 섹션으로 연결돼요.
참고 (Note)
Cohere v2 API는 Bedrock과 SageMaker에서
BedrockClientV2와SagemakerClientV2를 통해, Azure에서는 커스텀base_url과 함께ClientV2를 통해, OCI에서는OciClientV2를 통해 지원돼요.
| sdk | Cohere platform | Bedrock | Sagemaker | Azure | OCI | Private Deployment |
|---|---|---|---|---|---|---|
| Typescript | ✅ docs | ✅ docs | ✅ docs | ✅ docs | 🟠 soon | ✅ docs |
| Python | ✅ docs | ✅ docs | ✅ docs | ✅ docs | ✅ docs | ✅ docs |
| Go | ✅ docs | 🟠 soon | 🟠 soon | ✅ docs | 🟠 soon | ✅ docs |
| Java | ✅ docs | 🟠 soon | 🟠 soon | ✅ docs | 🟠 soon | ✅ docs |
기능 지원 (Feature support)
가장 완전한 기능 세트는 cohere 플랫폼에서 찾을 수 있고, 각 클라우드 플랫폼은 이 기능들의 일부를 지원해요. 지원하는 매개변수에 대한 자세한 내용은 플랫폼별 문서를 참조하세요.
| Feature | Cohere Platform | Bedrock | Sagemaker | Azure | OCI | Private Deployment |
|---|---|---|---|---|---|---|
| chat_stream | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| chat | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| generate_stream | ✅ | ✅ | ✅ | ✅ | ⬜️ | ✅ |
| generate | ✅ | ✅ | ✅ | ✅ | ⬜️ | ✅ |
| embed | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| rerank | ✅ | ✅ | ✅ | ✅ | ⬜️ | ✅ |
| classify | ✅ | ⬜️ | ⬜️ | ⬜️ | ⬜️ | ✅ |
| summarize | ✅ | ⬜️ | ⬜️ | ⬜️ | ⬜️ | ✅ |
| tokenize | ✅ | ✅ (offline) | ✅ (offline) | ✅ (offline) | ✅ (offline) | ✅ (offline) |
| detokenize | ✅ | ✅ (offline) | ✅ (offline) | ✅ (offline) | ✅ (offline) | ✅ (offline) |
| check_api_key | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
스니펫 (Snippets)
Cohere 플랫폼 (Cohere Platform)
TS
const { CohereClient } = require('cohere-ai');
const cohere = new CohereClient({
token: 'Your API key',
});
(async () => {
const response = await cohere.chat({
chatHistory: [
{ role: 'USER', message: 'Who discovered gravity?' },
{
role: 'CHATBOT',
message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
},
],
message: 'What year was he born?',
// perform web search before answering the question. You can also use your own custom connector.
connectors: [{ id: 'web-search' }],
});
console.log(response);
})();
PYTHON
import cohere
co = cohere.Client("Your API key")
response = co.chat(
chat_history=[
{"role": "USER", "message": "Who discovered gravity?"},
{
"role": "CHATBOT",
"message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
],
message="What year was he born?",
# perform web search before answering the question. You can also use your own custom connector.
connectors=[{"id": "web-search"}],
)
print(response)
GO
package main
import (
"context"
"log"
cohere "github.com/cohere-ai/cohere-go/v2"
client "github.com/cohere-ai/cohere-go/v2/client"
)
func main() {
co := client.NewClient(client.WithToken("Your API key"))
resp, err := co.Chat(
context.TODO(),
&cohere.ChatRequest{
ChatHistory: []*cohere.ChatMessage{
{
Role: cohere.ChatMessageRoleUser,
Message: "Who discovered gravity?",
},
{
Role: cohere.ChatMessageRoleChatbot,
Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
}},
Message: "What year was he born?",
Connectors: []*cohere.ChatConnector{
{Id: "web-search"},
},
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", resp)
}
JAVA
import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.Message;
import com.cohere.api.types.NonStreamedChatResponse;
import java.util.List;
public class ChatPost {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("Your API key").clientName("snippet").build();
NonStreamedChatResponse response = cohere.chat(
ChatRequest.builder()
.message("What year was he born?")
.chatHistory(
List.of(Message.user(ChatMessage.builder().message("Who discovered gravity?").build()),
Message.chatbot(ChatMessage.builder().message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build()))).build());
System.out.println(response);
}
}
프라이빗 배포 (Private Deployment)
TS
const { CohereClient } = require('cohere-ai');
const cohere = new CohereClientV2({
token: '',
environment: '<YOUR_DEPLOYMENT_URL>'
});
(async () => {
const response = await cohere.chat({
chatHistory: [
{ role: 'USER', message: 'Who discovered gravity?' },
{
role: 'CHATBOT',
message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
},
],
message: 'What year was he born?',
// perform web search before answering the question. You can also use your own custom connector.
connectors: [{ id: 'web-search' }],
});
console.log(response);
})();
PYTHON
import cohere
co = cohere.ClientV2(api_key="", base_url="<YOUR_DEPLOYMENT_URL>")
response = co.chat(
chat_history=[
{"role": "USER", "message": "Who discovered gravity?"},
{
"role": "CHATBOT",
"message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
],
message="What year was he born?",
# perform web search before answering the question. You can also use your own custom connector.
connectors=[{"id": "web-search"}],
)
print(response)
GO
package main
import (
"context"
"log"
cohere "github.com/cohere-ai/cohere-go/v2"
client "github.com/cohere-ai/cohere-go/v2/client"
)
func main() {
co := client.NewClient(
client.WithBaseURL("<YOUR_DEPLOYMENT_URL>"),
)
resp, err := co.V2.Chat(
context.TODO(),
&cohere.ChatRequest{
ChatHistory: []*cohere.ChatMessage{
{
Role: cohere.ChatMessageRoleUser,
Message: "Who discovered gravity?",
},
{
Role: cohere.ChatMessageRoleChatbot,
Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
}},
Message: "What year was he born?",
Connectors: []*cohere.ChatConnector{
{Id: "web-search"},
},
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", resp)
}
JAVA
import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.Message;
import com.cohere.api.types.NonStreamedChatResponse;
import java.util.List;
public class ChatPost {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().token("Your API key").clientName("snippet").build();
Cohere cohere = Cohere.builder().environment(Environment.custom("<YOUR_DEPLOYMENT_URL>")).clientName("snippet").build();
NonStreamedChatResponse response = cohere.v2.chat(
ChatRequest.builder()
.message("What year was he born?")
.chatHistory(
List.of(Message.user(ChatMessage.builder().message("Who discovered gravity?").build()),
Message.chatbot(ChatMessage.builder().message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build()))).build());
System.out.println(response);
}
}
Bedrock
TS
const { BedrockClient } = require('cohere-ai');
const cohere = new BedrockClient({
awsRegion: "us-east-1",
awsAccessKey: "...",
awsSecretKey: "...",
awsSessionToken: "...",
});
(async () => {
const response = await cohere.chat({
model: "cohere.command-r-plus-v1:0",
chatHistory: [
{ role: 'USER', message: 'Who discovered gravity?' },
{
role: 'CHATBOT',
message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
},
],
message: 'What year was he born?',
});
console.log(response);
})();
PYTHON
import cohere
co = cohere.BedrockClient(
aws_region="us-east-1",
aws_access_key="...",
aws_secret_key="...",
aws_session_token="...",
)
response = co.chat(
model="cohere.command-r-plus-v1:0",
chat_history=[
{"role": "USER", "message": "Who discovered gravity?"},
{
"role": "CHATBOT",
"message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
],
message="What year was he born?",
)
print(response)
GO
package main
import (
"context"
"log"
cohere "github.com/cohere-ai/cohere-go/v2"
client "github.com/cohere-ai/cohere-go/v2/client"
"github.com/cohere-ai/cohere-go/v2/core"
)
func main() {
co := client.NewBedrockClient([]core.RequestOption{}, []client.AwsRequestOption{
client.WithAwsRegion("us-east-1"),
client.WithAwsAccessKey(""),
client.WithAwsSecretKey(""),
client.WithAwsSessionToken(""),
})
resp, err := co.Chat(
context.TODO(),
&cohere.ChatRequest{
ChatHistory: []*cohere.ChatMessage{
{
Role: cohere.ChatMessageRoleUser,
Message: "Who discovered gravity?",
},
{
Role: cohere.ChatMessageRoleChatbot,
Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
}},
Message: "What year was he born?",
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", resp)
}
JAVA
//Coming Soon
Sagemaker
TS
const { SagemakerClient } = require('cohere-ai');
const cohere = new SagemakerClient({
awsRegion: "us-east-1",
awsAccessKey: "...",
awsSecretKey: "...",
awsSessionToken: "...",
});
(async () => {
const response = await cohere.chat({
model: "my-endpoint-name",
chatHistory: [
{ role: 'USER', message: 'Who discovered gravity?' },
{
role: 'CHATBOT',
message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
},
],
message: 'What year was he born?',
});
console.log(response);
})();
PYTHON
import cohere
co = cohere.SagemakerClient(
aws_region="us-east-1",
aws_access_key="...",
aws_secret_key="...",
aws_session_token="...",
)
response = co.chat(
model="my-endpoint-name",
chat_history=[
{"role": "USER", "message": "Who discovered gravity?"},
{
"role": "CHATBOT",
"message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
],
message="What year was he born?",
)
print(response)
GO
package main
import (
"context"
"log"
cohere "github.com/cohere-ai/cohere-go/v2"
client "github.com/cohere-ai/cohere-go/v2/client"
"github.com/cohere-ai/cohere-go/v2/core"
)
func main() {
co := client.NewSagemakerClient([]core.RequestOption{}, []client.AwsRequestOption{
client.WithAwsRegion("us-east-1"),
client.WithAwsAccessKey(""),
client.WithAwsSecretKey(""),
client.WithAwsSessionToken(""),
})
resp, err := co.Chat(
context.TODO(),
&cohere.ChatRequest{
Model: cohere.String("my-endpoint-name"),
ChatHistory: []*cohere.ChatMessage{
{
Role: cohere.ChatMessageRoleUser,
Message: "Who discovered gravity?",
},
{
Role: cohere.ChatMessageRoleChatbot,
Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
}},
Message: "What year was he born?",
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", resp)
}
JAVA
//Coming Soon
Azure
TS
const { CohereClient } = require('cohere-ai');
const cohere = new CohereClient({
token: "<azure token>",
environment: "https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1",
});
(async () => {
const response = await cohere.chat({
chatHistory: [
{ role: 'USER', message: 'Who discovered gravity?' },
{
role: 'CHATBOT',
message: 'The man who is widely credited with discovering gravity is Sir Isaac Newton',
},
],
message: 'What year was he born?',
});
console.log(response);
})();
PYTHON
import cohere
co = cohere.Client(
api_key="<azure token>",
base_url="https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1",
)
response = co.chat(
chat_history=[
{"role": "USER", "message": "Who discovered gravity?"},
{
"role": "CHATBOT",
"message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
],
message="What year was he born?",
)
print(response)
GO
package main
import (
"context"
"log"
cohere "github.com/cohere-ai/cohere-go/v2"
client "github.com/cohere-ai/cohere-go/v2/client"
)
func main() {
client := client.NewClient(
client.WithToken("<azure token>"),
client.WithBaseURL("https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1"),
)
resp, err := co.Chat(
context.TODO(),
&cohere.ChatRequest{
ChatHistory: []*cohere.ChatMessage{
{
Role: cohere.ChatMessageRoleUser,
Message: "Who discovered gravity?",
},
{
Role: cohere.ChatMessageRoleChatbot,
Message: "The man who is widely credited with discovering gravity is Sir Isaac Newton",
}},
Message: "What year was he born?",
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("%+v", resp)
}
JAVA
import com.cohere.api.Cohere;
import com.cohere.api.requests.ChatRequest;
import com.cohere.api.types.ChatMessage;
import com.cohere.api.types.Message;
import com.cohere.api.types.NonStreamedChatResponse;
import java.util.List;
public class ChatPost {
public static void main(String[] args) {
Cohere cohere = Cohere.builder().environment(Environment.custom("https://Cohere-command-r-plus-phulf-serverless.eastus2.inference.ai.azure.com/v1")).token("<azure token>").clientName("snippet").build();
NonStreamedChatResponse response = cohere.chat(
ChatRequest.builder()
.message("What year was he born?")
.chatHistory(
List.of(Message.user(ChatMessage.builder().message("Who discovered gravity?").build()),
Message.chatbot(ChatMessage.builder().message("The man who is widely credited with discovering gravity is Sir Isaac Newton").build()))).build());
System.out.println(response);
}
}
OCI
PYTHON
import cohere
co = cohere.OciClientV2(
oci_region="us-chicago-1",
oci_compartment_id="ocid1.compartment.oc1...",
)
response = co.chat(
model="command-a-plus-05-2026",
messages=[
{"role": "user", "content": "Who discovered gravity?"},
],
)
print(response)