与 Anyscale 和 Together 强制执行 JSON Schema
使用 Anyscale 和 Together AI 新引入的 JSON 模式,让 LLM 遵循您的 JSON 架构
import Portkey from 'portkey-ai';
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY",
virtualKey: "ANYSCALE_VIRTUAL_KEY"// OR "TOGETHER_VIRTUAL_KEY"
})
asyn function main(){
const json_response = await portkey.chat.completions.create({
messages: [{role: "user",content: `Give me a recipe for making Ramen, in JSON format`}],
model: "mistralai/Mistral-7B-Instruct-v0.1",
response_format: {
type: "json_object",
schema: {
type: "object",
properties: {
title: { type: "string" },
description: { type: "string" },
steps: { type: "array" }
}
}
}
});
}
console.log(json_response.choices[0].message.content);
main()输出 JSON:
支持的模型
模型/提供者
确保 JSON
确保 Schema
创建嵌套 JSON 对象架构
Last updated