Skip to content

Commit

Permalink
Merge pull request #686 from chat2db/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
shanhexi authored Oct 28, 2023
2 parents ce0ad42 + 0f84db3 commit c667666
Show file tree
Hide file tree
Showing 17 changed files with 10,906 additions and 396,399 deletions.
3 changes: 3 additions & 0 deletions chat2db-client/src/blocks/Setting/BaseSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export default function BaseSetting() {

function changeLang(e: any) {
setLangLocalStorage(e.target.value);
//切换语言时,需要设置cookie,用来改变后台服务的Locale
const date = new Date('2030-12-30 12:30:00').toUTCString();
document.cookie = `CHAT2DB.LOCALE=${e.target.value};Expires=${date}`;
location.reload();
}

Expand Down
10,844 changes: 10,844 additions & 0 deletions chat2db-client/yarn.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ public class CopyTemplate {
/**
* 模板文件
**/
public static final List<String> TEMPLATE_FILE = Arrays.asList("template.html", "template_diy.docx", "sub_template_diy.docx");
private static final List<String> TEMPLATE_FILE = Arrays.asList("template.html", "template_diy.docx", "sub_template_diy.docx");

static {
//复制模板
copyTemplateFile();
}

public static void copyTemplateFile() {
public void copyTemplateFile() {
String templateDir = ConfigUtils.CONFIG_BASE_PATH + File.separator + "template";
File file = new File(templateDir);
if (!file.exists()) {
Expand All @@ -39,7 +34,7 @@ public static void copyTemplateFile() {
}
}

public static void saveFile(String dir, String path, boolean isOverride) {
public void saveFile(String dir, String path, boolean isOverride) {
if (!isOverride) {
File file = new File(dir + File.separator + path);
if (file.exists()) {
Expand All @@ -49,7 +44,7 @@ public static void saveFile(String dir, String path, boolean isOverride) {
try (// 模板文件输入输出地址 读取resources下文件
FileOutputStream outputStream = new FileOutputStream(dir + File.separator + path);
//返回读取指定资源的输入流
InputStream inputStream = ConfigUtils.class.getClassLoader().getResourceAsStream("template" + File.separator + path)) {
InputStream inputStream = CopyTemplate.class.getClassLoader().getResourceAsStream("template/" + path)) {
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = inputStream.read(buffer))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ai.chat2db.server.start.listener;

import ai.chat2db.server.start.config.util.CopyTemplate;
import ai.chat2db.server.web.api.controller.rdb.doc.event.TemplateEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
* TemplateListener
*
* @author lzy
**/
@Component
public class TemplateListener {

@Autowired
private CopyTemplate copyTemplate;

@EventListener(classes = TemplateEvent.class)
public void copyTemplate() {
//复制模板
copyTemplate.copyTemplateFile();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@
</dependency>


<dependency>
<groupId>org.ansj</groupId>
<artifactId>ansj_seg</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import ai.chat2db.server.web.api.http.response.EsTableSchemaResponse;
import ai.chat2db.server.web.api.http.response.TableSchemaResponse;
import ai.chat2db.server.web.api.util.ApplicationContextUtil;
import ai.chat2db.server.web.api.util.SegmentUtils;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
Expand Down Expand Up @@ -556,10 +555,9 @@ public String mappingDatabaseSchema(ChatQueryRequest queryRequest) {
if (StringUtils.isNotBlank(apiKey)) {
boolean res = gatewayClientService.checkInWhite(new WhiteListRequest(apiKey, WhiteListTypeEnum.VECTOR.getCode())).getData();
if (res) {
properties = queryDatabaseSchema(queryRequest) + querySchemaByEs(queryRequest);
// properties = queryDatabaseSchema(queryRequest) + querySchemaByEs(queryRequest);
properties = queryDatabaseSchema(queryRequest);
}
} else {
properties = querySchemaByEs(queryRequest);
}
return properties;
}
Expand All @@ -573,10 +571,11 @@ public String mappingDatabaseSchema(ChatQueryRequest queryRequest) {
*/
public String queryDatabaseSchema(ChatQueryRequest queryRequest) {
// request embedding
String input = SegmentUtils.baseAnalysis(queryRequest.getMessage());
log.info("search message:{}", input);
FastChatEmbeddingResponse response = distributeAIEmbedding(input);
FastChatEmbeddingResponse response = distributeAIEmbedding(queryRequest.getMessage());
List<List<BigDecimal>> contentVector = new ArrayList<>();
if (Objects.isNull(response) || CollectionUtils.isEmpty(response.getData())) {
return "";
}
contentVector.add(response.getData().get(0).getEmbedding());

// search embedding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public WebPageResult<TableVO> list(@Valid TableBriefQueryRequest request) {
try {
Chat2DBContext.putContext(connectInfo);
syncTableVector(request);
syncTableEs(request);
// syncTableEs(request);
} catch (Exception e) {
log.error("sync table vector error", e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter;
import ai.chat2db.server.web.api.controller.rdb.doc.DatabaseExportService;
import ai.chat2db.server.web.api.controller.rdb.doc.conf.ExportOptions;
import ai.chat2db.server.web.api.controller.rdb.doc.event.TemplateEvent;
import ai.chat2db.server.web.api.controller.rdb.factory.ExportServiceFactory;
import ai.chat2db.server.web.api.controller.rdb.request.DataExportRequest;
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
Expand All @@ -20,6 +21,7 @@
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -48,13 +50,18 @@ public class RdbDocController {
@Autowired
private RdbWebConverter rdbWebConverter;

@Autowired
private ApplicationContext applicationContext;

/**
* export data
*
* @param request
*/
@PostMapping("/export")
public void export(@Valid @RequestBody DataExportRequest request, HttpServletResponse response) throws Exception {
//复制模板
applicationContext.publishEvent(new TemplateEvent("copy"));
ExportTypeEnum exportType = EasyEnumUtils.getEnum(ExportTypeEnum.class, request.getExportType());
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public WebPageResult<TableVO> list(@Valid TableBriefQueryRequest request) {
try {
Chat2DBContext.putContext(connectInfo);
syncTableVector(request);
syncTableEs(request);
// syncTableEs(request);
} catch (Exception e) {
log.error("sync table vector error", e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ai.chat2db.server.web.api.controller.rdb.doc.event;

import org.springframework.context.ApplicationEvent;

/**
* TemplateEvent
*
* @author lzy
**/
public class TemplateEvent extends ApplicationEvent {
public TemplateEvent(String key) {
super(key);
}
}

This file was deleted.

6 changes: 0 additions & 6 deletions chat2db-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,6 @@
<version>2.0.24</version>
</dependency>


<dependency>
<groupId>org.ansj</groupId>
<artifactId>ansj_seg</artifactId>
<version>5.1.1</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
11 changes: 0 additions & 11 deletions library/ambiguity.dic

This file was deleted.

Loading

0 comments on commit c667666

Please sign in to comment.