JuliusSandmann commited on
Commit
cf6e682
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py CHANGED
@@ -18,6 +18,64 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def construction_site_info(city: str, site_id: str = None) -> str:
23
+ """Fetches information about current construction sites.
24
+
25
+ Args:
26
+ city: The city to check for construction sites (e.g., 'Karlsruhe').
27
+ site_id: Optional specific construction site ID to get detailed information.
28
+ """
29
+ import requests
30
+
31
+ API_KEY = "your_construction_api_key_here"
32
+ BASE_URL = "https://api.construction-info.com/v1"
33
+
34
+ try:
35
+ if site_id:
36
+ # Fetch details for a specific construction site
37
+ URL = f"{BASE_URL}/sites/{city}/{site_id}?key={API_KEY}"
38
+ response = requests.get(URL)
39
+ data = response.json()
40
+
41
+ if "error" in data:
42
+ return f"Error: {data['error_message']}"
43
+
44
+ site = data["site"]
45
+ return f"""
46
+ Construction Site: {site['name']}
47
+ Location: {site['address']}
48
+ Type: {site['type']}
49
+ Start Date: {site['start_date']}
50
+ Expected End Date: {site['end_date']}
51
+ Current Status: {site['status']}
52
+ Traffic Impact: {site['traffic_impact']}
53
+ Contact: {site['contact_info']}
54
+ """
55
+ else:
56
+ # Fetch list of all construction sites in the city
57
+ URL = f"{BASE_URL}/sites/{city}?key={API_KEY}"
58
+ response = requests.get(URL)
59
+ data = response.json()
60
+
61
+ if "error" in data:
62
+ return f"Error: {data['error_message']}"
63
+
64
+ sites = data["sites"]
65
+ if not sites:
66
+ return f"No construction sites found in {city}."
67
+
68
+ result = f"Found {len(sites)} construction sites in {city}:\n\n"
69
+ for site in sites:
70
+ result += f"ID: {site['id']} - {site['name']} ({site['status']})\n"
71
+ result += f"Location: {site['address']}\n"
72
+ result += f"Impact: {site['traffic_impact']}\n\n"
73
+
74
+ return result
75
+
76
+ except Exception as e:
77
+ return f"Error fetching construction site information: {str(e)}"
78
+
79
  @tool
80
  def get_current_time_in_timezone(timezone: str) -> str:
81
  """A tool that fetches the current local time in a specified timezone.