| | |
| | | package cc.mrbird.febs.ai.strategy.Impl; |
| | | |
| | | import cc.mrbird.febs.ai.strategy.LlmStrategyService; |
| | | import cc.mrbird.febs.ai.strategy.enumerates.LlmStrategyContextEnum; |
| | | import cc.mrbird.febs.ai.strategy.param.LlmStrategyDto; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | @Component("AliLlmStrategyService") |
| | |
| | | Generation gen = new Generation(); |
| | | generationParam.setMessages(messages); |
| | | generationParam.setResultFormat(GenerationParam.ResultFormat.MESSAGE); |
| | | generationParam.setEnableThinking( true); |
| | | generationParam.setIncrementalOutput(true); |
| | | Flowable<GenerationResult> result; |
| | | try { |
| | |
| | | |
| | | return Flux.from(result) |
| | | .map(message -> { |
| | | String content = message.getOutput().getChoices().get(0).getMessage().getContent(); |
| | | return new FebsResponse().success().data(content); |
| | | HashMap<String, String> stringStringHashMap = new HashMap<>(); |
| | | if (StrUtil.isNotEmpty(message.getOutput().getChoices().get(0).getMessage().getReasoningContent())){ |
| | | stringStringHashMap.put(LlmStrategyContextEnum.THINK.name(),message.getOutput().getChoices().get(0).getMessage().getReasoningContent()); |
| | | } |
| | | if (StrUtil.isNotEmpty(message.getOutput().getChoices().get(0).getMessage().getContent())){ |
| | | stringStringHashMap.put(LlmStrategyContextEnum.CONTENT.name(),message.getOutput().getChoices().get(0).getMessage().getReasoningContent()); |
| | | } |
| | | return new FebsResponse().success().data(stringStringHashMap); |
| | | }) |
| | | .doOnComplete(() -> { |
| | | long endTime = System.currentTimeMillis(); |