无关紧要的更新
This commit is contained in:
parent
c84fa50ef2
commit
582e367f52
@ -17,7 +17,6 @@ class Retriever:
|
||||
self.web_searcher = WebSearcher()
|
||||
|
||||
def retrieval(self, query, history, meta):
|
||||
|
||||
refs = {"query": query, "history": history, "meta": meta}
|
||||
refs["model_name"] = self.config.model_name
|
||||
refs["entities"] = self.reco_entities(query, history, refs)
|
||||
@ -105,12 +104,14 @@ class Retriever:
|
||||
distance_threshold = meta.get("distanceThreshold", 0)
|
||||
top_k = meta.get("topK", 5)
|
||||
|
||||
# 检索
|
||||
all_kb_res = self.dbm.knowledge_base.search(rw_query, db_name, limit=max_query_count)
|
||||
for r in all_kb_res:
|
||||
r["file"] = kb.id2file(r["entity"]["file_id"])
|
||||
|
||||
kb_res = [r for r in all_kb_res if r["distance"] > distance_threshold]
|
||||
|
||||
# 重排序
|
||||
if self.config.enable_reranker and len(kb_res) > 0:
|
||||
texts = [r["entity"]["text"] for r in kb_res]
|
||||
rerank_scores = self.reranker.compute_score([rw_query, texts], normalize=True)
|
||||
@ -228,6 +229,7 @@ class Retriever:
|
||||
return formatted_results
|
||||
|
||||
def format_query_results(self, results):
|
||||
logger.debug(f"Graph Query Results: {results}")
|
||||
formatted_results = {"nodes": [], "edges": []}
|
||||
node_dict = {}
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@ chat = APIRouter(prefix="/chat")
|
||||
# 创建线程池
|
||||
executor = ThreadPoolExecutor()
|
||||
|
||||
refs_pool = {}
|
||||
|
||||
@chat.get("/")
|
||||
async def chat_get():
|
||||
@ -25,6 +24,7 @@ def chat_post(
|
||||
cur_res_id: str = Body(...)):
|
||||
|
||||
history_manager = HistoryManager(history)
|
||||
logger.debug(f"Received query: {query} with meta: {meta}")
|
||||
|
||||
def make_chunk(content=None, **kwargs):
|
||||
return json.dumps({
|
||||
@ -111,10 +111,4 @@ async def call(query: str = Body(...), meta: dict = Body(None)):
|
||||
response = await predict_async(query)
|
||||
logger.debug({"query": query, "response": response.content})
|
||||
|
||||
return {"response": response.content}
|
||||
|
||||
@chat.get("/refs")
|
||||
def get_refs(cur_res_id: str):
|
||||
global refs_pool
|
||||
refs = refs_pool.pop(cur_res_id, None)
|
||||
return {"refs": refs}
|
||||
return {"response": response.content}
|
||||
@ -112,7 +112,7 @@ async def get_graph_nodes(kgdb_name: str, num: int):
|
||||
result = startup.dbm.graph_base.get_sample_nodes(kgdb_name, num)
|
||||
return {"result": startup.retriever.format_general_results(result), "message": "success"}
|
||||
|
||||
@data.post("/graph/add")
|
||||
@data.post("/graph/add-by-jsonl")
|
||||
async def add_graph_entity(file_path: str = Body(...), kgdb_name: Optional[str] = Body(None)):
|
||||
if not startup.config.enable_knowledge_graph:
|
||||
raise HTTPException(status_code=400, detail="Knowledge graph is not enabled")
|
||||
|
||||
@ -152,7 +152,7 @@ const getGraphData = () => {
|
||||
const addDocumentByFile = () => {
|
||||
state.precessing = true
|
||||
const files = fileList.value.filter(file => file.status === 'done').map(file => file.response.file_path)
|
||||
fetch('/api/data/graph/add', {
|
||||
fetch('/api/data/graph/add-by-jsonl', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json" // 添加 Content-Type 头
|
||||
@ -178,7 +178,7 @@ const loadSampleNodes = () => {
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
} else if (!configStore.config.enable_knowledge_graph) {
|
||||
} else if (configStore?.config && !configStore?.config.enable_knowledge_graph) {
|
||||
throw new Error('请前往设置页面配置启用知识图谱')
|
||||
} else {
|
||||
throw new Error("加载失败");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user