Lurosm commited on
Commit
e26c834
·
verified ·
1 Parent(s): 019e76d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -38
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) -> str:
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
- return "No results found for the given query."
83
 
84
  first_result = docs[0]
85
-
86
- # Format the output in a more readable and comprehensive way
87
- output_lines = []
88
- output_lines.append(f"Information about: {first_result.get('weergavenaam', 'N/A')}")
89
- output_lines.append("-" * 30)
90
-
91
- # Key information, handle potential missing values gracefully
92
- output_lines.append(f" Type: {first_result.get('type', 'N/A')}")
93
- output_lines.append(f" Street: {first_result.get('straatnaam', 'N/A')}")
94
- output_lines.append(f" House Number: {first_result.get('huisnummer', 'N/A')}")
95
- if 'huisletter' in first_result:
96
- output_lines.append(f" House Letter: {first_result.get('huisletter', 'N/A')}")
97
- if 'huisnummertoevoeging' in first_result:
98
- output_lines.append(f" House Number Addition: {first_result.get('huisnummertoevoeging', 'N/A')}")
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