Skip to content

Commit

Permalink
通义千问解析结果调整
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinDai committed May 21, 2024
1 parent 81b489b commit f3f325c
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.doodl6.wechatrobot.service.assistant.impl;

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationOutput;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
Expand All @@ -14,8 +13,6 @@
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class DashscopeService implements AssistantService {

Expand All @@ -40,19 +37,11 @@ public BaseMessage processText(String content, String fromUserName) {
Message systemMsg = Message.builder().role(Role.SYSTEM.getValue()).content("你是一个AI助手,保持回复内容尽量简短").build();
Message userMsg = Message.builder().role(Role.USER.getValue()).content(content).build();
GenerationParam param =
GenerationParam.builder().model(Generation.Models.QWEN_TURBO).messages(Lists.newArrayList(systemMsg,userMsg))
GenerationParam.builder().model(Generation.Models.QWEN_TURBO).messages(Lists.newArrayList(systemMsg, userMsg))
.resultFormat(GenerationParam.ResultFormat.TEXT)
.build();
GenerationResult result = gen.call(param);
String responseText = result.getOutput().getText();
if (responseText == null) {
List<GenerationOutput.Choice> choiceList = result.getOutput().getChoices();
if (choiceList != null && !choiceList.isEmpty()) {
responseText = choiceList.get(0).getMessage().getContent();
}
}
System.out.println("responseText=" + responseText);

if (responseText != null) {
return new TextMessage(responseText);
}
Expand Down

0 comments on commit f3f325c

Please sign in to comment.