forked from thestriver/research-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (26 loc) · 896 Bytes
/
index.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
const { OpenAI } = require("openai");
const openai = new OpenAI({
apiKey: "YOUR_OPENAI_API_KEY",
dangerouslyAllowBrowser: true,
});
async function queryAIModel(question) {
try {
const completion = await openai.chat.completions.create({
model: "gpt-4",
messages: [
{ role: "system", content: "You are a helpful research assistant." },
{ role: "user", content: question }
],
});
return completion.choices[0].message.content.trim();
} catch (error) {
console.error("An error occurred while querying GPT-4:", error);
return "Sorry, an error occurred. Please try again.";
}
}
async function queryResearchAssistant() {
const query = "What is the role of Javascript in building AI Applications?";
const answer = await queryAIModel(query);
console.log(`Question: ${query}\nAnswer: ${answer}`);
}
queryResearchAssistant();