mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 20:51:48 +00:00
[improvement](headless) Optimize the reload embedding interface (#1655)
This commit is contained in:
@@ -12,4 +12,6 @@ public interface ExemplarService {
|
|||||||
List<Text2SQLExemplar> recallExemplars(String collection, String query, int num);
|
List<Text2SQLExemplar> recallExemplars(String collection, String query, int num);
|
||||||
|
|
||||||
List<Text2SQLExemplar> recallExemplars(String query, int num);
|
List<Text2SQLExemplar> recallExemplars(String query, int num);
|
||||||
|
|
||||||
|
void loadSysExemplars();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import org.springframework.core.annotation.Order;
|
|||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -88,18 +87,18 @@ public class ExemplarServiceImpl implements ExemplarService, CommandLineRunner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) {
|
public void run(String... args) {
|
||||||
try {
|
|
||||||
loadSysExemplars();
|
loadSysExemplars();
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Failed to load system exemplars", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSysExemplars() throws IOException {
|
public void loadSysExemplars() {
|
||||||
|
try {
|
||||||
ClassPathResource resource = new ClassPathResource(SYS_EXEMPLAR_FILE);
|
ClassPathResource resource = new ClassPathResource(SYS_EXEMPLAR_FILE);
|
||||||
InputStream inputStream = resource.getInputStream();
|
InputStream inputStream = resource.getInputStream();
|
||||||
List<Text2SQLExemplar> exemplars = objectMapper.readValue(inputStream, valueTypeRef);
|
List<Text2SQLExemplar> exemplars = objectMapper.readValue(inputStream, valueTypeRef);
|
||||||
String collection = embeddingConfig.getText2sqlCollectionName();
|
String collection = embeddingConfig.getText2sqlCollectionName();
|
||||||
exemplars.stream().forEach(e -> storeExemplar(collection, e));
|
exemplars.stream().forEach(e -> storeExemplar(collection, e));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to load system exemplars", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import javax.validation.Valid;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||||
|
import com.tencent.supersonic.common.service.ExemplarService;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.DictItemFilter;
|
import com.tencent.supersonic.headless.api.pojo.request.DictItemFilter;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.DictItemReq;
|
import com.tencent.supersonic.headless.api.pojo.request.DictItemReq;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.DictSingleTaskReq;
|
import com.tencent.supersonic.headless.api.pojo.request.DictSingleTaskReq;
|
||||||
@@ -36,10 +37,12 @@ public class KnowledgeController {
|
|||||||
|
|
||||||
@Autowired private DictConfService confService;
|
@Autowired private DictConfService confService;
|
||||||
|
|
||||||
@Autowired private MetaEmbeddingTask embeddingTask;
|
@Autowired private MetaEmbeddingTask metaEmbeddingTask;
|
||||||
|
|
||||||
@Autowired private DictionaryReloadTask dictionaryReloadTask;
|
@Autowired private DictionaryReloadTask dictionaryReloadTask;
|
||||||
|
|
||||||
|
@Autowired private ExemplarService exemplarService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addDictConf-新增item的字典配置 Add configuration information for dictionary entries
|
* addDictConf-新增item的字典配置 Add configuration information for dictionary entries
|
||||||
*
|
*
|
||||||
@@ -130,15 +133,16 @@ public class KnowledgeController {
|
|||||||
return taskService.queryLatestDictTask(taskReq, user);
|
return taskService.queryLatestDictTask(taskReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/meta/embedding/reload")
|
@GetMapping("/embedding/reload")
|
||||||
public Object reloadMetaEmbedding() {
|
public Object reloadEmbedding() {
|
||||||
embeddingTask.reloadMetaEmbedding();
|
metaEmbeddingTask.reloadMetaEmbedding();
|
||||||
|
exemplarService.loadSysExemplars();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/embedding/persistFile")
|
@GetMapping("/embedding/persistFile")
|
||||||
public Object executePersistFileTask() {
|
public Object executePersistFileTask() {
|
||||||
embeddingTask.executePersistFileTask();
|
metaEmbeddingTask.executePersistFileTask();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user