Spaces:
Sleeping

doluong6 commited on
Commit
f177b2f
·
verified ·
1 Parent(s): 5bca3dd

Update actions.py

Browse files
Files changed (1) hide show
  1. actions.py +22 -0
actions.py CHANGED
@@ -140,3 +140,25 @@ def action_price_lookup(query: str, top_k: int = 5) -> str:
140
  p_str = str(p)
141
  lines.append(f"- {m['name']} — {p_str} (nguồn: {m['file']}, match={m['score']:.2f})")
142
  return "\n".join(lines)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  p_str = str(p)
141
  lines.append(f"- {m['name']} — {p_str} (nguồn: {m['file']}, match={m['score']:.2f})")
142
  return "\n".join(lines)
143
+ # actions.py (thêm cuối file hoặc ngay dưới các hàm action_)
144
+ from fastapi import APIRouter, Query
145
+
146
+ router = APIRouter()
147
+
148
+ @router.get("/price_table")
149
+ def price_table():
150
+ """REST endpoint: liệt kê các bảng giá đã phát hiện."""
151
+ return {"text": action_price_table()}
152
+
153
+ @router.get("/price_lookup")
154
+ def price_lookup(q: str = Query(..., description="Tên thiết bị/dịch vụ cần tra giá"), top_k: int = 5):
155
+ """REST endpoint: tra cứu giá theo tên."""
156
+ return {"text": action_price_lookup(q, top_k=top_k)}
157
+
158
+ # (tuỳ chọn) nếu bạn có hàm action_procedure_answer:
159
+ @router.get("/procedure_search")
160
+ def procedure_search(q: str = Query(..., description="Câu hỏi về Quy trình/Tài liệu")):
161
+ try:
162
+ return {"text": action_procedure_answer(q)}
163
+ except Exception as e:
164
+ return {"text": f"Lỗi: {e}"}