Administrator
2025-09-03 629da7314cfdb172ba734d4abafa51d7f0c32c3a
src/main/java/cc/mrbird/febs/ai/strategy/Impl/AliLlmStrategyServiceImpl.java
@@ -29,7 +29,8 @@
    private GenerationParam generationParam;
    private static final String apiKey = "sk-babdcf8799144134915cee2683794b2f";
    private static final String model = "qwen-plus";
//    private static final String model = "qwen-plus";
    private static final String model = "qwen3-14b-ft-202509031002-7446";
    @PostConstruct
    public void init() {
@@ -75,6 +76,7 @@
        List<Message> messages = getMessages(dto);
        Generation gen = new Generation();
        generationParam.setMessages(messages);
        generationParam.setEnableThinking( false);
        FebsResponse febsResponse = new FebsResponse();
        try {
            GenerationResult result = gen.call(generationParam);
@@ -92,7 +94,7 @@
    }
    @Override
    public Flux<FebsResponse> llmInvokeStreaming(List<LlmStrategyDto> dto) {
    public Flux<FebsResponse> llmInvokeStreamingWithThink(List<LlmStrategyDto> dto) {
        if (CollUtil.isEmpty(dto)){
            throw new FebsException("百炼大模型初始化异常");
        }
@@ -103,7 +105,7 @@
        generationParam.setMessages(messages);
        generationParam.setResultFormat(GenerationParam.ResultFormat.MESSAGE);
        generationParam.setEnableThinking( true);
        generationParam.setIncrementalOutput(true);
        generationParam.setIncrementalOutput( true);
        Flowable<GenerationResult> result;
        try {
            result = gen.streamCall(generationParam);
@@ -118,7 +120,46 @@
                        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());
                        stringStringHashMap.put(LlmStrategyContextEnum.CONTENT.name(),message.getOutput().getChoices().get(0).getMessage().getContent());
                    }
                    return new FebsResponse().success().data(stringStringHashMap);
                })
                .doOnComplete(() -> {
                    long endTime = System.currentTimeMillis();
                    System.out.println("百炼大模型输出:" + (endTime - startTime) + "毫秒");
                })
                .doOnError(error -> {
                    throw new FebsException(StrUtil.format("百炼大模型输出失败:{}",error));
                });
    }
    @Override
    public Flux<FebsResponse> llmInvokeStreamingNoThink(List<LlmStrategyDto> dto) {
        if (CollUtil.isEmpty(dto)){
            throw new FebsException("百炼大模型初始化异常");
        }
        List<Message> messages = getMessages(dto);
        long startTime = System.currentTimeMillis();
        Generation gen = new Generation();
        generationParam.setMessages(messages);
        generationParam.setResultFormat(GenerationParam.ResultFormat.MESSAGE);
        generationParam.setIncrementalOutput( true);
        generationParam.setEnableThinking( false);
        Flowable<GenerationResult> result;
        try {
            result = gen.streamCall(generationParam);
        } catch (NoApiKeyException | InputRequiredException e) {
            throw new FebsException(StrUtil.format("百炼大模型输出失败:{}",e.getMessage()));
        }
        return Flux.from(result)
                .map(message -> {
                    HashMap<String, String> stringStringHashMap = new HashMap<>();
                    if (StrUtil.isNotEmpty(message.getOutput().getChoices().get(0).getMessage().getContent())){
                        String content = message.getOutput().getChoices().get(0).getMessage().getContent();
                        System.out.print( content);
                        stringStringHashMap.put(LlmStrategyContextEnum.CONTENT.name(),content);
                    }
                    return new FebsResponse().success().data(stringStringHashMap);
                })