I have an assistant with an ID created from the platform.openai.com. I want to use it instead of the default gpt. How do I do that?
import { config } from "dotenv";
config();
import { OpenAI } from "openai";
import readline from "readline";
const openai = new OpenAI({ apiKey: process.env.API_KEY });
const userInterface = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let messages = [];
userInterface.prompt();
userInterface.on("line", async (input) => {
messages.push({ role: "user", content: input });
const res = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: contextMessages,
});
const assistantMessage = res.choices[0].message.content;
console.log(assistantMessage);
messages.push({ role: "assistant", content: assistantMessage });
userInterface.prompt();
});
I can fetch the assistant through the api by creating a thread and a run like below. I just dont know how to use it in the code above, so the user is chatting with my custom gpt assistant.
const emptyThread = await openai.beta.threads.create();
const run = await openai.beta.threads.runs.create(emptyThread.id, {
assistant_id: "asst_DmX0pcXXXXXXXXXXX",
});
console.log(run);