调用GPT接口使用3.5模型报错:Unrecognized request argument supplied: messages

报错信息:

话不多说,今天我请求chatgpt接口返回这样的信息:

{
  "error": {
    "message": "Unrecognized request argument supplied: messages",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

一看懵逼了,我的请求参数存在问题,然后各种试,各种改,改成json字符串,改http请求方式,都不行,当中我又怀疑是我key的问题,又换了key还是不行,又以为是我代理网站的问题,后面又换海外网络,用官网域名请求,还是不行,自我怀疑好久,是不是3.5接口更新了,请求格式不对?后面才发现是我请求url和text模型的url搞错了

text模型接口URL:https://api.openai.com/v1/completions

3.5模型接口URL:https://api.openai.com/v1/chat/completions 

最终修改请求URL就能正常调用了,分享一下请求体的json数据:

{
    "messages": [
        {
            "content": "你是一个智能的AI助手。",
            "role": "system"
        },
        {
            "content": "请用java写一个helloWorld",
            "role": "user"
        }
    ],
    "model": "gpt-3.5-turbo"
}

请求方式是用okhttp3:

    private static String fetch(String rowStr, String url) {
        RequestBody requestBody = RequestBody.create(rowStr, MediaType.parse("application/json; charset=utf-8"));
        Request request = new Request.Builder()
                .url(url)
                .header("Authorization", "Bearer " + token)
                .post(requestBody)
                .build();

        Call call = client.newCall(request);
        try {
            Response execute = call.execute();
            return execute.body().string();
        } catch (IOException e) {
            return "error";
        }
    }


//client初始化:

static OkHttpClient client = new OkHttpClient();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值