其他 API 端点的网关
您使用的 LLM 提供商可能支持与 Portkey 支持的端点不同的其他端点。该网关支持直接代理请求。
您可以通过在 https://api.portkey.ai/v1 后添加端点来调用它
https://api.portkey.ai/v1 后添加端点来调用它我们根据在头部或配置对象中传递的 provider 或 virtual_key 来识别所需的提供商和参数。
示例
让我们来看一个使用 Cohere Rerank API 的例子(这里没有直接文档说明)
Cohere 的端点是 /rerank
我们将在 UI 中为 cohere 创建一个虚拟密钥,并使用它通过 Portkey 进行调用,或者直接使用模式为 cohere。
使用虚拟密钥的示例 cURL 请求(推荐)
curl --request POST \
--url https://api.portkey.ai/v1/rerank \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-portkey-api-key: $PORTKEY_API_KEY' \
--header 'x-portkey-virtual-key: $COHERE_VIRTUAL_KEY' \
--data '
{
"return_documents": false,
"max_chunks_per_doc": 10,
"model": "rerank-english-v2.0",
"query": "What is the capital of the United States?",
"documents": [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
"Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
]
}
'使用提供者的示例 cURL 请求
SDK 使用
Portkey SDK 提供了 2 个特殊函数,以便像这样进行方法调用:
portkey.post(url, requestParams) 和 portkey.get(url[, requestParams])
使用相关的 headers 和 configParams 进行这些调用,就像所有其他请求一样。
Cohere 重排序的示例请求
这些响应对象未被Portkey转换,完全按照从LLM提供者那里接收到的内容返回。
Last updated