zl程序教程

您现在的位置是:首页 >  其他

当前栏目

为在线客服系统接入chatGPT(二):接口对接开发

2023-03-07 09:42:50 时间

我们可以知道chatGPT的公开接口为:

请求接口:
URL:-POST https://api.openai.com/v1/completions
headers: { 'content-type': 'application/json', 'Authorization': 'Bearer ' +官网获取的api秘钥 }
data:{prompt: 问题内容, max_tokens: 2048, model: "text-davinci-003"}

curl脚本测试

curl 'https://api.openai.com/v1/completions' \
-X POST \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer 官网密钥' \
-d '{"prompt":"你是谁?","max_tokens":2048,"model":"text-davinci-003"}' \
--compressed

其他各种语言的脚本可以自行根据上面的参数进行编写

例如我golang语言的测试