import Portkey from "portkey-ai";
import ora from "ora";
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "sk-openaikey***",
});
const portkey = new Portkey({
apiKey: process.env.PORTKEY_API_KEY,
virtualKey: process.env.ANYSCALE_VIRTUAL_KEY,
});
const spinner = ora("Reaching Mistral LLM via Portkey...").start();
const tools = [
{
type: "function",
function: {
name: "get_current_weather",
description: "Get the current weather in a given location",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA",
},
unit: { type: "string", enum: ["celsius", "fahrenheit"] },
},
required: ["location"],
},
},
},
];
// change "portkey" to "openai" incase you want to error with openai & vice versa
const chatCompletion = await portkey.chat.completions.create({
model: "mistralai/Mixtral-8x7B-Instruct-v0.1",
tools,
// to reproduce the error with comment the messages property
messages: [
{ role: "system", content: "You are helpful assistant." },
{ role: "user", content: "What's the weather like in San Francisco?" },
],
tool_choice: "auto",
});
console.log(chatCompletion.choices[0].message);
spinner.stop("Done");