Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use retrieval content #429

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions source/lambda/online/common_logic/common_utils/monitor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ def is_null_or_empty(value):
return False


def _generate_markdown_link(file_path: str) -> str:
file_name = file_path.split("/")[-1]
markdown_link = f"[{file_name}]({file_path})"
return markdown_link
def _file_name_in_path(file_path: str) -> str:
return file_path.split("/")[-1]


def format_qq_data(data) -> str:
Expand All @@ -37,7 +35,7 @@ def format_qq_data(data) -> str:
markdown_table += "|-----|-----|-----|-----|\n"

# Data contains only one QQ match result
qq_source = _generate_markdown_link(data.get("source", ""))
qq_source = _file_name_in_path(data.get("source", ""))
qq_score = data.get("score", -1)
qq_question = data.get("page_content", "").replace("\n", "<br>")
qq_answer = data.get("answer", "").replace("\n", "<br>")
Expand All @@ -64,9 +62,9 @@ def format_rag_data(data, qq_result) -> str:
markdown_table += "|-----|-----|-----|-----|\n"
for item in data:
raw_source = item.get("source", "")
source = _generate_markdown_link(raw_source)
source = _file_name_in_path(raw_source)
score = item.get("score", -1)
page_content = item.get("page_content", "").replace("\n", "<br>")
page_content = item.get("retrieval_content", "").replace("\n", "<br>")
markdown_table += f"| {source} | {raw_source} | {score} | {page_content} |\n"

if not is_null_or_empty(qq_result):
Expand All @@ -76,7 +74,7 @@ def format_rag_data(data, qq_result) -> str:

for qq_item in qq_result:
raw_qq_source = qq_item.get("source", "")
qq_source = _generate_markdown_link(raw_qq_source)
qq_source = _file_name_in_path(raw_qq_source)
qq_score = qq_item.get("score", -1)
qq_question = qq_item.get("page_content", "").replace("\n", "<br>")
qq_answer = qq_item.get("answer", "").replace("\n", "<br>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def contexts_trunc(docs: list[dict], context_num=2):
context_strs.append(content)
s.add(content)
context_docs.append(
{"doc": content, "source": doc["source"], "score": doc["score"]}
{"doc": content,
"source": doc["source"], "score": doc["score"]}
)
context_sources.append(doc["source"])
return {
Expand Down Expand Up @@ -53,8 +54,10 @@ def retriever_results_format(
"answer": doc.metadata.get("answer", ""),
"question": doc.metadata.get("question", ""),
"figure": doc.metadata.get("figure", []),
"retrieval_content": doc.metadata.get("retrieval_content", ""),
}
)

if print_source:
source_strs = []
for doc_dict in doc_dicts:
Expand Down
Loading