Commit 0c199fc8 authored by yangyw's avatar yangyw

feature: 增加测试接口

parent ece79536
......@@ -241,4 +241,30 @@ public class AiPlatformExtensionService {
}
return "false";
}
public List<VectorSegment> testSearchWithRerank(String query, Integer assistantId, Integer topK, Double score, Integer rerankTopK, Double rerankScore) {
RagSearchRequest request = new RagSearchRequest();
request.setQuery(query);
request.setMinScore(ObjectUtil.defaultIfNull(score, 0d));
request.setTopK(ObjectUtil.defaultIfNull(topK, 5));
request.setEnableRerank(true);
request.setTopKRerank(ObjectUtil.defaultIfNull(rerankTopK, 5));
request.setMinScoreRerank(ObjectUtil.defaultIfNull(rerankScore, 0d));
if (!ObjectUtil.equals(assistantId, 0)) {
//需要过滤分类
QaAssistantResponseModel qaAssistantResponseModel =chatCompletionService.qaAssistantDetail(assistantId);
if (ObjectUtil.isNotNull(qaAssistantResponseModel)) {
if (JSONValidator.from(qaAssistantResponseModel.getCategoryIds()).validate()) {
List<Integer> categoryIds = JSONArray.parseArray(qaAssistantResponseModel.getCategoryIds(), Integer.class);
if (CollUtil.isNotEmpty(categoryIds)) {
Map<String, Object> metadata = new HashMap<>();
metadata.put("tag_id", categoryIds);
request.setMetadata(metadata);
}
}
}
}
log.info("search:{}", request);
return aiService.searchWithRerank(request);
}
}
package cn.breeze.elleai.controller.extension;
import cn.breeze.elleai.application.dto.langchain.VectorSegment;
import cn.breeze.elleai.application.service.AiPlatformExtensionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author yangyw
*/
......@@ -55,4 +58,16 @@ public class AiPlatformExtensionController {
return extensionService.canAnswerByLlm(assistantId);
}
@Operation(summary = "向量搜索(测试)")
@PostMapping(value = "/test_search_with_rerank")
public List<VectorSegment> testSearchWithRerank(@RequestParam("query") String query,
@RequestParam(value = "assistant_id", required = false, defaultValue = "0") Integer assistantId,
@RequestParam(value = "top_k", required = false, defaultValue = "5") Integer topK,
@RequestParam(value = "score", required = false, defaultValue = "0") Double score,
@RequestParam(value = "rerank_top_k", required = false, defaultValue = "5") Integer rerankTopK,
@RequestParam(value = "rerank_score", required = false, defaultValue = "0") Double rerankScore) {
return extensionService.testSearchWithRerank(query, assistantId, topK, score, rerankTopK, rerankScore);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment