-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchatbot.js
30 lines (26 loc) · 874 Bytes
/
chatbot.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 base_url = "http://127.0.0.1:1234/v1";
const api_key = "not-needed"; // Not needed for the local mock server
const postCompletion = async (messages) => {
try {
const response = await fetch(`${base_url}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${api_key}`
},
body: JSON.stringify({
model: "local-model", // This field is currently unused
messages: messages,
temperature: 0.7,
stream: false
})
});
if (!response.ok) throw new Error('Failed to fetch');
const completion = await response.json();
const answer = completion.choices[0].message.content
return answer;
} catch (error) {
console.error('ErrorGS:', error);
}
};
module.exports = { postCompletion };