mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-10 11:17:00 +08:00
Test: 测试结构化输出
This commit is contained in:
@@ -64,7 +64,9 @@ public class ChatAIInvocationHandler extends AbstractAIInvocationHandler<ChatPro
|
||||
Object aiService = AiServiceFactory.createAiService(wrapBean.getEntityClass(), chatModel);
|
||||
|
||||
try {
|
||||
return AiServiceFactory.chat(aiService, wrapBean.getUserPrompt(), wrapBean.getSystemPrompt());
|
||||
Object result = AiServiceFactory.chat(aiService, wrapBean.getUserPrompt(), wrapBean.getSystemPrompt());
|
||||
LOG.info("Chat response: {}", result);
|
||||
return result;
|
||||
} catch (Throwable e) {
|
||||
throw new LiteFlowAIException("Error during blocking chat processing", e);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,17 @@ package com.yomahub.liteflow.ai.ollama.model;
|
||||
|
||||
import com.yomahub.liteflow.ai.domain.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.domain.constant.ProviderName;
|
||||
import com.yomahub.liteflow.ai.domain.enums.ResponseType;
|
||||
import com.yomahub.liteflow.ai.model.ModelProviderRegistrar;
|
||||
import com.yomahub.liteflow.ai.proxy.wrap.AIProxyWrapBean;
|
||||
import dev.langchain4j.model.chat.Capability;
|
||||
import dev.langchain4j.model.chat.ChatModel;
|
||||
import dev.langchain4j.model.chat.StreamingChatModel;
|
||||
import dev.langchain4j.model.chat.request.ResponseFormat;
|
||||
import dev.langchain4j.model.ollama.OllamaChatModel;
|
||||
import dev.langchain4j.model.ollama.OllamaStreamingChatModel;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -33,8 +37,14 @@ public class OllamaModelProvider extends ModelProviderRegistrar {
|
||||
.builder()
|
||||
.baseUrl(modelConfig.getBaseUrl())
|
||||
.modelName(modelConfig.getModel())
|
||||
.build()
|
||||
);
|
||||
).map(ollamaChatModelBuilder -> {
|
||||
// 开启结构化输出
|
||||
if (Objects.equals(ResponseType.JSON, wrapBean.getResponseType())) {
|
||||
ollamaChatModelBuilder.responseFormat(ResponseFormat.JSON)
|
||||
.supportedCapabilities(Capability.RESPONSE_FORMAT_JSON_SCHEMA);
|
||||
}
|
||||
return ollamaChatModelBuilder.build();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user