Kalamazooter commited on
Commit
6220ead
·
verified ·
1 Parent(s): ea72a4d

add travel history

Browse files
Files changed (1) hide show
  1. app.py +65 -2
app.py CHANGED
@@ -5,13 +5,76 @@ import pytz
5
  import yaml
6
  from typing import List, Dict
7
  import tkapi
8
- from tkapi.fractie import Fractie, FractieFilter
 
9
  from tools.final_answer import FinalAnswerTool
10
 
11
  from Gradio_UI import GradioUI
12
 
13
  api = tkapi.TKApi()
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  @tool
16
  def Get_Active_Fractions() -> list[dict[str, str | int]]:
17
  """
@@ -173,7 +236,7 @@ with open("prompts.yaml", 'r') as stream:
173
 
174
  agent = CodeAgent(
175
  model=model,
176
- tools=[final_answer,Get_Active_Fractions,get_fraction_members], ## the given tools
177
  max_steps=6,
178
  verbosity_level=1,
179
  grammar=None,
 
5
  import yaml
6
  from typing import List, Dict
7
  import tkapi
8
+ from tkapi.fractie import Fractie, FractieFilter, PersoonFilter
9
+ from tkapi.util import queries
10
  from tools.final_answer import FinalAnswerTool
11
 
12
  from Gradio_UI import GradioUI
13
 
14
  api = tkapi.TKApi()
15
 
16
+ @tool
17
+ def get_kamerlid_reizen(achternaam: str) -> List[Dict[str, str]]:
18
+ """
19
+ Retrieves all registered travels for a specific parliament member by their last name.
20
+
21
+ Args:
22
+ achternaam: The last name of the parliament member to search for
23
+ (case-sensitive, partial matches are supported)
24
+
25
+ Returns:
26
+ List[Dict[str, str]]: A list of dictionaries containing travel information:
27
+ - 'bestemming': Destination of the travel
28
+ - 'doel': Purpose of the travel
29
+ - 'van': Start date of the travel
30
+ - 'tot': End date of the travel
31
+ - 'betaald_door': Who paid for the travel
32
+
33
+ Example return value:
34
+ [
35
+ {
36
+ 'bestemming': 'Brussels',
37
+ 'doel': 'EU Parliament meeting',
38
+ 'van': '2024-01-15',
39
+ 'tot': '2024-01-17',
40
+ 'betaald_door': 'European Parliament'
41
+ }
42
+ ]
43
+
44
+ Note:
45
+ If multiple parliament members match the given last name,
46
+ travels for all matching members will be returned.
47
+ """
48
+ try:
49
+ # Initialize API
50
+ api = tkapi.TKApi(verbose=False)
51
+
52
+ # Create person filter
53
+ filter = PersoonFilter()
54
+ filter.filter_achternaam(achternaam)
55
+
56
+ # Get matching persons
57
+ persons = api.get_personen(filter=filter)
58
+
59
+ # Collect all travels
60
+ all_travels = []
61
+ for person in persons:
62
+ for reis in person.reizen:
63
+ travel_info = {
64
+ 'bestemming': reis.bestemming,
65
+ 'doel': reis.doel,
66
+ 'van': str(reis.van) if reis.van else None,
67
+ 'tot': str(reis.tot_en_met) if reis.tot_en_met else None,
68
+ 'betaald_door': reis.betaald_door
69
+ }
70
+ all_travels.append(travel_info)
71
+
72
+ return all_travels
73
+
74
+ except Exception as e:
75
+ print(f"Error fetching travel data: {str(e)}")
76
+ return []
77
+
78
  @tool
79
  def Get_Active_Fractions() -> list[dict[str, str | int]]:
80
  """
 
236
 
237
  agent = CodeAgent(
238
  model=model,
239
+ tools=[final_answer,Get_Active_Fractions,get_fraction_members,get_kamerlid_reizen], ## the given tools
240
  max_steps=6,
241
  verbosity_level=1,
242
  grammar=None,