From 4326ab2da162f817f644ff050eb30f00eedb3bbc Mon Sep 17 00:00:00 2001 From: LuanY77 <2307984361@qq.com> Date: Thu, 31 Jul 2025 13:02:02 +0800 Subject: [PATCH] =?UTF-8?q?Test:=20=E6=B5=8B=E8=AF=95=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=8C=96=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invocation/ChatAIInvocationHandler.java | 4 ++- .../ai/ollama/model/OllamaModelProvider.java | 14 ++++++++-- .../com/yomahub/liteflow/test/cmp/AICmp.java | 2 +- .../com/yomahub/liteflow/test/cmp/Output.java | 28 +++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/Output.java diff --git a/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/proxy/invocation/ChatAIInvocationHandler.java b/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/proxy/invocation/ChatAIInvocationHandler.java index a0791a76d..5f49cfe1d 100644 --- a/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/proxy/invocation/ChatAIInvocationHandler.java +++ b/liteflow-ai/liteflow-ai-core/src/main/java/com/yomahub/liteflow/ai/proxy/invocation/ChatAIInvocationHandler.java @@ -64,7 +64,9 @@ public class ChatAIInvocationHandler extends AbstractAIInvocationHandler { + // 开启结构化输出 + if (Objects.equals(ResponseType.JSON, wrapBean.getResponseType())) { + ollamaChatModelBuilder.responseFormat(ResponseFormat.JSON) + .supportedCapabilities(Capability.RESPONSE_FORMAT_JSON_SCHEMA); + } + return ollamaChatModelBuilder.build(); + }); } @Override diff --git a/liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/AICmp.java b/liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/AICmp.java index 73527f792..2b9400d52 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/AICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/AICmp.java @@ -29,7 +29,7 @@ import com.yomahub.liteflow.ai.domain.enums.ResponseType; ) @AIOutput( responseType = ResponseType.JSON, - entityClass = Integer.class, + entityClass = Output.class, methodExpress = "setData", useKeyIndex = true, key = "result" diff --git a/liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/Output.java b/liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/Output.java new file mode 100644 index 000000000..16828270e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-ai/src/test/java/com/yomahub/liteflow/test/cmp/Output.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.cmp; + +/** + * 测试结构化输出使用 + * + * @author 苍镜月 + * @since TODO + */ + +public class Output { + + private String content; + + public Output() { + } + + public Output(String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +}