aiflow - Hello world
在 solon 项目里添加依赖(支持 java8, java11, java17, java21, java24)。也可嵌入到第三方框架生态。
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-ai-flow</artifactId>
</dependency>
1、Helloworld 编排
借助 ollama
服务,在本地运行一个 qwen2.5:1.5b
模型服务。然后开始 aiflow
编排:
- 配置一个 message 变量,作为聊天模型的提示语,最后把结果输出到控制台。
具体为:flow/helloworld.chain.yml
:
id: helloworld
layout:
- task: "@VarInput"
meta:
message: "你好"
- task: "@ChatModel"
meta:
chatConfig: # "@type": "org.noear.solon.ai.chat.ChatConfig"
provider: "ollama"
model: "qwen2.5:1.5b"
apiUrl: "http://127.0.0.1:11434/api/chat"
- task: "@ConsoleOutput"
2、solon 集成方式
在应用属性 app.yml
添加 solon-flow 配置内容(可以自动完成加载):
solon.flow:
- classpath:flow/*.yml
启动应用,并添加测试代码
import org.noear.solon.Solon;
import org.noear.solon.annotation.*;
import org.noear.solon.flow.FlowEngine;
@Component
public class DemoApp {
public static void main(String[] args) {
Solon.start(DemoApp.class, args);
}
@Inject
FlowEngine flowEngine;
@Init
public void test() {
flowEngine.eval("helloworld");
}
}
3、java 原生集成方式
public class DemoApp {
public static void main(String[] args) {
FlowEngine flowEngine = FlowEngine.newInstance();
flowEngine.load("classpath:flow/*.yml");
flowEngine.eval("helloworld");
}
}