• 为什么星火大模型连接失败


    关注 码龄 粉丝数 原力等级 -- 被采纳 被点赞 采纳率 稀有气体 2024-03-21 14:52 采纳率: 0% 浏览 3 首页/ 编程语言 / 为什么星火大模型连接失败 java人工智能 尝试连接星火大模型,代码是ai写的,依赖项已导入,代码如下 package com.example; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.json.JSONObject; public class XingHuoApiDemo { private static final String API_URL = "wss://spark-api.xf-yun.com/v3.5/chat"; private static final String API_KEY = "xxx"; private static final String API_SECRET = "xx"; private static final String API_ID = "xxx"; public XingHuoApiDemo() { } public static void main(String[] args) { String question = "你好,星火大模型!"; try { String response = sendRequest(question); System.out.println("星火大模型的回答:" + response); } catch (Exception var3) { System.err.println("发送请求失败:" + var3.getMessage()); } } private static String sendRequest(String question) throws Exception { CloseableHttpClient httpClient = HttpClients.createDefault(); String var7; try { HttpPost httpPost = new HttpPost("wss://spark-api.xf-yun.com/v3.5/chat"); httpPost.setHeader("Content-Type", "application/json"); httpPost.setHeader("X-API-Key", "cea060d349029bde01d26f207def9184"); httpPost.setHeader("X-API-Secret", "ZTBhYzgxYmE0ZDI4YjBlZGZlN2QyMDlm"); JSONObject json = new JSONObject(); json.put("question", question); json.put("api_id", "37b2e96d"); StringEntity entity = new StringEntity(json.toString(), "UTF-8"); httpPost.setEntity(entity); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); var7 = EntityUtils.toString(httpEntity, "UTF-8"); } catch (Throwable var9) { if (httpClient != null) { try { httpClient.close(); } catch (Throwable var8) { var9.addSuppressed(var8); } } throw var9; } if (httpClient != null) { httpClient.close(); } return var7; } } 报错日志如下“"C:\Program Files\Java\jdk-20\bin\java.exe" "-javaagent:D:\IDEA\IntelliJ IDEA 2023.3.4\lib\idea_rt.jar=52557:D:\IDEA\IntelliJ IDEA 2023.3.4\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\Administrator\myproject\target\classes;C:\Users\Administrator.m2\repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;C:\Users\Administrator.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\Administrator.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;C:\Users\Administrator.m2\repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;C:\Users\Administrator.m2\repository\org\json\json\20210307\json-20210307.jar com.example.XingHuoApiDemo发送请求失败:null” xml文件如下 4.0.0 com.example myproject jar 1.0-SNAPSHOT myproject http://maven.apache.org org.apache.httpcomponents httpclient 4.5.13 org.apache.httpcomponents httpcore 4.4.13 org.json json 20210307 ide为idea,请问为什么会失败啊 展开全部 收起 写回答 好问题 0 提建议 追加酬金 关注问题 微信扫一扫 点击复制链接 分享 邀请回答 编辑 收藏 删除 结题 收藏 举报 追加酬金 (90%的用户在追加酬金后获得了解决方案) 当前问题酬金 ¥ 0 (可追加 ¥500) ¥ 15¥ 20¥ 50¥ 100¥ 200 支付方式 扫码支付 二维码出错 点击刷新 支付金额 15 元 提供问题酬金的用户不参与问题酬金结算和分配 支付即为同意 《付费问题酬金结算规则》 结题 再想想 删除 再等等

    1条回答 默认 最新

    • 码农阿豪 Java领域优质创作者 2024-03-21 14:52
      关注
      让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
      问题描述: 尝试连接星火大模型,在AI编写的代码中已导入相关依赖,但运行后出现报错日志。 解答: 根据报错日志,可能是因为代码中引入的依赖未正常加载所致。可尝试以下步骤进行排查与解决: 1.检查已经导入的依赖是否存在问题,例如版本过旧、缺失等,可尝试更新或重新下载并添加到项目中。 2.检查代码中涉及到依赖的部分是否正确,例如方法名、参数名等是否正确拼写。 3.检查代码和依赖的打包方式是否一致,例如如果代码是使用Maven打包的,则依赖也应该是通过Maven管理的。 4.最后,如果问题仍未解决,可尝试通过重新安装Java运行时环境或IDE等方式进行排查。 样例代码:
      import org.apache.http.HttpEntity;
      import org.apache.http.HttpResponse;
      import org.apache.http.client.methods.HttpPost;
      import org.apache.http.entity.StringEntity;
      import org.apache.http.impl.client.CloseableHttpClient;
      import org.apache.http.impl.client.HttpClients;
      import org.apache.http.util.EntityUtils;
      import org.json.JSONObject;
      public class XingHuoApiDemo {
          private static final String API_URL = "wss://spark-api.xf-yun.com/v3.5/chat";
          private static final String API_KEY = "xxx";
          private static final String API_SECRET = "xx";
          private static final String API_ID = "xxx";
          
          public XingHuoApiDemo() {}
          
          public static void main(String[] args) {
              String question = "你好,星火大模型!";
              try {
                  String response = sendRequest(question);
                  System.out.println("星火大模型的回答:" + response);
              } catch (Exception var3) {
                  System.err.println("发送请求失败:" + var3.getMessage());
              }
          }
          
          private static String sendRequest(String question) throws Exception {
          CloseableHttpClient httpClient = HttpClients.createDefault();
              String responseStr;
              try {
                  HttpPost httpPost = new HttpPost(API_URL);
                  httpPost.setHeader("Content-Type", "application/json");
                  httpPost.setHeader("X-API-Key", API_KEY);
                  httpPost.setHeader("X-API-Secret", API_SECRET);
                  JSONObject json = new JSONObject();
                  json.put("question", question);
                  json.put("api_id", API_ID);
                  StringEntity se = new StringEntity(json.toString(), "UTF-8");
                  httpPost.setEntity(se);
                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  responseStr = EntityUtils.toString(httpEntity, "UTF-8");
              } catch (Throwable var9) {
                  if (httpClient != null) {
                      try {
                          httpClient.close(); 
                      } catch (Throwable var8) {
                          var9.addSuppressed(var8);
                      }
                  }
                  throw var9;
              }
              if (httpClient != null) {
                  httpClient.close();
              }
              return responseStr;
          }
      }
      

      展开全部

      评论
      编辑
      预览

      报告相同问题?

    • 相关阅读:
      【超好懂的比赛题解】HNCPC Multi-university Training Round2 比赛题解(AHBGIK)
      目标检测(3)—— 如何使用PyTorch加载COCO类型的数据集
      Android Studio模拟器/虚拟设备连接互联网的方法
      一带一路合作高峰论坛召开,附市场开发建议
      2021 RoboCom 世界机器人开发者大赛-本科组(初赛)
      FFT专题:IFFT后信号如何重建
      Shader Graph的用法初探
      Linux 之 openssl 文件夹加密压缩与解压
      多巴胺修饰ZnS硫化锌量子点 Dopamine-ZnS QDs
      Linux学习记录——삼십일 socket编程---TCP套接字
    • 原文地址:https://ask.csdn.net/questions/8076785