Lurosm commited on
Commit
e0d70a1
·
verified ·
1 Parent(s): 9c26a51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -35,16 +35,19 @@ class PDOKLocationSearchInput(BaseModel):
35
  class PDOKLocationInfo(BaseModel):
36
  type: str
37
  weergavenaam: str
38
- straatnaam: str
39
- huisnummer: int
40
- huisletter: Optional[str]
41
- huisnummertoevoeging: Optional[str]
42
- postcode: str
43
- woonplaatsnaam: str
44
- gemeentenaam: str
45
- provincienaam: str
46
- centroide_ll: str
47
- centroide_rd: str
 
 
 
48
 
49
  @tool
50
  def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional[str] = None, street_name: Optional[str] = None, city: Optional[str] = None) -> str:
@@ -95,14 +98,9 @@ def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional
95
  "wt": "json",
96
  }
97
 
98
- debug_info.append(f"API request details:\n"
99
- f" URL: {base_url}\n"
100
- f" Params: {params}")
101
-
102
  try:
103
  response = requests.get(base_url, params=params, headers=headers)
104
- debug_info.append(f"Response status code: {response.status_code}\n"
105
- f"Response URL: {response.url}")
106
 
107
  response.raise_for_status()
108
  data = response.json()
@@ -114,8 +112,9 @@ def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional
114
  return f"Error: No results found\nDebug info:\n" + "\n".join(debug_info)
115
 
116
  first_result = docs[0]
 
 
117
  location_info = PDOKLocationInfo(**first_result)
118
- # Convert the PDOKLocationInfo object to a JSON string
119
  return location_info.model_dump_json()
120
 
121
  except requests.exceptions.RequestException as e:
@@ -123,7 +122,6 @@ def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional
123
  except (ValueError, KeyError) as e:
124
  return f"Error processing API response: {e}\nDebug info:\n" + "\n".join(debug_info)
125
 
126
-
127
  @tool
128
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
129
  #Keep this format for the description / args / args description but feel free to modify the tool
 
35
  class PDOKLocationInfo(BaseModel):
36
  type: str
37
  weergavenaam: str
38
+ straatnaam: Optional[str] = None
39
+ huisnummer: Optional[int] = None
40
+ huisletter: Optional[str] = None
41
+ huisnummertoevoeging: Optional[str] = None
42
+ postcode: Optional[str] = None
43
+ woonplaatsnaam: Optional[str] = None
44
+ gemeentenaam: Optional[str] = None
45
+ provincienaam: Optional[str] = None
46
+ centroide_ll: Optional[str] = None
47
+ centroide_rd: Optional[str] = None
48
+
49
+ class Config:
50
+ extra = "allow" # This will allow extra fields from the API response
51
 
52
  @tool
53
  def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional[str] = None, street_name: Optional[str] = None, city: Optional[str] = None) -> str:
 
98
  "wt": "json",
99
  }
100
 
 
 
 
 
101
  try:
102
  response = requests.get(base_url, params=params, headers=headers)
103
+ debug_info.append(f"Response status code: {response.status_code}")
 
104
 
105
  response.raise_for_status()
106
  data = response.json()
 
112
  return f"Error: No results found\nDebug info:\n" + "\n".join(debug_info)
113
 
114
  first_result = docs[0]
115
+ debug_info.append(f"First result data: {first_result}")
116
+
117
  location_info = PDOKLocationInfo(**first_result)
 
118
  return location_info.model_dump_json()
119
 
120
  except requests.exceptions.RequestException as e:
 
122
  except (ValueError, KeyError) as e:
123
  return f"Error processing API response: {e}\nDebug info:\n" + "\n".join(debug_info)
124
 
 
125
  @tool
126
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
127
  #Keep this format for the description / args / args description but feel free to modify the tool