ASown's picture
Consolidate project history under ASown
f368481
Raw History Blame Contribute Delete
2.46 kB
"""Harness adapter: tìm văn bản/tài liệu trên web (KHÔNG liên quan máy in)."""
from __future__ import annotations
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
ROOT = HERE.parent.parent
for p in (str(HERE), str(ROOT)):
if p not in sys.path:
sys.path.insert(0, p)
from harness.tool_base import Tool, ToolResult
class DocFinderTool(Tool):
name = "doc_finder"
description = (
"TÌM một văn bản/tài liệu trên web (luật, nghị định, thông tư, bài thơ, bài "
"hát, quy định…): tìm kiếm → đọc & xác minh bằng LLM → trả về file PDF để tải "
"về. CHỈ tìm kiếm — KHÔNG in ra giấy, KHÔNG dò máy in. Muốn IN thì mới dùng "
"paper_printer."
)
def run(self, task: str, **ctx) -> ToolResult:
import doc_search as ds
on_step = ctx.get("on_progress")
r = ds.find_doc(task, on_step)
if not r.get("ok"):
return ToolResult(False, f"Không tìm được văn bản phù hợp: {r.get('error','')}", r)
title = r.get("title", "")
original = r.get("is_original")
vr = "đã XÁC MINH đúng" if r.get("verified") else "GẦN ĐÚNG (chưa xác minh chắc chắn)"
if original:
msg = (f"Đã TẢI VỀ FILE GỐC ({vr}): “{title}” từ {r.get('doc_url','')}. "
"Đây là file thật tải trực tiếp, không phải bản dựng lại.")
if not r.get("verified"):
msg += " Chưa chắc đúng 100% — hãy nói thẳng và mời người dùng nêu tên/số hiệu cụ thể hơn."
else:
# KHÔNG có file gốc — chỉ trích text từ trang web. Phải nói THẲNG.
msg = (f"KHÔNG tìm thấy FILE GỐC. Chỉ tìm được TRANG WEB “{title}” ({r.get('doc_url','')}) "
"và lưu nội dung TRÍCH từ trang đó thành PDF — file này KHÔNG phải tài liệu gốc "
"chính thức, có thể thiếu/không đúng định dạng. Hãy nói THẲNG với người dùng rằng "
"chưa lấy được bản gốc, đây chỉ là nội dung trích từ web; gợi ý nêu link/tên/số "
"hiệu cụ thể hơn để tìm đúng file.")
return ToolResult(True, msg, r)
def get_tool() -> Tool:
return DocFinderTool()