Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,8 +33,22 @@ class PDOKLocationSearchInput(BaseModel):
|
|
33 |
else:
|
34 |
return ""
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
@tool
|
37 |
-
def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional[str] = None, street_name: Optional[str] = None, city: Optional[str] = None) ->
|
38 |
"""Provides information about a Dutch address or postal code.
|
39 |
|
40 |
Args:
|
@@ -79,45 +93,23 @@ def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional
|
|
79 |
|
80 |
docs = data.get("response", {}).get("docs", [])
|
81 |
if not docs:
|
82 |
-
|
83 |
|
84 |
first_result = docs[0]
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
output_lines.append(f" Postal Code: {first_result.get('postcode', 'N/A')}")
|
100 |
-
output_lines.append(f" City: {first_result.get('woonplaatsnaam', 'N/A')}")
|
101 |
-
output_lines.append(f" Municipality: {first_result.get('gemeentenaam', 'N/A')}")
|
102 |
-
output_lines.append(f" Province: {first_result.get('provincienaam', 'N/A')}")
|
103 |
-
output_lines.append(f" Coordinates (Lat/Lon): {first_result.get('centroide_ll', 'N/A')}")
|
104 |
-
output_lines.append(f" Coordinates (RD): {first_result.get('centroide_rd', 'N/A')}")
|
105 |
-
|
106 |
-
# Add more fields if they are present and relevant
|
107 |
-
if 'buurtnaam' in first_result:
|
108 |
-
output_lines.append(f" Neighborhood: {first_result.get('buurtnaam', 'N/A')}")
|
109 |
-
if 'wijknaam' in first_result:
|
110 |
-
output_lines.append(f" District: {first_result.get('wijknaam', 'N/A')}")
|
111 |
-
if 'waterschapsnaam' in first_result:
|
112 |
-
output_lines.append(f" Water Authority: {first_result.get('waterschapsnaam', 'N/A')}")
|
113 |
-
|
114 |
-
|
115 |
-
return "\n".join(output_lines)
|
116 |
-
|
117 |
-
except requests.exceptions.RequestException as e:
|
118 |
-
return f"Error during API request: {e}"
|
119 |
-
except (ValueError, KeyError) as e:
|
120 |
-
return f"Error processing API response: {e}"
|
121 |
|
122 |
@tool
|
123 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
33 |
else:
|
34 |
return ""
|
35 |
|
36 |
+
class PDOKLocationInfo(BaseModel):
|
37 |
+
type: str
|
38 |
+
weergavenaam: str
|
39 |
+
straatnaam: str
|
40 |
+
huisnummer: int
|
41 |
+
huisletter: Optional[str]
|
42 |
+
huisnummertoevoeging: Optional[str]
|
43 |
+
postcode: str
|
44 |
+
woonplaatsnaam: str
|
45 |
+
gemeentenaam: str
|
46 |
+
provincienaam: str
|
47 |
+
centroide_ll: str
|
48 |
+
centroide_rd: str
|
49 |
+
|
50 |
@tool
|
51 |
+
def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional[str] = None, street_name: Optional[str] = None, city: Optional[str] = None) -> Optional[PDOKLocationInfo]:
|
52 |
"""Provides information about a Dutch address or postal code.
|
53 |
|
54 |
Args:
|
|
|
93 |
|
94 |
docs = data.get("response", {}).get("docs", [])
|
95 |
if not docs:
|
96 |
+
return None
|
97 |
|
98 |
first_result = docs[0]
|
99 |
+
location_info = PDOKLocationInfo(**first_result)
|
100 |
+
|
101 |
+
# Format the output in a more user-friendly way
|
102 |
+
print(f"Information about: {location_info.weergavenaam}")
|
103 |
+
print("-" * 30)
|
104 |
+
for field, value in location_info.dict().items():
|
105 |
+
print(f" {field.capitalize()}: {value}")
|
106 |
+
|
107 |
+
# Add more features as needed, such as geocoding, reverse geocoding, and caching
|
108 |
+
return location_info
|
109 |
+
except requests.exceptions.RequestException as e:
|
110 |
+
return f"Error during API request: {e}"
|
111 |
+
except (ValueError, KeyError) as e:
|
112 |
+
return f"Error processing API response: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
@tool
|
115 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|