[optimization] 通义千问代码优化02
This commit is contained in:
parent
fc2e12b51c
commit
d8cc24675f
@ -13,6 +13,9 @@ import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
|||||||
import org.springframework.data.redis.core.ReactiveValueOperations;
|
import org.springframework.data.redis.core.ReactiveValueOperations;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -20,13 +23,15 @@ import java.util.*;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@RestController
|
||||||
|
@RequestMapping("/aaaa")
|
||||||
public class QWenService {
|
public class QWenService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
|
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/aaa")
|
||||||
public Mono<QWenReplyRequest> communication(TongYiCommunicationRest rest) {
|
public Mono<QWenReplyRequest> communication(TongYiCommunicationRest rest) {
|
||||||
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
|
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
|
||||||
return operations.get(RedisConstans.TY_QUEUE_LIST + rest.getOnlyId()).defaultIfEmpty("").flatMap(res -> {
|
return operations.get(RedisConstans.TY_QUEUE_LIST + rest.getOnlyId()).defaultIfEmpty("").flatMap(res -> {
|
||||||
@ -63,9 +68,10 @@ public class QWenService {
|
|||||||
return WebClientUtils.post("http://192.168.8.211:5010/qg_human/qwen", new JSONObject(map)).flatMap(jsonObject -> {
|
return WebClientUtils.post("http://192.168.8.211:5010/qg_human/qwen", new JSONObject(map)).flatMap(jsonObject -> {
|
||||||
long time = new Date().getTime();
|
long time = new Date().getTime();
|
||||||
QGResponse qgResponse = jsonObject.toJavaObject(QGResponse.class);
|
QGResponse qgResponse = jsonObject.toJavaObject(QGResponse.class);
|
||||||
QWenReplyRequest data = (QWenReplyRequest) qgResponse.getData();
|
QWenReplyRequest data = new QWenReplyRequest();
|
||||||
log.info("发起TY请求,响应时间时间为:{}", new Date().getTime() - time);
|
log.info("发起TY请求,响应时间时间为:{}", new Date().getTime() - time);
|
||||||
if (qgResponse.getStatusCode() == 0) {
|
if (qgResponse.getStatusCode() == 0) {
|
||||||
|
data = JSONObject.parseObject(qgResponse.getData().toString(), QWenReplyRequest.class);
|
||||||
//成功
|
//成功
|
||||||
log.info("通知成功:" + qgResponse.getData());
|
log.info("通知成功:" + qgResponse.getData());
|
||||||
data.setCode(200);
|
data.setCode(200);
|
||||||
@ -83,8 +89,7 @@ public class QWenService {
|
|||||||
map.put("task_type", "qwen");
|
map.put("task_type", "qwen");
|
||||||
map.put("text", "你好");
|
map.put("text", "你好");
|
||||||
try {
|
try {
|
||||||
Mono<QWenReplyRequest> qgResponseMono = httpTY(map);
|
httpTY(map);
|
||||||
System.out.println(qgResponseMono.block());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("异常:{}", e);
|
log.info("异常:{}", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user