Merge remote-tracking branch 'origin/dev_1.0.0' into dev_1.0.0
# Conflicts: # know_sub_business/pom.xml # know_sub_rag/src/main/java/com/supervision/knowsub/config/ElasticsearchVectorStoreConfig.java # pom.xmldev_1.0.0
commit
a9348831f7
@ -0,0 +1 @@
|
||||
-- 新增RAG搜索的SQL
|
@ -0,0 +1,154 @@
|
||||
<?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.supervision</groupId>
|
||||
<artifactId>know_sub</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>know_sub_etl</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>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-tika-document-reader</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>io.springboot.ai</groupId>-->
|
||||
<!-- <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-elasticsearch-store</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.supervision</groupId>
|
||||
<artifactId>know_sub_common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.supervision</groupId>
|
||||
<artifactId>know_sub_model</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<name>aliyun central repo</name>
|
||||
<url>https://maven.aliyun.com/nexus/content/repositories/central/</url>
|
||||
<layout>default</layout>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>daily</updatePolicy>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
<updatePolicy>never</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<parameters>true</parameters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,18 @@
|
||||
package som.supervision.knowsub;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@MapperScan(basePackages = {"com.supervision.**.mapper"})
|
||||
@EnableConfigurationProperties
|
||||
public class KnowSubEtlApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(KnowSubEtlApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package som.supervision.knowsub.config;
|
||||
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.springframework.ai.embedding.EmbeddingModel;
|
||||
import org.springframework.ai.vectorstore.ElasticsearchVectorStore;
|
||||
import org.springframework.ai.vectorstore.ElasticsearchVectorStoreOptions;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(EmbeddingProperties.class)
|
||||
public class ElasticsearchVectorStoreConfig {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "embedding", name = "url")
|
||||
public EmbeddingModel embeddingModel(EmbeddingProperties embeddingProperties) {
|
||||
Assert.notNull(embeddingProperties.getUrl(), "配置文件embedding:url未找到");
|
||||
return new VectorEmbeddingModel(embeddingProperties.getUrl());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "embedding", name = "url")
|
||||
public ElasticsearchVectorStore vectorStore(EmbeddingModel embeddingModel, RestClient restClient) {
|
||||
ElasticsearchVectorStoreOptions options = new ElasticsearchVectorStoreOptions();
|
||||
options.setIndexName("know-sub-rag-store");
|
||||
options.setDimensions(1024);
|
||||
return new ElasticsearchVectorStore(options, restClient, embeddingModel, true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package som.supervision.knowsub.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "embedding")
|
||||
public class EmbeddingProperties {
|
||||
|
||||
private String url;
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package som.supervision.knowsub.config;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.embedding.*;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Slf4j
|
||||
public class VectorEmbeddingModel implements EmbeddingModel {
|
||||
|
||||
private final String embeddingUrl;
|
||||
|
||||
public VectorEmbeddingModel(String embeddingUrl) {
|
||||
this.embeddingUrl = embeddingUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Double> embed(Document document) {
|
||||
List<List<Double>> list = this.call(new EmbeddingRequest(List.of(document.getContent()), EmbeddingOptions.EMPTY))
|
||||
.getResults()
|
||||
.stream()
|
||||
.map(Embedding::getOutput)
|
||||
.toList();
|
||||
return list.iterator().next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddingResponse call(EmbeddingRequest request) {
|
||||
Assert.notEmpty(request.getInstructions(), "At least one text is required!");
|
||||
List<List<Double>> embeddingList = new ArrayList<>();
|
||||
|
||||
for (String inputContent : request.getInstructions()) {
|
||||
// 这里需要吧inputContent转化为向量数据
|
||||
String post = HttpUtil.post(embeddingUrl, JSONUtil.toJsonStr(Map.of("text", inputContent)));
|
||||
EmbeddingData bean = JSONUtil.toBean(post, EmbeddingData.class);
|
||||
embeddingList.add(bean.embeddings);
|
||||
}
|
||||
var indexCounter = new AtomicInteger(0);
|
||||
List<Embedding> embeddings = embeddingList.stream()
|
||||
.map(e -> new Embedding(e, indexCounter.getAndIncrement()))
|
||||
.toList();
|
||||
return new EmbeddingResponse(embeddings);
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class EmbeddingData {
|
||||
private List<Double> embeddings;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package som.supervision.knowsub.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import som.supervision.knowsub.service.KnowledgeEtlService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Tag(name = "知识ETL类")
|
||||
@RestController
|
||||
@RequestMapping("etl")
|
||||
@RequiredArgsConstructor
|
||||
public class KnowledgeEtlController {
|
||||
|
||||
private final KnowledgeEtlService knowledgeEtlService;
|
||||
|
||||
@Operation(summary = "对知识进行ETL")
|
||||
@PostMapping("knowledgeEtl")
|
||||
public void knowledgeEtl(@RequestParam("files") MultipartFile[] files) {
|
||||
knowledgeEtlService.knowledgeEtl(files);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package som.supervision.knowsub.service;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface KnowledgeEtlService {
|
||||
|
||||
void knowledgeEtl(MultipartFile[] files);
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package som.supervision.knowsub.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.reader.tika.TikaDocumentReader;
|
||||
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
|
||||
import org.springframework.ai.vectorstore.ElasticsearchVectorStore;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import som.supervision.knowsub.service.KnowledgeEtlService;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KnowledgeEtlServiceImpl implements KnowledgeEtlService {
|
||||
|
||||
private final ElasticsearchVectorStore elasticsearchVectorStore;
|
||||
|
||||
/**
|
||||
* 参考文档 <a href="https://zhuanlan.zhihu.com/p/703705663"/>
|
||||
*
|
||||
* @param inputStream 输入流
|
||||
*/
|
||||
private void loadFile(InputStream inputStream, String fileName) {
|
||||
// 首先使用tika进行文件切分操作
|
||||
log.info("{} 进行内容切分", fileName);
|
||||
TikaDocumentReader tikaDocumentReader = new TikaDocumentReader(new InputStreamResource(inputStream));
|
||||
List<Document> documents = tikaDocumentReader.read();
|
||||
log.info("{} 切分完成,开始进行chunk分割", fileName);
|
||||
// 然后切分为chunk
|
||||
TokenTextSplitter tokenTextSplitter = new TokenTextSplitter(500, 250, 10, 1000, true);
|
||||
List<Document> apply = tokenTextSplitter.apply(documents);
|
||||
for (Document document : apply) {
|
||||
document.getMetadata().put("fileName", fileName);
|
||||
}
|
||||
log.info("{} 切分完成,开始进行保存到向量库中", fileName);
|
||||
// 保存到向量数据库中
|
||||
elasticsearchVectorStore.accept(apply);
|
||||
log.info("{} 保存完成", fileName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void knowledgeEtl(MultipartFile[] files) {
|
||||
AtomicInteger atomicInteger = new AtomicInteger(1);
|
||||
for (MultipartFile file : files) {
|
||||
try {
|
||||
loadFile(file.getInputStream(), file.getOriginalFilename());
|
||||
} catch (Exception e) {
|
||||
log.error("{}文件处理失败", file.getOriginalFilename(), e);
|
||||
}
|
||||
int andIncrement = atomicInteger.getAndIncrement();
|
||||
log.info("处理第{}个文件,剩余:{}个", andIncrement, files.length - andIncrement + 1);
|
||||
|
||||
}
|
||||
log.info("文件处理结束");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.supervision.knowsub;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@MapperScan(basePackages = {"com.supervision.**.mapper"})
|
||||
@EnableConfigurationProperties
|
||||
public class KnowSubRagApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(KnowSubRagApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.supervision.knowsub.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.vectorstore.ElasticsearchVectorStore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("esTest")
|
||||
public class EsTestController {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchVectorStore elasticsearchVectorStore;
|
||||
|
||||
@GetMapping("add")
|
||||
public void add() {
|
||||
Document document = new Document("测试测试");
|
||||
elasticsearchVectorStore.add(List.of(document));
|
||||
}
|
||||
|
||||
@GetMapping("search")
|
||||
public void search(String question) {
|
||||
List<Document> result = elasticsearchVectorStore.similaritySearch(question);
|
||||
for (Document document : result) {
|
||||
System.out.println(document.getContent());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.supervision.knowsub.controller;
|
||||
|
||||
import com.supervision.knowsub.service.RagService;
|
||||
import com.supervision.knowsub.vo.RagResVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "RAG问答")
|
||||
@RestController
|
||||
@RequestMapping("rag")
|
||||
@RequiredArgsConstructor
|
||||
public class RagController {
|
||||
|
||||
private final RagService ragService;
|
||||
|
||||
@Operation(summary = "问答")
|
||||
@GetMapping("esAsk")
|
||||
public RagResVO esAsk(String question) {
|
||||
return ragService.esAsk(question);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.supervision.knowsub.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.supervision.knowsub.service.RagService;
|
||||
import com.supervision.knowsub.vo.RagResVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("test")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class TestController {
|
||||
|
||||
private final RagService ragService;
|
||||
|
||||
@GetMapping("esTest")
|
||||
public void esTest(){
|
||||
ExcelReader reader = ExcelUtil.getReader("/Users/flevance/Desktop/深圳人社POC/question.xlsx","Sheet2");
|
||||
List<Object> objects = reader.readColumn(3, 1);
|
||||
ExcelWriter writer = reader.getWriter();
|
||||
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
RagResVO ask = ragService.esAsk(objects.get(i).toString());
|
||||
|
||||
writer.writeCellValue(5, i + 1, ask.getAnswer());
|
||||
writer.writeCellValue(6, i + 1, JSONUtil.toJsonStr(ask.getFileName()));
|
||||
log.info("第{}条数据写入成功,剩余{}条", i + 1, objects.size() - i - 1);
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.supervision.knowsub.service;
|
||||
|
||||
import com.supervision.knowsub.vo.RagResVO;
|
||||
|
||||
public interface RagService {
|
||||
|
||||
RagResVO esAsk(String question);
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.supervision.knowsub.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class AiChatUtil {
|
||||
|
||||
// private static final ExecutorService chatExecutor = ThreadUtil.newFixedExecutor(5, 5, "chat", new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//
|
||||
// private static final OllamaChatClient chatClient = SpringBeanUtil.getBean(OllamaChatClient.class);
|
||||
//
|
||||
// /**
|
||||
// * 单轮对话
|
||||
// *
|
||||
// * @param chat 对话的内容
|
||||
// * @return jsonObject
|
||||
// */
|
||||
// public static Optional<JSONObject> chat(String chat) {
|
||||
// Prompt prompt = new Prompt(List.of(new UserMessage(chat)));
|
||||
// Future<String> submit = chatExecutor.submit(new ChatTask(chatClient, prompt));
|
||||
// try {
|
||||
// return Optional.of(JSONUtil.parseObj(submit.get()));
|
||||
// } catch (ExecutionException | InterruptedException e) {
|
||||
// log.error("调用大模型生成失败");
|
||||
// }
|
||||
// return Optional.empty();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 支持多轮对话,自定义消息
|
||||
// *
|
||||
// * @param messageList 消息列表
|
||||
// * @return jsonObject
|
||||
// */
|
||||
// public static Optional<JSONObject> chat(List<Message> messageList) {
|
||||
// Prompt prompt = new Prompt(messageList);
|
||||
// Future<String> submit = chatExecutor.submit(new ChatTask(chatClient, prompt));
|
||||
// try {
|
||||
// return Optional.of(JSONUtil.parseObj(submit.get()));
|
||||
// } catch (ExecutionException | InterruptedException e) {
|
||||
// log.error("调用大模型生成失败");
|
||||
// }
|
||||
// return Optional.empty();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 支持序列化的方式
|
||||
// *
|
||||
// * @param messageList 消息列表
|
||||
// * @param clazz 需要序列化的对象
|
||||
// * @param <T> 需要序列化的对象的泛型
|
||||
// * @return 对应对象类型, 不支持列表类型
|
||||
// */
|
||||
// public static <T> Optional<T> chat(List<Message> messageList, Class<T> clazz) {
|
||||
// Prompt prompt = new Prompt(messageList);
|
||||
// Future<String> submit = chatExecutor.submit(new ChatTask(chatClient, prompt));
|
||||
// try {
|
||||
// String s = submit.get();
|
||||
// return Optional.ofNullable(JSONUtil.toBean(s, clazz));
|
||||
// } catch (ExecutionException | InterruptedException e) {
|
||||
// log.error("调用大模型生成失败", e);
|
||||
// }
|
||||
// return Optional.empty();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 支持序列化的方式的对话
|
||||
// *
|
||||
// * @param chat 对话的消息
|
||||
// * @param clazz 需要序列化的对象
|
||||
// * @param <T> 需要序列化的对象的泛型
|
||||
// * @return 对应对象类型, 不支持列表类型
|
||||
// */
|
||||
// public static <T> Optional<T> chat(String chat, Class<T> clazz) {
|
||||
// Prompt prompt = new Prompt(List.of(new UserMessage(chat)));
|
||||
// Future<String> submit = chatExecutor.submit(new ChatTask(chatClient, prompt));
|
||||
// try {
|
||||
// String s = submit.get();
|
||||
// return Optional.ofNullable(JSONUtil.toBean(s, clazz));
|
||||
// } catch (ExecutionException | InterruptedException e) {
|
||||
// log.error("调用大模型生成失败");
|
||||
// }
|
||||
// return Optional.empty();
|
||||
// }
|
||||
//
|
||||
// private record ChatTask(OllamaChatClient chatClient, Prompt prompt) implements Callable<String> {
|
||||
// @Override
|
||||
// public String call() {
|
||||
// ChatResponse call = chatClient.call(prompt);
|
||||
// return call.getResult().getOutput().getContent();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.supervision.knowsub.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class RagResVO {
|
||||
|
||||
private String answer;
|
||||
|
||||
private Set<String> fileName;
|
||||
}
|
Loading…
Reference in New Issue