|
|
|
package org.jeecg.modules.airag.app.controller;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import java.sql.Connection; // PostgreSQL JDBC 连接
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.ResultSetMetaData;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import dev.langchain4j.store.embedding.EmbeddingStore; // LangChain4j 的 EmbeddingStore 接口
|
|
|
|
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
|
|
|
|
import dev.langchain4j.data.embedding.Embedding;
|
|
|
|
import dev.langchain4j.data.segment.TextSegment;
|
|
|
|
import dev.langchain4j.model.embedding.EmbeddingModel;
|
|
|
|
import dev.langchain4j.model.output.Response;
|
|
|
|
import dev.langchain4j.store.embedding.EmbeddingMatch;
|
|
|
|
import dev.langchain4j.store.embedding.EmbeddingSearchRequest;
|
|
|
|
import dev.langchain4j.store.embedding.EmbeddingSearchResult;
|
|
|
|
import dev.langchain4j.store.embedding.EmbeddingStore;
|
|
|
|
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
//import org.jeecg.modules.airag.app.config.PostgreEmbeddingStore;
|
|
|
|
import org.jeecg.modules.airag.app.entity.Embeddings;
|
|
|
|
import org.jeecg.modules.airag.app.entity.Embeddings;
|
|
|
|
import org.jeecg.modules.airag.app.service.IEmbeddingsService;
|
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
|
import org.jeecg.modules.airag.app.utils.AiModelUtils;
|
|
|
|
import org.jeecg.modules.airag.llm.entity.AiragModel;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description: Embeddings
|
|
|
|
* @Author: jeecg-boot
|
|
|
|
* @Date: 2025-05-26
|
|
|
|
* @Version: V1.0
|
|
|
|
*/
|
|
|
|
@Tag(name="Embeddings")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/embeddings/embeddings")
|
|
|
|
@Slf4j
|
|
|
|
public class EmbeddingsController {
|
|
|
|
@Autowired
|
|
|
|
private IEmbeddingsService embeddingsService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private AiModelUtils aiModelUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 分页列表查询
|
|
|
|
*
|
|
|
|
* @param Embeddings
|
|
|
|
* @param pageNo
|
|
|
|
* @param pageSize
|
|
|
|
* @param req
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "Embeddings-分页列表查询")
|
|
|
|
@Operation(summary="Embeddings-分页列表查询")
|
|
|
|
@GetMapping(value = "/list")
|
|
|
|
public Result<IPage<Embeddings>> queryPageList(Embeddings Embeddings,
|
|
|
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
|
HttpServletRequest req) throws NoSuchFieldException, IllegalAccessException, SQLException {
|
|
|
|
Response<Embedding> embedding = aiModelUtils.getEmbedding("1925730210204721154", "33333");
|
|
|
|
|
|
|
|
List<Embeddings> records = embeddingsService.findAll();
|
|
|
|
for (Embeddings record : records) {
|
|
|
|
System.out.println("record = " + record);
|
|
|
|
}
|
|
|
|
Page<Embeddings> page = new Page<Embeddings>(pageNo, pageSize);
|
|
|
|
page.setRecords(records);
|
|
|
|
return Result.OK(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加
|
|
|
|
*
|
|
|
|
* @param Embeddings
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "Embeddings-添加")
|
|
|
|
@Operation(summary="Embeddings-添加")
|
|
|
|
@RequiresPermissions("Embeddings:Embeddings:add")
|
|
|
|
@PostMapping(value = "/add")
|
|
|
|
public Result<String> add(@RequestBody Embeddings Embeddings) {
|
|
|
|
// embeddingsService.save(Embeddings);
|
|
|
|
return Result.OK("添加成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
*
|
|
|
|
* @param Embeddings
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "Embeddings-编辑")
|
|
|
|
@Operation(summary="Embeddings-编辑")
|
|
|
|
@RequiresPermissions("Embeddings:Embeddings:edit")
|
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
|
public Result<String> edit(@RequestBody Embeddings Embeddings) {
|
|
|
|
// embeddingsService.updateById(Embeddings);
|
|
|
|
return Result.OK("编辑成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id删除
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "Embeddings-通过id删除")
|
|
|
|
@Operation(summary="Embeddings-通过id删除")
|
|
|
|
@RequiresPermissions("Embeddings:Embeddings:delete")
|
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
|
// embeddingsService.removeById(id);
|
|
|
|
return Result.OK("删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 批量删除
|
|
|
|
*
|
|
|
|
* @param ids
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@AutoLog(value = "Embeddings-批量删除")
|
|
|
|
@Operation(summary="Embeddings-批量删除")
|
|
|
|
@RequiresPermissions("Embeddings:Embeddings:deleteBatch")
|
|
|
|
@DeleteMapping(value = "/deleteBatch")
|
|
|
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
|
// this.embeddingsService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
|
return Result.OK("批量删除成功!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过id查询
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
//@AutoLog(value = "Embeddings-通过id查询")
|
|
|
|
@Operation(summary="Embeddings-通过id查询")
|
|
|
|
@GetMapping(value = "/queryById")
|
|
|
|
public Result<Embeddings> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
|
// Embeddings Embeddings = embeddingsService.getById(id);
|
|
|
|
// if(Embeddings==null) {
|
|
|
|
// return Result.error("未找到对应数据");
|
|
|
|
// }
|
|
|
|
return Result.OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 导出excel
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param Embeddings
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("Embeddings:Embeddings:exportXls")
|
|
|
|
@RequestMapping(value = "/exportXls")
|
|
|
|
public ModelAndView exportXls(HttpServletRequest request, Embeddings Embeddings) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过excel导入数据
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* @param response
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("Embeddings:Embeddings:importExcel")
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|