-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot-api.js
44 lines (37 loc) · 1.09 KB
/
bot-api.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
35
36
37
38
39
40
41
42
43
44
import axios from "axios";
import dotenv from "dotenv";
// Load environment variables from .env file
dotenv.config({ path: "./.env" }); // Make sure the path is correct
export async function main(prompt) {
console.log("Prompt:", prompt);
console.log("Model:", process.env.MODEL_NAME);
try {
// Construct the request payload
const payload = {
question: prompt,
chat_history: [],
knowledge_source_id: process.env.MODEL_NAME,
};
// Set the headers
const endpoint = process.env.ENDPOINT; // Ensure endpoint is defined
if (!endpoint) {
throw new Error("Endpoint is not defined in the environment variables.");
}
const headers = {
"x-api-key": process.env.FLOCK_API_KEY, // Ensure API key is set in .env
};
// Send POST request using axios
const response = await axios.post(
`${endpoint}/chat/conversational_rag_chat`,
payload,
{
headers,
}
);
// Output the response data
console.log(response.data);
return response.data;
} catch (error) {
console.error("Error:", error);
}
}