-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpt-3.5-turbo.js
31 lines (29 loc) · 1.04 KB
/
gpt-3.5-turbo.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
const SECRET_KEY = "API_key_here";
const MAX_TURBO_TOKENS = 500;
function TURBO(prompt, model="gpt-3.5-turbo", temperature=0.5) {
let apiKey = SECRET_KEY;
let endpoint = "https://api.openai.com/v1/chat/completions";
let payload = {
messages:[
{role: 'system', content: 'This is where you describe what gpt does and how it answers.'},
{role: 'user', content: 'This is an example question'},
{role: 'assistant', content: "This is an example answer"},
{role: 'user', content: `${prompt}`},
],
model: model,
temperature: temperature,
max_tokens: MAX_TURBO_TOKENS,
};
let options = {
method: "post",
contentType: "application/json",
payload: JSON.stringify(payload),
headers: {
"Authorization": "Bearer " + apiKey
}
};
let response = UrlFetchApp.fetch(endpoint, options);
let json = response.getContentText();
let data = JSON.parse(json);
return data.choices[0].message.content.trim();
}