Spaces:
Runtime error
Runtime error
Commit ·
e837188
1
Parent(s): aee383d
feat: add address validation function to enhance address recognition
Browse files- backend/systemprompt.py +1 -1
- backend/tools.py +34 -1
backend/systemprompt.py
CHANGED
|
@@ -108,7 +108,7 @@ When the user confirms they want to buy a promotion or product:
|
|
| 108 |
- เขต/อำเภอ
|
| 109 |
- แขวง/ตำบล
|
| 110 |
- ถนน
|
| 111 |
-
- หมู่บ้าน/ชื่ออาคาร
|
| 112 |
- ซอย
|
| 113 |
- บ้านเลขที่
|
| 114 |
- Postal code (5 digits)
|
|
|
|
| 108 |
- เขต/อำเภอ
|
| 109 |
- แขวง/ตำบล
|
| 110 |
- ถนน
|
| 111 |
+
- หมู่บ้าน/ชื่ออาคาร : For this type of address the asr may not recognize it well, you can verify it by call address_verification tool. input only the village/building name. this will return list of candidate address that match the input. pick the most relevant one based on other infomation(เเขวง/เขต/ตำบล/อำเภอ) to confirm with user. if it's return empty list or not close to the input, just confirm with user the input as is.
|
| 112 |
- ซอย
|
| 113 |
- บ้านเลขที่
|
| 114 |
- Postal code (5 digits)
|
backend/tools.py
CHANGED
|
@@ -50,6 +50,23 @@ TOOL_DEFINITIONS =[
|
|
| 50 |
},
|
| 51 |
},
|
| 52 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
{
|
| 54 |
"type": "function",
|
| 55 |
"function": {
|
|
@@ -396,13 +413,27 @@ def get_promotion_description(permission: str) -> Any:
|
|
| 396 |
}
|
| 397 |
return {"status": "ok", "description": PROMOTION_DESCRIPTION}
|
| 398 |
# return {"status": "ok", "description": "test"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
|
| 401 |
TOOL_FUNCTIONS = {
|
| 402 |
"get_promotion_description": get_promotion_description,
|
| 403 |
"summary_order": summary_order,
|
| 404 |
"purchase_product": purchase_product,
|
| 405 |
-
"call_admin": call_admin
|
|
|
|
| 406 |
}
|
| 407 |
|
| 408 |
|
|
@@ -426,6 +457,8 @@ def execute_tool(name: str, arguments: Dict[str, Any]) -> str:
|
|
| 426 |
return json.dumps({"status": "error", "message": str(exc)}, ensure_ascii=False)
|
| 427 |
|
| 428 |
return _format_tool_result(result)
|
|
|
|
|
|
|
| 429 |
|
| 430 |
|
| 431 |
if __name__ == "__main__":
|
|
|
|
| 50 |
},
|
| 51 |
},
|
| 52 |
},
|
| 53 |
+
{
|
| 54 |
+
"type": "function",
|
| 55 |
+
"function": {
|
| 56 |
+
"name": "address_validation",
|
| 57 |
+
"description": "Check the correctness of หมู่บ้าน, ชื่ออาคาร, ชื่อคอนโด",
|
| 58 |
+
"parameters": {
|
| 59 |
+
"type": "object",
|
| 60 |
+
"properties": {
|
| 61 |
+
"keyword": {
|
| 62 |
+
"type": "string",
|
| 63 |
+
"description": "input หมู่บ้าน, ชื่ออาคาร, ชื่อคอนโด from user",
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
"required": ["keyword"],
|
| 67 |
+
},
|
| 68 |
+
},
|
| 69 |
+
},
|
| 70 |
{
|
| 71 |
"type": "function",
|
| 72 |
"function": {
|
|
|
|
| 413 |
}
|
| 414 |
return {"status": "ok", "description": PROMOTION_DESCRIPTION}
|
| 415 |
# return {"status": "ok", "description": "test"}
|
| 416 |
+
def address_validation(keyword):
|
| 417 |
+
LONGDO_API_KEY = os.getenv("LONGDO_API_KEY")
|
| 418 |
+
# keyword = "เพอเฟคเพลซ"
|
| 419 |
+
url = f"https://api.longdo.com/mapsearch/json/suggest?keyword={keyword}&key={LONGDO_API_KEY}&sdx=1"
|
| 420 |
+
|
| 421 |
+
try:
|
| 422 |
+
response = requests.get(url)
|
| 423 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
| 424 |
+
data = [res.get('w') for res in response.json().get("data")]
|
| 425 |
+
return data
|
| 426 |
+
except requests.exceptions.RequestException as e:
|
| 427 |
+
print(f"Error fetching data from Longdo Map API: {e}")
|
| 428 |
+
return []
|
| 429 |
|
| 430 |
|
| 431 |
TOOL_FUNCTIONS = {
|
| 432 |
"get_promotion_description": get_promotion_description,
|
| 433 |
"summary_order": summary_order,
|
| 434 |
"purchase_product": purchase_product,
|
| 435 |
+
"call_admin": call_admin,
|
| 436 |
+
"address_validation": address_validation,
|
| 437 |
}
|
| 438 |
|
| 439 |
|
|
|
|
| 457 |
return json.dumps({"status": "error", "message": str(exc)}, ensure_ascii=False)
|
| 458 |
|
| 459 |
return _format_tool_result(result)
|
| 460 |
+
|
| 461 |
+
|
| 462 |
|
| 463 |
|
| 464 |
if __name__ == "__main__":
|