Commit d3bc71cc authored by alex yao's avatar alex yao

fix:修复大模型调用失败提示文案

parent 4e805c45
...@@ -816,7 +816,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -816,7 +816,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
if (!"0".equals(result.getCode())) { if (!"0".equals(result.getCode())) {
logger.error("LLM Error,code:{}", result.getCode()); logger.error("LLM Error,code:{}", result.getCode());
I18nMessageException ex = new I18nMessageException("exception/call.failure"); I18nMessageException ex = new I18nMessageException("exception/call.failure");
writer.write(EVENT_STREAM_PREFIX + JsonUtils.serialize(ex.getMessage()) + "\n\n"); result.setMessage(ex.getMessage());
writer.write(EVENT_STREAM_PREFIX + JsonUtils.serialize(result) + "\n\n");
writer.write(EVENT_STREAM_PREFIX + "[DONE]\n\n"); writer.write(EVENT_STREAM_PREFIX + "[DONE]\n\n");
writer.flush(); writer.flush();
writer.close(); writer.close();
......
...@@ -19,6 +19,8 @@ import org.apache.http.entity.StringEntity; ...@@ -19,6 +19,8 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -40,6 +42,8 @@ import java.util.List; ...@@ -40,6 +42,8 @@ import java.util.List;
public class AIDialogueServiceImpl implements AIDialogueService { public class AIDialogueServiceImpl implements AIDialogueService {
private final String POST = "POST"; private final String POST = "POST";
private final Logger logger = LoggerFactory.getLogger(AIDialogueService.class);
@Value("${dgtools.domain.url}") @Value("${dgtools.domain.url}")
private String DOMAIN_URL; private String DOMAIN_URL;
...@@ -95,20 +99,20 @@ public class AIDialogueServiceImpl implements AIDialogueService { ...@@ -95,20 +99,20 @@ public class AIDialogueServiceImpl implements AIDialogueService {
.build() .build()
); );
InputStream inputStream = httpResponse.getEntity().getContent(); InputStream inputStream = httpResponse.getEntity().getContent();
Header contentType = httpResponse.getFirstHeader("Content-type"); // Header contentType = httpResponse.getFirstHeader("Content-type");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
if ("application/json".equals(contentType.getValue()) || "text/plain;charset=UTF-8".equals(contentType.getValue()) || "application/json; charset=utf-8".equals(contentType.getValue())) { // if ("application/json".equals(contentType.getValue()) || "text/plain;charset=UTF-8".equals(contentType.getValue()) || "application/json; charset=utf-8".equals(contentType.getValue())) {
String res; // String res;
StringBuilder stringBuilder = new StringBuilder(); // StringBuilder stringBuilder = new StringBuilder();
while ((res = bufferedReader.readLine()) != null) { // while ((res = bufferedReader.readLine()) != null) {
if (StringUtils.isBlank(res)) { // if (StringUtils.isBlank(res)) {
continue; // continue;
} // }
stringBuilder.append(res); // stringBuilder.append(res);
} // }
LargeModelDemandResult result = JsonUtils.deSerialize(stringBuilder.toString(), LargeModelDemandResult.class); // LargeModelDemandResult result = JsonUtils.deSerialize(stringBuilder.toString(), LargeModelDemandResult.class);
throw new BusinessException(result.getMessage()); // logger.error("调用大模型接口失败:{}", result.getMessage());
} // }
return bufferedReader; return bufferedReader;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment