feat:init
This commit is contained in:
28
xservice-server/pom.xml
Normal file
28
xservice-server/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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>com.xiang</groupId>
|
||||
<artifactId>xservice-ai-center</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>xservice-server</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xiang</groupId>
|
||||
<artifactId>xservice-service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.xiang;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
@SpringBootApplication
|
||||
public class XserviceAIApplication {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(XserviceAIApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
log.info("======> xservice stock center application 启动准备 <======");
|
||||
ConfigurableApplicationContext context = SpringApplication.run(XserviceAIApplication.class, args);
|
||||
Environment environment = context.getBean(Environment.class);
|
||||
log.info("启动环境配置:{}, 启动端口配置:{}", environment.getProperty("spring.profiles.active"), environment.getProperty("server.port"));
|
||||
log.info("======> xservice ai center application 启动完成 <======");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.xiang.xsa.xservice.ai.server;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
||||
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
|
||||
import org.springframework.ai.chat.memory.ChatMemory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class ChatController {
|
||||
|
||||
private final ChatClient chatClient;
|
||||
private final ChatMemory chatMemory;
|
||||
|
||||
@PostMapping("/chat")
|
||||
public String chatDemo(@RequestParam("question") String question) {
|
||||
return chatClient.prompt(question).call().content();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/chatWithFlux")
|
||||
public Flux<String> chatWithFlux(@RequestParam("question") String question) {
|
||||
return chatClient.prompt(question).stream().content();
|
||||
}
|
||||
|
||||
@PostMapping("/chatWithConversionId")
|
||||
public String chatWithConversionId(@RequestParam("sessionId") String sessionId, @RequestParam("question") String question) {
|
||||
|
||||
return chatClient.prompt()
|
||||
.user(question)
|
||||
.advisors(
|
||||
MessageChatMemoryAdvisor.builder(chatMemory).conversationId(sessionId).build(), new SimpleLoggerAdvisor()
|
||||
)
|
||||
.call().content();
|
||||
}
|
||||
}
|
||||
22
xservice-server/src/main/resources/application.yml
Normal file
22
xservice-server/src/main/resources/application.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
spring:
|
||||
ai:
|
||||
dashscope:
|
||||
api-key: sk-07353fd191074c9c930b134230ba88ea
|
||||
application:
|
||||
name: xservice-ai-center
|
||||
profiles:
|
||||
active: local
|
||||
datasource:
|
||||
url: jdbc:mysql://rm-bp15t34gqx62jm069ro.mysql.rds.aliyuncs.com:3306/xservice-ai-center?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||
username: root
|
||||
password: xb#UWqnhH24&XpX
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
server:
|
||||
port: 38020
|
||||
# 返回结果UTF-8格式编码
|
||||
servlet:
|
||||
encoding:
|
||||
charset: UTF-8
|
||||
enabled: true
|
||||
force: true
|
||||
|
||||
Reference in New Issue
Block a user