Spaces:
Sleeping
Sleeping
File size: 3,522 Bytes
9b5b26a c19d193 6aae614 8fe992b 9b5b26a 6b1c2e6 75454ee 6b1c2e6 75454ee 6b1c2e6 75454ee 3533c1a 75454ee 6b1c2e6 75454ee 6b1c2e6 75454ee 9b5b26a 75454ee 6b1c2e6 9b5b26a 6b1c2e6 9b5b26a 6b1c2e6 9b5b26a ca455d7 ee9d643 6bad9e1 ee9d643 6bad9e1 ee9d643 8c01ffb 6aae614 ae7a494 e121372 bf6d34c 43f8032 fe328e0 13d500a 8c01ffb 861422e 9b5b26a 8c01ffb 8fe992b 6b1c2e6 8c01ffb 861422e 8fe992b 9b5b26a 8c01ffb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
import sqlite3
from datetime import datetime
# Connect to SQLite database. It will be created if it doesn't exist
conn = sqlite3.connect('employee_database.db')
cursor = conn.cursor()
# Create employees table with basic columns
cursor.execute('''
CREATE TABLE IF NOT EXISTS employees (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
job_title TEXT NOT NULL
)
''')
# Commit the transaction
conn.commit()
# Sample data for employees
employees_data = [
('John', 'Smith', 'Software Engineer'),
('Sarah', 'Johnson', 'Marketing Manager'),
('Michael', 'Brown', 'Data Scientist'),
('Emma', 'Wilson', 'Product Designer'),
('William', 'Davis', 'DevOps Engineer'),
('Olivia', 'Miller', 'UX Researcher'),
('James', 'Wilson', 'Backend Developer'),
('Jessica', 'Moore', 'Project Manager'),
('Robert', 'Taylor', 'Frontend Developer'),
('Lisa', 'Anderson', 'Quality Assurance'),
('Richard', 'Thomas', 'Technical Writer'),
('Amy', 'Jackson', 'Business Analyst'),
('Charles', 'White', 'Database Administrator'),
('Elizabeth', 'Harris', 'Customer Support'),
('Thomas', 'Martin', 'Network Engineer'),
('Jennifer', 'Thompson', 'HR Specialist'),
('Donald', 'Walker', 'Security Specialist'),
('Margaret', 'Young', 'Content Manager'),
('Ronald', 'Allen', 'Sales Representative'),
('Susan', 'Scott', 'Financial Analyst')
]
# Insert multiple records efficiently using executemany
cursor.executemany('''
INSERT INTO employees (first_name, last_name, job_title)
VALUES (?, ?, ?)
''', employees_data)
# Commit the transaction
conn.commit()
# Below is an example of a tool that does nothing. Amaze us with your creativity !
@tool
def get_employee_job_title(first_name:str, last_name:str)-> str: #it's import to specify the return type
"""A tool that allows to do a sqlite sql query based on first_name and last_name
Args:
first_name: the first argument
last_name: the second argument
"""
conn = sqlite3.connect('employee_database.db')
cursor = conn.cursor()
cursor.execute(f"SELECT job_title FROM employees WHERE first_name='{first_name}' AND last_name='{last_name}'")
rows = cursor.fetchall()
if len(rows) > 1:
return "Many employees with that name"
elif len(rows) == 0:
return "No employee with that name"
else:
row = rows[0][0]
return row
final_answer = FinalAnswerTool()
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
model = HfApiModel(
max_tokens=2096,
temperature=0.5,
model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/",
custom_role_conversions=None,
)
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[final_answer, get_employee_job_title], ## add your tools here (don't remove final answer)
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch() |