-
Notifications
You must be signed in to change notification settings - Fork 332
feat(FEL): 提供 Spring 框架启动支持 #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CodeCasterX
merged 12 commits into
ModelEngine-Group:3.6.x
from
relat-ivity:fel-decoupling
Feb 5, 2026
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b9826f8
fel-flow说明文档
relat-ivity 96bc826
响应式流实现java的publisher接口
relat-ivity 4f95926
FelSpringBootAutoConfiguration集成
relat-ivity 657b748
依赖更新
relat-ivity fa5c554
choir替换java的publisher实现
relat-ivity c01c431
添加jdk的publisher测试
relat-ivity 7e89b74
添加示例与文档
relat-ivity cf947e1
模块名称修正
relat-ivity 8c568ac
修改匿名类
relat-ivity a182df8
重构fel-starter
relat-ivity 7fa74fe
fel-spring-example注释完善
relat-ivity b7217a0
fel-spring-example修改注释
relat-ivity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name: PR Title Check | ||
|
|
||
| on: | ||
| pull_request: | ||
| pull_request_target: | ||
| types: [opened, edited, synchronize] | ||
|
|
||
| permissions: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.fitframework.example</groupId> | ||
| <artifactId>fel-spring-example-parent</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>chat-model-spring-example</artifactId> | ||
|
|
||
| <dependencies> | ||
| <!-- FEL Spring Boot Starter --> | ||
| <dependency> | ||
| <groupId>org.fitframework.fel</groupId> | ||
| <artifactId>fel-spring-boot-starter</artifactId> | ||
| <version>${fel.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- Spring Boot Web --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- WebFlux:流式响应需要 --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-webflux</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
70 changes: 70 additions & 0 deletions
70
.../01-model/src/main/java/modelengine/example/ai/chat/model/ChatModelExampleController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.example.ai.chat.model; | ||
|
|
||
| import modelengine.fel.core.chat.ChatMessage; | ||
| import modelengine.fel.core.chat.ChatModel; | ||
| import modelengine.fel.core.chat.ChatOption; | ||
| import modelengine.fel.core.chat.support.ChatMessages; | ||
| import modelengine.fel.core.chat.support.HumanMessage; | ||
| import modelengine.fitframework.flowable.Choir; | ||
| import reactor.adapter.JdkFlowAdapter; | ||
| import reactor.core.publisher.Flux; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * 聊天模型样例控制器(Spring Boot 版本)。 | ||
| * | ||
| * @author 黄可欣 | ||
| * @since 2025-01-20 | ||
| */ | ||
| @RestController | ||
| @RequestMapping("/ai/example") | ||
| @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") | ||
| public class ChatModelExampleController { | ||
| private final ChatModel chatModel; | ||
| @Value("${example.model}") | ||
| private String modelName; | ||
|
|
||
| public ChatModelExampleController(ChatModel chatModel) { | ||
| this.chatModel = chatModel; | ||
| } | ||
|
|
||
| /** | ||
| * 聊天接口。 | ||
| * | ||
| * @param query 表示用户输入查询的 {@link String}。 | ||
| * @return 表示聊天模型生成的回复的 Map。 | ||
| */ | ||
| @GetMapping("/chat") | ||
| public Object chat(@RequestParam("query") String query) { | ||
| ChatOption option = ChatOption.custom().model(this.modelName).stream(false).build(); | ||
| ChatMessage aiMessage = | ||
| this.chatModel.generate(ChatMessages.from(new HumanMessage(query)), option).first().block().get(); | ||
| return java.util.Map.of("content", aiMessage.text(), "toolCalls", aiMessage.toolCalls()); | ||
| } | ||
|
|
||
| /** | ||
| * 流式聊天接口。 | ||
| * | ||
| * @param query 表示用户输入查询的 {@link String}。 | ||
| * @return 表示聊天模型生成的流式回复的 Choir。 | ||
| */ | ||
| @GetMapping(value = "/chat-stream", produces = "text/event-stream;charset=UTF-8") | ||
| public Flux<Map<String, Object>> chatStream(@RequestParam("query") String query) { | ||
| ChatOption option = ChatOption.custom().model(this.modelName).stream(true).build(); | ||
| Choir<ChatMessage> choir = this.chatModel.generate(ChatMessages.from(new HumanMessage(query)), option); | ||
| return JdkFlowAdapter.flowPublisherToFlux(choir.map(chatMessage -> Map.of("content", chatMessage.text()))); | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
...ing-example/01-model/src/main/java/modelengine/example/ai/chat/model/DemoApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.example.ai.chat.model; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| /** | ||
| * 启动程序(Spring Boot 版本)。 | ||
| * | ||
| * @author 黄可欣 | ||
| * @since 2025-01-20 | ||
| */ | ||
| @SpringBootApplication | ||
| public class DemoApplication { | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(DemoApplication.class, args); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
examples/fel-spring-example/01-model/src/main/resources/application.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| spring: | ||
| application: | ||
| name: chat-model-example | ||
|
|
||
| fel: | ||
| openai: | ||
| api-base:'${api-base}' | ||
| api-key:'${your-api-key}' | ||
| example: | ||
| model:'${model-name}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.fitframework.example</groupId> | ||
| <artifactId>fel-spring-example-parent</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>chat-template-spring-example</artifactId> | ||
|
|
||
| <dependencies> | ||
| <!-- FEL Spring Boot Starter --> | ||
| <dependency> | ||
| <groupId>org.fitframework.fel</groupId> | ||
| <artifactId>fel-spring-boot-starter</artifactId> | ||
| <version>${fel.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- Spring Boot Web --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
60 changes: 60 additions & 0 deletions
60
...ate/src/main/java/modelengine/example/ai/chat/template/ChatTemplateExampleController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.example.ai.chat.template; | ||
|
|
||
| import modelengine.fel.core.chat.ChatMessage; | ||
| import modelengine.fel.core.chat.ChatModel; | ||
| import modelengine.fel.core.chat.ChatOption; | ||
| import modelengine.fel.core.chat.support.ChatMessages; | ||
| import modelengine.fel.core.template.MessageTemplate; | ||
| import modelengine.fel.core.template.support.HumanMessageTemplate; | ||
| import modelengine.fel.core.util.Tip; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| /** | ||
| * 聊天模板样例控制器(Spring Boot 版本)。 | ||
| * | ||
| * @author 黄可欣 | ||
| * @since 2025-01-20 | ||
| */ | ||
| @RestController | ||
| @RequestMapping("/ai/example") | ||
| @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") | ||
| public class ChatTemplateExampleController { | ||
| private final ChatModel chatModel; | ||
| private final MessageTemplate template; | ||
| @Value("${example.model}") | ||
| private String modelName; | ||
|
|
||
| public ChatTemplateExampleController(ChatModel chatModel) { | ||
| this.chatModel = chatModel; | ||
| this.template = new HumanMessageTemplate("给我讲个关于{{adjective}}的{{content}}。"); | ||
| } | ||
|
|
||
| /** | ||
| * 聊天接口。 | ||
| * | ||
| * @param adjective 表示主题的 {@link String}。 | ||
| * @param content 表示内容的 {@link String}。 | ||
| * @return 表示聊天模型生成的回复的 Map。 | ||
| */ | ||
| @GetMapping("/chat") | ||
| public Object chat(@RequestParam("adjective") String adjective, @RequestParam("content") String content) { | ||
| ChatOption option = ChatOption.custom().model(this.modelName).stream(false).build(); | ||
| ChatMessage aiMessage = this.chatModel.generate(ChatMessages.from(this.template.render(Tip.from("adjective", adjective) | ||
| .add("content", content) | ||
| .freeze())), option).first().block().get(); | ||
| return java.util.Map.of( | ||
| "content", aiMessage.text(), | ||
| "toolCalls", aiMessage.toolCalls() | ||
| ); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...ample/02-template/src/main/java/modelengine/example/ai/chat/template/DemoApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.example.ai.chat.template; | ||
|
|
||
| import modelengine.fitframework.starter.spring.annotation.EnableFitProxy; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| /** | ||
| * 启动程序(Spring Boot 版本)。 | ||
| * | ||
| * @author 黄可欣 | ||
| * @since 2025-01-20 | ||
| */ | ||
| @SpringBootApplication | ||
| public class DemoApplication { | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(DemoApplication.class, args); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
examples/fel-spring-example/02-template/src/main/resources/application.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| spring: | ||
| application: | ||
| name: chat-template-example | ||
| fel: | ||
| openai: | ||
| api-base:'${api-base}' | ||
| api-key:'${your-api-key}' | ||
| example: | ||
| model:'${model-name}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.fitframework.example</groupId> | ||
| <artifactId>fel-spring-example-parent</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>chat-memory-spring-example</artifactId> | ||
|
|
||
| <dependencies> | ||
| <!-- FEL Spring Boot Starter --> | ||
| <dependency> | ||
| <groupId>org.fitframework.fel</groupId> | ||
| <artifactId>fel-spring-boot-starter</artifactId> | ||
| <version>${fel.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- Spring Boot Web --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
59 changes: 59 additions & 0 deletions
59
...-memory/src/main/java/modelengine/example/ai/chat/memory/ChatMemoryExampleController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.example.ai.chat.memory; | ||
|
|
||
| import modelengine.fel.core.chat.ChatMessage; | ||
| import modelengine.fel.core.chat.ChatModel; | ||
| import modelengine.fel.core.chat.ChatOption; | ||
| import modelengine.fel.core.chat.support.ChatMessages; | ||
| import modelengine.fel.core.chat.support.HumanMessage; | ||
| import modelengine.fel.core.memory.Memory; | ||
| import modelengine.fel.core.memory.support.CacheMemory; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| /** | ||
| * 聊天记忆样例控制器(Spring Boot 版本)。 | ||
| * | ||
| * @author 黄可欣 | ||
| * @since 2025-01-20 | ||
| */ | ||
| @RestController | ||
| @RequestMapping("/ai/example") | ||
| @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") | ||
| public class ChatMemoryExampleController { | ||
| private final ChatModel chatModel; | ||
| private final Memory memory = new CacheMemory(); | ||
| @Value("${example.model}") | ||
| private String modelName; | ||
|
|
||
| public ChatMemoryExampleController(ChatModel chatModel) { | ||
| this.chatModel = chatModel; | ||
| } | ||
|
|
||
| /** | ||
| * 聊天接口。 | ||
| * | ||
| * @param query 表示用户输入查询的 {@link String}。 | ||
| * @return 表示聊天模型生成的回复的 Map。 | ||
| */ | ||
| @GetMapping("/chat") | ||
| public Object chat(@RequestParam("query") String query) { | ||
| ChatOption option = ChatOption.custom().model(this.modelName).stream(false).build(); | ||
| this.memory.add(new HumanMessage(query)); | ||
| ChatMessage aiMessage = | ||
| this.chatModel.generate(ChatMessages.from(this.memory.messages()), option).first().block().get(); | ||
| this.memory.add(aiMessage); | ||
| return java.util.Map.of( | ||
| "content", aiMessage.text(), | ||
| "toolCalls", aiMessage.toolCalls() | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.