Cohere ↗ 构建旨在解决实际业务挑战的 AI 模型。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere向 Cohere ↗ 发送请求时,将当前使用的 URL 中的 https://api.cohere.ai/v1 替换为 https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere。
向 Cohere 发送请求时,请确保具备以下条件:
- 你的 AI Gateway Account ID。
- 你的 AI Gateway gateway 名称。
- 有效的 Cohere API 令牌。
- 要使用的 Cohere 模型名称。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere/v1/chat \
--header 'Authorization: Token {cohere_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"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?",
"connectors": [{"id": "web-search"}]
}'如果使用 cohere-python-sdk ↗,可以这样设置端点:
import cohere
import os
api_key = os.getenv('API_KEY')
account_id = '{account_id}'
gateway_id = '{gateway_id}'
base_url = f"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere/v1"
co = cohere.Client(
api_key=api_key,
base_url=base_url,
)
message = "hello world!"
model = "command-r-plus"
chat = co.chat(
message=message,
model=model
)
print(chat)你也可以通过 REST API 使用 OpenAI API schema 访问 Cohere 模型。将请求发送至:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions指定:
{
"model": "cohere/{model}"
}