-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenai.service.js
34 lines (34 loc) · 1.38 KB
/
openai.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require("fs");
const createAssistant = async (openai) => {
// Assistant file path
const assistantFilePath = "assistant.json";
// check if file exists
if (!fs.existsSync(assistantFilePath)) {
// Create a file
const file = await openai.files.create({
file: fs.createReadStream("Sample.docx"),
purpose: "assistants",
});
// Create a vector store including our file
let vectorStore = await openai.beta.vectorStores.create({
name: "Chat Demo",
file_ids: [file.id],
});
// Create assistant
const assistant = await openai.beta.assistants.create({
name: "timestone",
instructions: `You are a chatbot implemented in a website. that provides almost all the details i can share to my classmates, just like one of them and that my involve asking about time table, and asking question papers, and you have to answer, with simple and precise output, just provide simple answer`,
tools: [{ type: "file_search" }],
tool_resources: { file_search: { vector_store_ids: [vectorStore.id] } },
model: "gpt-4o-mini",
});
// Write assistant to file
fs.writeFileSync(assistantFilePath, JSON.stringify(assistant));
return assistant;
} else {
// Read assistant from file
const assistant = JSON.parse(fs.readFileSync(assistantFilePath));
return assistant;
}
};
module.exports = { createAssistant };