mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-11 16:06:53 +08:00
Test: OllamaModel基础实现,添加基础测试
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.yomahub.liteflow.ai.config;
|
||||
|
||||
import com.yomahub.liteflow.ai.proxy.AIComponentPostProcessor;
|
||||
import com.yomahub.liteflow.springboot.config.LiteflowMainAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -12,6 +14,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@AutoConfigureBefore({ LiteflowMainAutoConfiguration.class })
|
||||
public class LiteflowAIAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.yomahub.liteflow.ai.domain.constant;
|
||||
|
||||
/**
|
||||
* 模型提供商常量
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
public interface ProviderName {
|
||||
|
||||
String OLLAMA = "ollama";
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.enums;
|
||||
package com.yomahub.liteflow.ai.domain.enums;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
@@ -2,7 +2,7 @@ package com.yomahub.liteflow.ai.proxy.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.ai.annotation.AIComponent;
|
||||
import com.yomahub.liteflow.ai.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.domain.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.proxy.wrap.AIProxyWrapBean;
|
||||
import com.yomahub.liteflow.ai.util.SetUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.yomahub.liteflow.ai.proxy.handler;
|
||||
|
||||
import com.yomahub.liteflow.ai.annotation.AIChat;
|
||||
import com.yomahub.liteflow.ai.annotation.AIComponent;
|
||||
import com.yomahub.liteflow.ai.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.domain.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.proxy.invocation.ChatAIInvocationHandler;
|
||||
import com.yomahub.liteflow.ai.proxy.wrap.AIProxyWrapBean;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.yomahub.liteflow.ai.proxy.handler;
|
||||
|
||||
import com.yomahub.liteflow.ai.annotation.AIClassify;
|
||||
import com.yomahub.liteflow.ai.annotation.AIComponent;
|
||||
import com.yomahub.liteflow.ai.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.domain.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.proxy.invocation.ClassifyAIInvocationHandler;
|
||||
import com.yomahub.liteflow.ai.proxy.wrap.AIProxyWrapBean;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.yomahub.liteflow.ai.proxy.handler;
|
||||
|
||||
import com.yomahub.liteflow.ai.annotation.AIComponent;
|
||||
import com.yomahub.liteflow.ai.annotation.AIRetrieval;
|
||||
import com.yomahub.liteflow.ai.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.domain.enums.AITypeEnum;
|
||||
import com.yomahub.liteflow.ai.proxy.invocation.RetrievalAIInvocationHandler;
|
||||
import com.yomahub.liteflow.ai.proxy.wrap.AIProxyWrapBean;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.yomahub.liteflow.ai.config.LiteflowAIAutoConfiguration
|
||||
@@ -0,0 +1 @@
|
||||
com.yomahub.liteflow.ai.config.LiteflowAIAutoConfiguration
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yomahub.liteflow.ai.ollama.config;
|
||||
|
||||
import com.yomahub.liteflow.ai.ollama.model.OllamaModelProvider;
|
||||
import com.yomahub.liteflow.springboot.config.LiteflowMainAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@AutoConfigureBefore({ LiteflowMainAutoConfiguration.class })
|
||||
public class OllamaAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public OllamaModelProvider ollamaModelProvider() {
|
||||
return new OllamaModelProvider();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.yomahub.liteflow.ai.ollama.model;
|
||||
|
||||
import com.yomahub.liteflow.ai.config.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.domain.constant.ProviderName;
|
||||
import com.yomahub.liteflow.ai.model.ModelProviderRegistrar;
|
||||
import dev.langchain4j.model.chat.ChatModel;
|
||||
import dev.langchain4j.model.chat.StreamingChatModel;
|
||||
import dev.langchain4j.model.ollama.OllamaChatModel;
|
||||
import dev.langchain4j.model.ollama.OllamaStreamingChatModel;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
public class OllamaModelProvider extends ModelProviderRegistrar {
|
||||
|
||||
@Override
|
||||
public String getProviderName() {
|
||||
return ProviderName.OLLAMA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ChatModel> createChatModel(ModelConfig config) {
|
||||
// TODO
|
||||
return Optional.of(
|
||||
OllamaChatModel.builder()
|
||||
.baseUrl(config.getBaseUrl())
|
||||
.modelName(config.getModel())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<StreamingChatModel> createStreamingChatModel(ModelConfig config) {
|
||||
// TODO
|
||||
return Optional.of(
|
||||
OllamaStreamingChatModel.builder()
|
||||
.baseUrl(config.getBaseUrl())
|
||||
.modelName(config.getModel())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.yomahub.liteflow.ai.ollama.config.OllamaAutoConfiguration
|
||||
@@ -0,0 +1 @@
|
||||
com.yomahub.liteflow.ai.ollama.config.OllamaAutoConfiguration
|
||||
@@ -19,6 +19,12 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-ai-ollama</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.yonahub.liteflow.test;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
@TestPropertySource(value = "classpath:application.properties")
|
||||
@SpringBootTest(classes = {ProxyTest.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yonahub.liteflow.test.cmp"})
|
||||
public class ProxyTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testProxy() {
|
||||
LiteflowResponse liteflowResponse = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assertions.assertTrue(liteflowResponse.isSuccess());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yonahub.liteflow.test.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
@Component("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yonahub.liteflow.test.cmp;
|
||||
|
||||
import com.yomahub.liteflow.ai.annotation.AIChat;
|
||||
import com.yomahub.liteflow.ai.annotation.AIComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
@AIComponent(
|
||||
nodeId = "aiCmpId",
|
||||
nodeName = "aiCmpName",
|
||||
provider = "ollama",
|
||||
baseUrl = "http://localhost:11434",
|
||||
model = "qwen3:32b"
|
||||
)
|
||||
@Component
|
||||
@AIChat(
|
||||
userPrompt = "Why sky is blue?"
|
||||
)
|
||||
public interface AICmp {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yonahub.liteflow.test.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=flow.el.xml
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
THEN(a, aiCmpId, b);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user