18586361686
2025-05-20 d8f364dd457f2732bdf09d0d10cf3a32d5adf717
chore: 优化代码
1个文件已修改
24 ■■■■ 已修改文件
aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/controller/AiBotController.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/controller/AiBotController.java
@@ -180,21 +180,23 @@
            @Override
            public void onMessage(ChatContext context, AiMessageResponse response) {
                try {
                    // 检查是否需要触发 Function Calling
                    if (CollectionUtil.hasItems(response.getFunctionCallers())) {
                        needClose[0] = false;
                        function_call(response, emitter, needClose, historiesPrompt, llm, prompt, false);
                    } else {
                        // 强制流式返回,即使有 Function Calling 也先返回部分结果
                        if (response.getMessage() != null) {
                            String content = response.getMessage().getContent();
                            if (StringUtil.hasText(content)) {
                                emitter.send(JSON.toJSONString(response.getMessage()));
                    if (response != null){
                        // 检查是否需要触发 Function Calling
                        if (response.getFunctionCallers() != null && CollectionUtil.hasItems(response.getFunctionCallers())) {
                            needClose[0] = false;
                            function_call(response, emitter, needClose, historiesPrompt, llm, prompt, false);
                        } else {
                            // 强制流式返回,即使有 Function Calling 也先返回部分结果
                            if (response.getMessage() != null) {
                                String content = response.getMessage().getContent();
                                if (StringUtil.hasText(content)) {
                                    emitter.send(JSON.toJSONString(response.getMessage()));
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    emitter.completeWithError(e);
                }