初始化代码
commit
b8418fc60c
@ -0,0 +1,34 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
/log/
|
@ -0,0 +1,93 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.supervision</groupId>
|
||||
<artifactId>pdf-qa-server</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>pdf-qa-server</name>
|
||||
<description>pdf-qa-server</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-ai.version>1.0.0-M7</spring-ai.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-starter-model-ollama</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.26</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-bom</artifactId>
|
||||
<version>${spring-ai.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!--<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,14 @@
|
||||
package com.supervision.pdfqaserver;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
public class PdfQaServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PdfQaServerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.supervision.pdfqaserver.controller;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.supervision.pdfqaserver.dto.R;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.chat.messages.Message;
|
||||
import org.springframework.ai.chat.messages.SystemMessage;
|
||||
import org.springframework.ai.chat.messages.UserMessage;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ollama")
|
||||
@RequiredArgsConstructor
|
||||
@CrossOrigin(origins = "*", maxAge = 3600)
|
||||
public class ChatController {
|
||||
|
||||
private final OllamaChatModel ollamaChatModel;
|
||||
|
||||
@PostMapping("/chat")
|
||||
public R<String> pageList(@RequestBody Map<String,String> message) {
|
||||
List<Message> messages = new ArrayList<>();
|
||||
if (StrUtil.isNotEmpty(message.get("system"))){
|
||||
messages.add(new SystemMessage(message.get("system")));
|
||||
}
|
||||
if (StrUtil.isNotEmpty(message.get("user"))){
|
||||
messages.add(new UserMessage(message.get("user")));
|
||||
}
|
||||
log.info("system: {} , user: {}",message.get("system"),message.get("user"));
|
||||
Assert.notEmpty(messages, "消息不能为空");
|
||||
String response = ollamaChatModel.call(messages.toArray(new Message[0]));
|
||||
log.info("response:{}",response);
|
||||
return R.ok(response);
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
package com.supervision.pdfqaserver.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 响应信息主体
|
||||
*
|
||||
* @author qimaoyu
|
||||
*/
|
||||
@Data
|
||||
public class R<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String TOTAL_COUNT = "total";
|
||||
public static final String RESULT_LIST = "result";
|
||||
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
public static final int SUCCESS = 200;
|
||||
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
public static final int FAIL = 500;
|
||||
|
||||
private int code;
|
||||
|
||||
private String msg;
|
||||
|
||||
private T data;
|
||||
|
||||
public static <T> R<T> ok() {
|
||||
return restResult(null, SUCCESS, null);
|
||||
}
|
||||
|
||||
public static <T> R<T> judgeResult(Boolean bo, String successMessage, String failMessage) {
|
||||
if (bo) {
|
||||
return restResult(null, SUCCESS, successMessage);
|
||||
} else {
|
||||
return restResult(null, FAIL, failMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> R<T> okMsg(String msg) {
|
||||
return restResult(null, SUCCESS, msg);
|
||||
}
|
||||
|
||||
public static <T> R<T> ok(T data) {
|
||||
return restResult(data, SUCCESS, null);
|
||||
}
|
||||
|
||||
public static <T> R<T> ok(T data, String msg) {
|
||||
return restResult(data, SUCCESS, msg);
|
||||
}
|
||||
|
||||
public static <T> R<T> fail() {
|
||||
return restResult(null, FAIL, null);
|
||||
}
|
||||
|
||||
public static <T> R<T> fail(String msg) {
|
||||
return restResult(null, FAIL, msg);
|
||||
}
|
||||
|
||||
public static <T> R<T> fail(T data) {
|
||||
return restResult(data, FAIL, null);
|
||||
}
|
||||
|
||||
public static <T> R<T> fail(int code, String msg) {
|
||||
return restResult(null, code, msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static <T> R<T> restResult(T data, int code, String msg) {
|
||||
R<T> apiResult = new R<>();
|
||||
apiResult.setCode(code);
|
||||
apiResult.setData(data);
|
||||
apiResult.setMsg(msg);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Object> buildDataMap(List list) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
if (list == null) {
|
||||
dataMap.put(TOTAL_COUNT, 0);
|
||||
dataMap.put(RESULT_LIST, new ArrayList<>());
|
||||
} else {
|
||||
dataMap.put(TOTAL_COUNT, list.size());
|
||||
dataMap.put(RESULT_LIST, list);
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public static Map<String, Object> buildDataMap(List list, Long total) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put(TOTAL_COUNT, total);
|
||||
dataMap.put(RESULT_LIST, list);
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public static Map<String, Object> buildDataMap(Set list) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
if (list == null) {
|
||||
dataMap.put(TOTAL_COUNT, 0);
|
||||
dataMap.put(RESULT_LIST, new ArrayList<>());
|
||||
} else {
|
||||
dataMap.put(TOTAL_COUNT, list.size());
|
||||
dataMap.put(RESULT_LIST, list);
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public static Map<String, Object> buildDataMap(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
List<Object> resultList = new ArrayList<>();
|
||||
resultList.add(object);
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put(TOTAL_COUNT, resultList.size());
|
||||
dataMap.put(RESULT_LIST, resultList);
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.supervision.pdfqaserver.service;
|
||||
|
||||
import com.supervision.pdfqaserver.dto.DocumentDTO;
|
||||
import com.supervision.pdfqaserver.dto.TruncateDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文档切分器
|
||||
*/
|
||||
public interface DocumentSlicer {
|
||||
|
||||
/**
|
||||
* 切分文档
|
||||
* @param documents 文档列表
|
||||
* @return
|
||||
*/
|
||||
List<TruncateDTO> slice(List<DocumentDTO> documents);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
spring:
|
||||
application:
|
||||
name: pdf-qa-server
|
||||
ai:
|
||||
ollama:
|
||||
baseUrl: http://192.168.10.70:11434
|
||||
chat:
|
||||
model: qwen2.5:32b
|
||||
options:
|
||||
max_tokens: 512
|
||||
top_p: 0.9
|
||||
top_k: 40
|
||||
temperature: 0.7
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.pdfqaserver;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class PdfQaServerApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue