pgabrys commited on
Commit
6b1c2e6
·
verified ·
1 Parent(s): ae7a494

Add sqlite tool

Browse files
Files changed (1) hide show
  1. app.py +63 -23
app.py CHANGED
@@ -7,32 +7,72 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
- @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
- Args:
16
- arg1: the first argument
17
- arg2: the second argument
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.
 
 
24
  Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
26
  """
27
- try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
33
- except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
-
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -55,7 +95,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ import sqlite3
11
+ from datetime import datetime
12
+
13
+
14
+ # Connect to SQLite database. It will be created if it doesn't exist
15
+ conn = sqlite3.connect('employee_database.db')
16
+ cursor = conn.cursor()
17
+
18
+ # Create employees table with basic columns
19
+ cursor.execute('''
20
+ CREATE TABLE IF NOT EXISTS employees (
21
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
22
+ first_name TEXT NOT NULL,
23
+ last_name TEXT NOT NULL,
24
+ job_title TEXT NOT NULL
25
+ )
26
+ ''')
27
+
28
+ # Commit the transaction
29
+ conn.commit()
30
+
31
+ # Sample data for employees
32
+ employees_data = [
33
+ ('John', 'Smith', 'Software Engineer'),
34
+ ('Sarah', 'Johnson', 'Marketing Manager'),
35
+ ('Michael', 'Brown', 'Data Scientist'),
36
+ ('Emma', 'Wilson', 'Product Designer'),
37
+ ('William', 'Davis', 'DevOps Engineer'),
38
+ ('Olivia', 'Miller', 'UX Researcher'),
39
+ ('James', 'Wilson', 'Backend Developer'),
40
+ ('Jessica', 'Moore', 'Project Manager'),
41
+ ('Robert', 'Taylor', 'Frontend Developer'),
42
+ ('Lisa', 'Anderson', 'Quality Assurance'),
43
+ ('Richard', 'Thomas', 'Technical Writer'),
44
+ ('Amy', 'Jackson', 'Business Analyst'),
45
+ ('Charles', 'White', 'Database Administrator'),
46
+ ('Elizabeth', 'Harris', 'Customer Support'),
47
+ ('Thomas', 'Martin', 'Network Engineer'),
48
+ ('Jennifer', 'Thompson', 'HR Specialist'),
49
+ ('Donald', 'Walker', 'Security Specialist'),
50
+ ('Margaret', 'Young', 'Content Manager'),
51
+ ('Ronald', 'Allen', 'Sales Representative'),
52
+ ('Susan', 'Scott', 'Financial Analyst')
53
+ ]
54
+
55
+ # Insert multiple records efficiently using executemany
56
+ cursor.executemany('''
57
+ INSERT INTO employees (first_name, last_name, job_title)
58
+ VALUES (?, ?, ?)
59
+ ''', employees_data)
60
 
61
+ # Commit the transaction
62
+ conn.commit()
63
+
64
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
65
  @tool
66
+ def get_employee_job_title(first_name:str, last_name:str)-> str: #it's import to specify the return type
67
+ conn = sqlite3.connect('employee_database.db')
68
+ cursor = conn.cursor()
69
+ """A tool that allows to do a sqlite sql query based on first_name and last_name
70
  Args:
71
+ first_name: the first argument
72
+ last_name: the second argument
73
  """
74
+ return cursor.execute(f"SELECT job_title FROM employees WHERE first_name='{first_name}' AND last_name='{last_name}'")
75
+ rows = cursor.fetchall()[0][0]
 
 
 
 
 
 
 
76
 
77
  final_answer = FinalAnswerTool()
78
 
 
95
 
96
  agent = CodeAgent(
97
  model=model,
98
+ tools=[final_answer, get_employee_job_title], ## add your tools here (don't remove final answer)
99
  max_steps=6,
100
  verbosity_level=1,
101
  grammar=None,