Skip to content

Commit

Permalink
fix: source_documents url error
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankGTY committed Nov 4, 2024
1 parent 451e186 commit 4b5068f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Binary file renamed deploy/.DS_Store → .DS_Store
Binary file not shown.
26 changes: 20 additions & 6 deletions libs/aitutor/server/chat/kb_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,16 @@ async def knowledge_base_chat_iterator() -> AsyncIterable[str]:
file_name="",
metadata={},
)
source_documents = format_reference(
kb_name, docs, api_address(is_public=True)
)
source_documents = []
for inum, doc in enumerate(docs):
filename = doc.metadata.get("source")
text = f"""出处 [{inum + 1}] [{filename}] \n\n{doc.page_content}\n\n"""
source_documents.append(text)

if len(source_documents) == 0: # 没有找到相关文档
source_documents.append(
f"""<span style='color:red'>未找到相关文档,该回答为大模型自身能力解答!</span>"""
)
elif mode == "temp_kb":
ok, msg = check_embed_model()
if not ok:
Expand All @@ -115,9 +122,16 @@ async def knowledge_base_chat_iterator() -> AsyncIterable[str]:
top_k=top_k,
score_threshold=score_threshold,
)
source_documents = format_reference(
kb_name, docs, api_address(is_public=True)
)
source_documents = []
for inum, doc in enumerate(docs):
filename = doc.metadata.get("source")
text = f"""出处 [{inum + 1}] [{filename}] \n\n{doc.page_content}\n\n"""
source_documents.append(text)

if len(source_documents) == 0: # 没有找到相关文档
source_documents.append(
f"""<span style='color:red'>未找到相关文档,该回答为大模型自身能力解答!</span>"""
)
elif mode == "search_engine":
result = await run_in_threadpool(search_engine, query, top_k, kb_name)
docs = [x.dict() for x in result.get("docs", [])]
Expand Down

0 comments on commit 4b5068f

Please sign in to comment.