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; + } +}