「开源」Android Studio完美对接ChatGPT

支持多平台服务

  • OpenAI ChatGPT 系列模型
  • One Api 系列平台服务
  • API2D 平台服务
  • 其他代理服务

效果演示

图片[1]-「开源」Android Studio完美对接ChatGPT - 昔尘源分享-昔尘源分享

图片[2]-「开源」Android Studio完美对接ChatGPT - 昔尘源分享-昔尘源分享

部署教程

程序基于Android Studio开发,百度自行下载!

找到如下路径:app/src/main/java/com/example/gpt/MainActivity.java

搜索方法:callAPI

try {
    // 创建messages数组,包含用户角色和问题内容
    JSONArray messagesArray = new JSONArray();
    JSONObject systemMessage = new JSONObject();
    systemMessage.put("role", "system");
    systemMessage.put("content", "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.");
    JSONObject userMessage = new JSONObject();
    userMessage.put("role", "user");
    userMessage.put("content", question);
    messagesArray.put(systemMessage);
    messagesArray.put(userMessage);
    // 构建完整的JSON请求体
    jsonBody.put("model", "gpt-3.5-turbo"); // 模型选择
    jsonBody.put("messages", messagesArray);

}catch (JSONException e) {
    throw new RuntimeException(e);
}

RequestBody body = RequestBody.create(jsonBody.toString(), JSON);
Request request = new Request.Builder()
    .url("<https://api.openai.com/v1/chat/completions>") // 服务器地址
    .header("Authorization", "Bearer sk-xxx") // 填写你的key
    .header("Content-Type", "application/json")
    .post(body)
    .build();

下载

GitHub:https://github.com/PastKing/ChatGPT-Android
GitBee:https://gitee.com/past-dust/chat-gpt-android
123盘:https://www.123pan.com/s/7hX0Vv-hHkbv.html
提取码:BO5q

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容