feat(ai): 完成基础版本功能
This commit is contained in:
102
service-ai/bin/.gitignore
vendored
Normal file
102
service-ai/bin/.gitignore
vendored
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/*.code-snippets
|
||||||
|
.history/
|
||||||
|
*.vsix
|
||||||
|
*~
|
||||||
|
.fuse_hidden*
|
||||||
|
.directory
|
||||||
|
.Trash-*
|
||||||
|
.nfs*
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
lib-cov
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
.nyc_output
|
||||||
|
.grunt
|
||||||
|
bower_components
|
||||||
|
.lock-wscript
|
||||||
|
build/Release
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
web_modules/
|
||||||
|
*.tsbuildinfo
|
||||||
|
.npm
|
||||||
|
.eslintcache
|
||||||
|
.stylelintcache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
.node_repl_history
|
||||||
|
*.tgz
|
||||||
|
.yarn-integrity
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
.cache/
|
||||||
|
.vuepress/dist
|
||||||
|
.temp
|
||||||
|
.docusaurus
|
||||||
|
.serverless/
|
||||||
|
.fusebox/
|
||||||
|
.dynamodb/
|
||||||
|
.tern-port
|
||||||
|
.vscode-test
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
*.stackdump
|
||||||
|
[Dd]esktop.ini
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
*.lnk
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
Icon
|
||||||
|
._*
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
14
service-ai/bin/build-ai-chat.js
Normal file
14
service-ai/bin/build-ai-chat.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import {cd, path} from 'zx'
|
||||||
|
import {trim} from "licia";
|
||||||
|
import {run_deploy, run_package, run_upload} from '../../bin/library.js'
|
||||||
|
|
||||||
|
// 切换目录
|
||||||
|
cd(trim(path.dirname(import.meta.dirname)))
|
||||||
|
// 执行流程
|
||||||
|
try {
|
||||||
|
await run_deploy('service-ai-core')
|
||||||
|
await run_package('service-ai-chat')
|
||||||
|
await run_upload('service-ai-chat')
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
root_path=$(dirname $(cd $(dirname $0);pwd))
|
|
||||||
source $(realpath $root_path/..)/bin/library.sh
|
|
||||||
deploy service-ai-core
|
|
||||||
package service-ai-chat
|
|
||||||
upload $root_path/service-ai-chat/target/service-ai-chat-1.0.0-SNAPSHOT.jar
|
|
||||||
0
service-ai/bin/test.js
Normal file
0
service-ai/bin/test.js
Normal file
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
<spring-boot.version>3.4.3</spring-boot.version>
|
<spring-boot.version>3.4.3</spring-boot.version>
|
||||||
<spring-cloud.version>2024.0.1</spring-cloud.version>
|
<spring-cloud.version>2024.0.1</spring-cloud.version>
|
||||||
<spring-ai.version>1.0.0-M6</spring-ai.version>
|
<spring-ai.version>1.0.0-RC1</spring-ai.version>
|
||||||
<eclipse-collections.version>11.1.0</eclipse-collections.version>
|
<eclipse-collections.version>11.1.0</eclipse-collections.version>
|
||||||
<curator.version>5.1.0</curator.version>
|
<curator.version>5.1.0</curator.version>
|
||||||
<hutool.version>5.8.27</hutool.version>
|
<hutool.version>5.8.27</hutool.version>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
|
<artifactId>spring-ai-starter-model-openai</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -32,13 +32,19 @@ public class ChatController {
|
|||||||
private final ChatClient chatClient;
|
private final ChatClient chatClient;
|
||||||
|
|
||||||
public ChatController(ChatClient.Builder builder) {
|
public ChatController(ChatClient.Builder builder) {
|
||||||
this.chatClient = builder
|
this.chatClient = builder.build();
|
||||||
.defaultSystem("始终在中文语境下进行对话")
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChatClient.ChatClientRequestSpec buildRequest(ImmutableList<MessageVO> messages) {
|
private ChatClient.ChatClientRequestSpec buildRequest(ImmutableList<MessageVO> messages) {
|
||||||
return chatClient.prompt()
|
return chatClient.prompt()
|
||||||
|
.system("""
|
||||||
|
你是一名专业的AI运维助手,负责“Hudi数据同步服务平台”的运维工作;
|
||||||
|
你将会友好地帮助用户解答关于该平台运维工作的问题,你会尽可能通过各种方式获取知识和数据来解答;
|
||||||
|
对于无法通过已有知识回答的问题,你会提示用户你无法解答该问题,而不是虚构不存在的数据或答案;
|
||||||
|
对于与该平台无关的问题,你会委婉地拒绝用户,并提示无法回答;
|
||||||
|
你将始终在中文语境下进行对话。
|
||||||
|
""")
|
||||||
|
.tools(new DatetimeTools())
|
||||||
.messages(
|
.messages(
|
||||||
messages
|
messages
|
||||||
.collect(message -> StrUtil.equals(message.getRole(), "assistant")
|
.collect(message -> StrUtil.equals(message.getRole(), "assistant")
|
||||||
@@ -52,9 +58,10 @@ public class ChatController {
|
|||||||
@PostMapping("sync")
|
@PostMapping("sync")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String chatSync(@RequestBody ImmutableList<MessageVO> messages) {
|
public String chatSync(@RequestBody ImmutableList<MessageVO> messages) {
|
||||||
return buildRequest(messages)
|
String content = buildRequest(messages)
|
||||||
.call()
|
.call()
|
||||||
.content();
|
.content();
|
||||||
|
return StrUtil.trimToEmpty(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("async")
|
@PostMapping("async")
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import org.springframework.ai.tool.annotation.Tool;
|
|||||||
public class DatetimeTools {
|
public class DatetimeTools {
|
||||||
private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
@Tool(description = "获取当前时间")
|
@Tool(description = "获取当前日期和时间")
|
||||||
public String getCurrentTime() {
|
public String getCurrentDateTime() {
|
||||||
return LocalDateTime.now().format(formatter);
|
return LocalDateTime.now().format(formatter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: service-ai-chat
|
name: service-ai-chat
|
||||||
profiles:
|
profiles:
|
||||||
include: random-port,common,metrics,forest
|
include: random-port,common,discovery,metrics,forest
|
||||||
ai:
|
ai:
|
||||||
openai:
|
openai:
|
||||||
base-url: http://132.121.206.65:10086
|
base-url: http://132.121.206.65:10086
|
||||||
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
|
api-key: ENC(K+Hff9QGC+fcyi510VIDd9CaeK/IN5WBJ9rlkUsHEdDgIidW+stHHJlsK0lLPUXXREha+ToQZqqDXJrqSE+GUKCXklFhelD8bRHFXBIeP/ZzT2cxhzgKUXgjw3S0Qw2R)
|
||||||
chat:
|
chat:
|
||||||
options:
|
options:
|
||||||
model: 'Qwen3-1.7'
|
model: 'Qwen3-1.7-vllm'
|
||||||
mvc:
|
mvc:
|
||||||
async:
|
async:
|
||||||
request-timeout: 300000
|
request-timeout: 300000
|
||||||
|
|||||||
@@ -29,6 +29,6 @@
|
|||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="Console"/>
|
<appender-ref ref="Console"/>
|
||||||
<!-- <appender-ref ref="RollingFile"/>-->
|
<appender-ref ref="RollingFile"/>
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -44,5 +44,11 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.core.configuration;
|
||||||
|
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.http.client.JdkClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||||
|
import org.springframework.web.client.RestClient;
|
||||||
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vLLM只能使用http1.0
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250519
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class WebClientConfiguration {
|
||||||
|
private HttpClient httpClient() {
|
||||||
|
return HttpClient.newBuilder()
|
||||||
|
.version(HttpClient.Version.HTTP_1_1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public RestClient.Builder restClientBuilder() {
|
||||||
|
return RestClient.builder()
|
||||||
|
.requestFactory(new JdkClientHttpRequestFactory(httpClient()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public WebClient.Builder webClientBuilder() {
|
||||||
|
return WebClient.builder()
|
||||||
|
.clientConnector(new JdkClientHttpConnector(httpClient()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,11 +24,11 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
|
<artifactId>spring-ai-starter-model-openai</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
<artifactId>spring-ai-qdrant-store-spring-boot-starter</artifactId>
|
<artifactId>spring-ai-qdrant-store</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
|
|||||||
Reference in New Issue
Block a user