Cohere
Portkey 提供了一个强大且安全的网关,以便将各种大型语言模型(LLMs)集成到您的应用程序中,包括 Cohere 的生成、嵌入和其他端点。
使用 Portkey,您可以利用快速的 AI 网关访问、可观察性、提示管理等功能,同时通过 虚拟密钥 系统确保安全管理您的 LLM API 密钥。
Portkey SDK 与 Cohere 的集成
Portkey 提供了一致的 API 来与 Cohere 的模型进行交互。要将 Cohere 与 Portkey 集成:
1. 安装 Portkey SDK
将 Portkey SDK 添加到您的应用程序中,以通过 Portkey 的网关与 Cohere 的模型进行交互。
npm install --save portkey-aipip install portkey-ai2. 使用虚拟密钥初始化 Portkey
要使用 Cohere 和 Portkey,请在此获取您的 API 密钥,然后将其添加到 Portkey 以创建虚拟密钥。
import Portkey from 'portkey-ai'
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
virtualKey: "VIRTUAL_KEY" // Your Cohere Virtual Key
})from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VIRTUAL_KEY" # Replace with your virtual key for Cohere
)3. 使用 Cohere 调用聊天完成
使用 Portkey 实例向 Cohere 的模型发送请求。如果需要,可以在 API 调用中直接覆盖虚拟密钥。
管理 Cohere 提示
您可以在 提示库 中管理所有对 Cohere 的提示。所有当前的 Cohere 模型均受支持,您可以轻松开始测试不同的提示。
一旦您准备好提示,可以使用 portkey.prompts.completions.create 接口在您的应用程序中使用该提示。
其他 Cohere 端点
嵌入
嵌入端点在 Portkey 中原生支持,如下所示:
重新排序
您可以使用 cohere 的 portkey.post 方法进行重新排序,使用 Cohere 的重新排序 API 所期望的请求体。
下一步
SDK 支持的完整功能列表可以在以下链接中找到。
SDK您可以在相关部分找到更多信息:
Last updated