-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathChatGPT.gs
34 lines (28 loc) · 851 Bytes
/
ChatGPT.gs
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
/ Replace with your OpenAI API key
var API_KEY = "your_api_key";
function GPT(prompt) {
var Model_ID = "text-davinci-002";
var maxTokens = 64;
var temperature = 0.5;
// Build the API payload
var payload = {
'model': 'text-davinci-002', // or your desired model
'prompt': prompt,
'temperature': temperature,
'max_tokens': maxTokens,
};
// Build the API options
var options = {
"method": "post",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer " + API_KEY
},
"payload": JSON.stringify(payload)
};
// Make the API request
var response = UrlFetchApp.fetch("https://api.openai.com/v1/completions", options);
// Parse the response and return the generated text
var responseData = JSON.parse(response.getContentText());
return responseData.choices[0].text.trim();
}