您现在的位置是:网站首页> 编程开发> AI 编程开发

调用国内chatgpt接口

bean2023-06-29AI 242人已围观

简介接口地址:https://www.1bit.asia/openai/api/ask方式:post参数:{"prompt":" 帮我写一篇数据安全的技术文章,最后配图","userName":"douhaichao1","token":"af9667a03c76c00ad58443

调用国内chatgpt接口

最后更新:2023-06-29 18:54:46

推荐指数


接口地址:https://www.1bit.asia/openai/api/ask

方式:post

参数:

{"prompt":" 帮我写一篇数据安全的技术文章,最后配图","userName":"douhaichao1","token":"af9667a03c76c00ad58443310638b84083556773c0371528e","msgFrom":0}


说明:userName参数和token需要对应。同一时间多人调用会产生理解混乱,多组不同账号token请查看。

userName和token自己在网站上注册一下就好,发布一个消息,通过network看到请求的参数,拿出来做为接口使用。


java代码:

private static String getQuestionInfo(String question) {

    try {

        URL url = new URL("https://www.1bit.asia/openai/api/ask");

        HttpURLConnection con = (HttpURLConnection) url.openConnection();

        con.setRequestMethod("POST");

        // 设置请求头

        con.setRequestProperty("Content-Type", "application/json");

        // 设置请求体

        String requestBody = "{\"prompt\":\""+ question +"\",\"token\":\"链接页面获取\",\"userName\":\"apiuser002\"}";

        con.setDoOutput(true);

        con.setDoInput(true);

        OutputStream os = con.getOutputStream();

        os.write(requestBody.getBytes());

        os.flush();

        os.close();

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

        String inputLine;

        StringBuffer content = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {

            content.append(inputLine);

        }

        in.close();

        String questionInfo = content.toString();

        return questionInfo;

    } catch (IOException e) {

        e.printStackTrace();

        return "请求异常";

    }

}

运行结果如下:

5c201fe2b04d39367ffbccfe17a4d587_632804-20230323005811664-1483726444.png



很赞哦! (0)

文章评论

来说两句吧...

验证码: