forked from bh1xaq/ChatGPT-zabbixAlert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openai.js
48 lines (43 loc) · 1.29 KB
/
openai.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
// @see https://docs.aircode.io/guide/functions/
const aircode = require('aircode');
var axios = require('axios');
// 通过 OpenAI API 获取砖家意见
async function getOpenAIReply(content) {
var prompt = "请问 Zabbix 告警 " + content + " 应该如何处理。";
var data = JSON.stringify({
"model": "text-davinci-003",
"prompt": prompt,
"max_tokens": 1024,
"temperature": 0.9,
"frequency_penalty": 0.0,
"presence_penalty": 0.0,
"top_p": 1,
"stop": ["#"]
});
var config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.openai.com/v1/completions',
headers: {
'Authorization': `Bearer ${process.env.OPENAIKEY}`,
'Content-Type': 'application/json'
},
data: data
};
const response = await axios(config)
// 去除多余的换行
return response.data.choices[0].text.replace("\n\n", "")
}
module.exports = async function (params, context) {
console.log('Received params:', params);
if (params.zakey == process.env.ZAKEY) {
// 鉴权成功,处理问题
res = await getOpenAIReply(params.quesion)
return {
message: res
}
}
return {
message: '403...',
};
}