视觉
Portkey 的 AI 网关支持像 OpenAI 的 GPT-4V、Google 的 Gemini 等视觉模型。
Vision Chat Completion Usage
Portkey 支持 OpenAI 签名以将图像作为 API 请求的一部分定义消息。图像可以通过两种主要方式提供给模型:通过传递图像链接或直接在请求中传递 base64 编码的图像。
这是使用 OpenAI 的 gpt-4-vision-preview 模型的示例
import Portkey from 'portkey-ai';
// Initialize the Portkey client
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key
virtualKey: "VIRTUAL_KEY" // Add your provider's virtual key
});
// Generate a chat completion with streaming
async function getChatCompletionFunctions(){
const response = await portkey.chat.completions.create({
model: "gpt-4-vision-preview",
messages: [
{
role: "user",
content: [
{ type: "text", text: "What’s in this image?" },
{
type: "image_url",
image_url:
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
],
},
],
});
console.log(response)
}
await getChatCompletionFunctions();请求完成后,将在日志 UI 中记录请求,可以查看任何图像输入或输出。Portkey 将自动加载图像 URL 或 base64 图像,为视觉模型提供极佳的调试体验。

为视觉模型创建提示模板
Portkey 的提示库支持使用图像输入创建模板。如果在所有提示调用中都使用相同的图像,可以将其作为模板图像 URL 的一部分进行保存。或者,如果图像将作为变量通过 API 发送,则在图像链接中添加一个变量。

支持的提供者和模型
以下提供者支持图像生成,更多提供者即将添加。请提交请求或PR以将模型或提供者添加到AI网关。
提供者
模型
功能
anthropic.claude-3-sonnet
anthropic.claude-3-haiku
anthropic.claude-3-5-sonnet-20240620-v1:0
创建聊天完成
Last updated