var gptKey = 'xxxxxx'
var callChatGpt3 = function (text) {
Console.log('启用加速口令:' + gptKey.substr(-10))
Console.log('-----------------------------3')
if (!Utils.endsWith(text, "?") && !Utils.endsWith(text, "?")) {
text = text + "?"
}
var messages = new java.util.ArrayList();
var map = new java.util.HashMap();
map.put("role", "user");
map.put("content", text)
messages.add(map)
var data = {
"model": "gpt-3.5-turbo",
"tokensLength": 1024,
"messages": messages
}
var para = {
"token": gptKey,
"seriNo": Device.getAndroidId(),
"questions": data
}
var response = Http.post().url('https://viptest.byjxy.cn/voice-api/voice/ai/talk-toutiao')
.params(para)
.build().call()
if (!response) {
return null
}
var body = response.body().string()
var json = JSON.parse(body)
if (json == null) {
Console.log('gpt请求超时!')
return null
}
if (!json.data) {
Console.log('gpt调用数据错误:' + body)
if (json.code == 400) {
old = ''
}
return
}
return json.data.choices[0].message.content
}