-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (54 loc) · 1.34 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const axios = require('axios'); // For Node.js
/**
* Create a new RirikoLLaMAClient. An example client can be created like this:
*
* const client = new RirikoLLaMAClient({
* apiUrl: "",
* token: "",
* settings: {
* "max_new_tokens": 30,
* "temperature": 1.0,
* "repetition_penalty": 1,
* "top_p": 0.2,
* "start": "",
* "break": "\nHuman:"
* }
* });
*
* @author Earnest Angel https://github.com/earnestangel
*/
class RirikoLLaMAClient {
/**
* @param params {token: string, apiUrl: string, settings: {
* "max_new_tokens": integer,
* "temperature": float,
* "repetition_penalty": integer,
* "top_p": float,
* "start": string,
* "break": string
* }}
*/
constructor(params) {
// check if the token is in params
if (typeof params.token === "undefined") {
throw new Error("Token is not set");
}
this.token = params.token;
this.apiUrl = params.apiUrl;
this.settings = params.settings;
}
async ask(prompt) {
const url = this.apiUrl; // Replace with your URL
const data = {
"prompt": prompt,
...this.settings
};
return await axios.post(url, data, {
headers: {
'Content-Type': 'application/json'
},
timeout: 5 * 60 * 1000 // 5 minutes in milliseconds
});
}
}
module.exports = {RirikoLLaMAClient};