Spaces:
Sleeping
Sleeping
Create p_tool_nearby.py
Browse files- p_tool_nearby.py +22 -0
p_tool_nearby.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from langchain.tools import Tool
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
def call_mcp(method, params):
|
| 6 |
+
req = {
|
| 7 |
+
"jsonrpc": "2.0",
|
| 8 |
+
"id": 1,
|
| 9 |
+
"method": method,
|
| 10 |
+
"params": params
|
| 11 |
+
}
|
| 12 |
+
r = requests.post(
|
| 13 |
+
"https://puseletso55-township-mcp-server.hf.space/run/predict",
|
| 14 |
+
json={"data": [json.dumps(req)]}
|
| 15 |
+
)
|
| 16 |
+
return json.loads(r.json()["data"][0])
|
| 17 |
+
|
| 18 |
+
nearby_tool = Tool.from_function(
|
| 19 |
+
name="getNearbyBusinesses",
|
| 20 |
+
description="Finds businesses within 10km of a location. Use this to find spaza shops or services nearby.",
|
| 21 |
+
func=lambda loc: call_mcp("getNearbyBusinesses", {"location": loc})
|
| 22 |
+
)
|