Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
haungxing 7 months ago
parent
commit
98599d8198
  1. 13
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java
  2. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java
  3. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java
  4. 7
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  5. 4
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

13
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java

@ -1,28 +1,35 @@
package com.hnac.hzims.bigmodel; package com.hnac.hzims.bigmodel;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springblade.core.cloud.feign.EnableBladeFeign; import org.springblade.core.cloud.feign.EnableBladeFeign;
import org.springblade.core.jwt.JwtUtil;
import org.springblade.core.launch.BladeApplication; import org.springblade.core.launch.BladeApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.data.redis.core.RedisTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY;
@EnableBladeFeign(basePackages = {"org.springblade","com.hnac"}) @EnableBladeFeign(basePackages = {"org.springblade","com.hnac"})
@SpringCloudApplication @SpringCloudApplication
@MapperScan("com.hnac.hzims.**.mapper.**") @MapperScan("com.hnac.hzims.**.mapper.**")
@ComponentScan(basePackages = {"com.hnac.hzims.bigmodel.*"}) @ComponentScan(basePackages = {"com.hnac.hzims.bigmodel.*"})
@Resource @Resource
@ComponentScan(basePackages = {"com.hnac.hzims.*"}) @ComponentScan(basePackages = {"com.hnac.hzims.*"})
@Slf4j
public class HzimsBigModelApplication extends SpringBootServletInitializer { public class HzimsBigModelApplication extends SpringBootServletInitializer {
public static void main(String[] args) { public static void main(String[] args) {
BladeApplication.run(BigModelConstants.APP_NAME, HzimsBigModelApplication.class, args); BladeApplication.run(BigModelConstants.APP_NAME, HzimsBigModelApplication.class, args);
RedisTemplate<String, Object> redisTemplate = JwtUtil.getRedisTemplate();
redisTemplate.delete(HZIMS_BIGMODEL_ASK_KEY);
log.info("服务重启删除问题reids缓存:{}",HZIMS_BIGMODEL_ASK_KEY);
} }
@Override @Override

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java

@ -17,7 +17,7 @@ public class BigModelInvokeUrl {
private String assistantStatus; private String assistantStatus;
private String deleteAssistant; private String askAbort;
private String updateVideo; private String updateVideo;

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java

@ -62,7 +62,7 @@ public class InteractiveController {
@ApiOperation("删除对话sessionId") @ApiOperation("删除对话sessionId")
@ApiOperationSupport(order = 5) @ApiOperationSupport(order = 5)
@GetMapping("/removeSessionId") @GetMapping("/removeSessionId")
public R<Boolean> removeSessionId(@RequestParam(value = "sessionId") String sessionId) { public R<Boolean> removeSessionId(@RequestParam(value = "id") String sessionId) {
return R.data(interactiveService.removeSessionId(sessionId)); return R.data(interactiveService.removeSessionId(sessionId));
} }

7
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

@ -110,7 +110,9 @@ public class InteractiveServiceImpl implements IInteractiveService {
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks));
}else{ }else{
List<String> asks = JSONObject.parseArray(json.toString(),String.class); List<String> asks = JSONObject.parseArray(json.toString(),String.class);
if(!asks.contains(sessionId)){
asks.add(sessionId); asks.add(sessionId);
}
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks));
} }
return R.success("消息发送成功"); return R.success("消息发送成功");
@ -137,6 +139,9 @@ public class InteractiveServiceImpl implements IInteractiveService {
}); });
JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> {
String[] extras = answerVO.getExtra(); String[] extras = answerVO.getExtra();
if(ObjectUtil.isEmpty(answerVO.getExtra()) || extras.length == 0){
return;
}
List<String> extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); List<String> extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList());
answerVO.setExtra(extraList.toArray(new String[extraList.size()])); answerVO.setExtra(extraList.toArray(new String[extraList.size()]));
}); });
@ -172,7 +177,7 @@ public class InteractiveServiceImpl implements IInteractiveService {
// 调用大模型删除对话 // 调用大模型删除对话
Map<String,Object> params = new HashMap<>(); Map<String,Object> params = new HashMap<>();
params.put("id",sessionId); params.put("id",sessionId);
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAskAbort())
.body(JSON.toJSONString(params)).execute(); .body(JSON.toJSONString(params)).execute();
if(response.getStatus() != HttpServletResponse.SC_OK) { if(response.getStatus() != HttpServletResponse.SC_OK) {
log.error("远程调用大模型【删除对话】接口失败!"); log.error("远程调用大模型【删除对话】接口失败!");

4
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

@ -102,15 +102,17 @@ public class InteractiveSchedule {
List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds));
answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> {
XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!"); XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!");
if(sessionIds.contains(answerVO.getSessionId())){
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
wsService.sendMessage(session,message); wsService.sendMessage(session,message);
}
// 问题回答完成,去除redis问题标记 // 问题回答完成,去除redis问题标记
if(answerVO.getStatus() == 0){ if(answerVO.getStatus() == 0){
sessionIds.remove(answerVO.getSessionId()); sessionIds.remove(answerVO.getSessionId());
} }
}, getAnswerPoolExecutor));
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds));
}, getAnswerPoolExecutor));
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }

Loading…
Cancel
Save