- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我收到以下错误:
[3067] NetworkUtility.shouldRetryException: Unexpected response code400 for https://api.openai.com/v1/chat/completions
代码:
private fun getResponseTurbo(query: String) {
// setting text on for question on below line.
questionTV.text = query
queryEdt.setText("")
// creating a queue for request queue.
val queue: RequestQueue = Volley.newRequestQueue(applicationContext)
// creating a json object on below line.
val jsonObject: JSONObject ? = JSONObject()
// adding params to json object.
jsonObject ? .put("model", "gpt-3.5-turbo")
jsonObject ? .put("messages", "[{'role': 'user', 'content': 'What are your functionalities?'}]")
jsonObject ? .put("temperature", 0)
jsonObject ? .put("max_tokens", 48)
jsonObject ? .put("top_p", 1)
jsonObject ? .put("frequency_penalty", 0)
jsonObject ? .put("presence_penalty", 0)
// on below line making json object request.
val postRequest: JsonObjectRequest =
// on below line making json object request.
object: JsonObjectRequest(Method.POST, url_turbo, jsonObject,
Response.Listener {
response - >
// on below line getting response message and setting it to text view.
val responseMsg: String =
response.getJSONArray("choices").getJSONObject(0).getString("message")
chattypingLT.visibility = View.GONE
ll_copy_share.visibility = View.VISIBLE
responseTV.text = responseMsg
},
// adding on error listener
Response.ErrorListener {
error - >
Log.e("TAGAPI", "Error is : " + error.message + "\n" + error)
}) {
override fun getHeaders(): kotlin.collections.MutableMap < kotlin.String, kotlin.String > {
val params: MutableMap < String,
String > = HashMap()
// adding headers on below line.
params["Content-Type"] = "application/json"
params["Authorization"] =
"Bearer APIKEY"
return params;
}
}
// on below line adding retry policy for our request.
postRequest.setRetryPolicy(object: RetryPolicy {
override fun getCurrentTimeout(): Int {
return 50000
}
override fun getCurrentRetryCount(): Int {
return 50000
}
@Throws(VolleyError::class)
override fun retry(error: VolleyError) {}
})
// on below line adding our request to queue.
queue.add(postRequest)
}
最佳答案
您使用的是 gpt-3.5-turbo
型号。
Chat Completions API 之间存在三个主要区别(即 GPT-3.5 API)和 Completions API (即 GPT-3 API):
https://api.openai.com/v1/completions
https://api.openai.com/v1/chat/completions
prompt
参数(Completions API)已替换为 messages
参数(Chat Completions API)response.getJSONArray("choices").getJSONObject(0).getString("text")
response.getJSONArray("choices").getJSONObject(0).getString("message")
问题
您答对了第一点和第三点。这(即第二个要点)是代码中有问题的部分:
jsonObject ? .put("messages", "[{'role': 'user', 'content': 'What are your functionalities?'}]")
为什么?
您提供的代码中 messages
参数的 JSON 无效,这是因为它对字符串值使用单引号。在 JSON 中,字符串值应始终用双引号括起来,而不是单引号。
解决方案
试试这个:
JSONObject jsonObject = new JSONObject();
JSONArray messages = new JSONArray();
JSONObject message = new JSONObject();
message.put("role", "user");
message.put("content", "What are your functionalities?");
messages.put(message);
jsonObject.put("messages", messages);
此代码将创建以下 JSON 对象:
{
"messages": [
{
"role": "user",
"content": "What are your functionalities?"
}
]
}
如果您仍然收到 API 错误 400
,请确保您已将 Content-Type
header 设置为 application/json
。请小心,application/json, UTF-8
不起作用。
关于android - OpenAI ChatGPT (GPT-3.5) API 错误 400 : "Unexpected response code 400 for https://api.openai.com/v1/chat/completions" (migrating GPT-3 to GPT-3. 5 API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75823578/
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我收到以下错误:模块“openai”没有属性“ChatCompletion” 我检查了其他帖子。都在说升级OpenAI Python包或者升级Python。我都做了,但没有修复它。 Python:3.
我有一个用例,非常需要来自 OpenAI API 的完全确定性响应。然而,玩弄温度似乎无法产生完全的决定论。 import openai openai.organization = "org-..."
OpenAI api 包含一个微调服务,将任务分为“提示”和“完成” https://platform.openai.com/docs/guides/fine-tuning 文档说准确度指标是根据完成
我通过openai的text-davinci-003可以正常返回对话信息,但是目前无法实现上下文关联功能。我搜索了一下,发现有一个“conversation_id”参数,但是添加该参数后,API返回“
我有一个用例,非常需要来自 OpenAI API 的完全确定性响应。然而,玩弄温度似乎无法产生完全的决定论。 import openai openai.organization = "org-..."
OpenAI api 包含一个微调服务,将任务分为“提示”和“完成” https://platform.openai.com/docs/guides/fine-tuning 文档说准确度指标是根据完成
我通过openai的text-davinci-003可以正常返回对话信息,但是目前无法实现上下文关联功能。我搜索了一下,发现有一个“conversation_id”参数,但是添加该参数后,API返回“
我想使用 openai.embeddings_utils import get_embeddings所以已经安装了openai Name: openai Version: 0.26.5 Summary
当我使用 GPT3 的 playground 时,我经常得到带有编号列表和段落格式的结果,如下所示: Here's what the above class is doing: 1. It creat
当我使用 GPT3 的 playground 时,我经常得到带有编号列表和段落格式的结果,如下所示: Here's what the above class is doing: 1. It creat
我想使用 openai.embeddings_utils import get_embeddings所以已经安装了openai Name: openai Version: 0.26.5 Summary
OpenAI/chat GPT也支持docx/pdf文件上传吗?。我想上传多个文件到openAI/chatGPT。我在https://platform.openai.com/docs/api-refe
openAI/chatGPT也支持docx/pdf文件上传吗? 我想上传多个文件到 openAI/chatGPT。我尝试了 https://platform.openai.com/docs/api-r
openAI/chatGPT也支持docx/pdf文件上传吗? 我想上传多个文件到 openAI/chatGPT。我尝试了 https://platform.openai.com/docs/api-r
如果我们查看环境的预览,它们会在右下角的动画中显示剧集的增加。 https://gym.openai.com/envs/CartPole-v1/ .是否有明确显示的命令? 最佳答案 我认为 Ope
是否有人从使用 text-embedding-ada-002 的 Azure OpenAI 嵌入部署中获得的结果与 OpenAI 的结果不同?相同的文本,相同的模型,结果在向量空间中相差相当远。 对于
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我正在学习gpt微调 我成功运行了这个命令:pip install --upgrade openai 我无法运行此命令:export OPENAI_API_KEY="sk-xxxxxxxxxxxxxx
如何解决Openai API 不断输出的问题,比如让gpt api 写一篇文章。如果内容中断,可以继续提问,从而继续输出以上内容。这在ChatGPT中很容易做到,但是Openai API加上上面的提示
我是一名优秀的程序员,十分优秀!