Spaces:
Running
Running
update
Browse files
app.py
CHANGED
@@ -7,31 +7,82 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
@tool
|
12 |
-
def
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
26 |
"""
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
@@ -55,7 +106,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[DuckDuckGoSearchTool(),
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
|
11 |
+
|
12 |
+
########### setup bd
|
13 |
+
|
14 |
+
from sqlalchemy import (
|
15 |
+
Column,
|
16 |
+
Float,
|
17 |
+
Integer,
|
18 |
+
MetaData,
|
19 |
+
String,
|
20 |
+
Table,
|
21 |
+
create_engine,
|
22 |
+
insert,
|
23 |
+
inspect,
|
24 |
+
text,
|
25 |
+
)
|
26 |
+
|
27 |
+
|
28 |
+
engine = create_engine("sqlite:///:memory:")
|
29 |
+
metadata_obj = MetaData()
|
30 |
+
|
31 |
+
# create city SQL table
|
32 |
+
table_name = "receipts"
|
33 |
+
receipts = Table(
|
34 |
+
table_name,
|
35 |
+
metadata_obj,
|
36 |
+
Column("receipt_id", Integer, primary_key=True),
|
37 |
+
Column("customer_name", String(16), primary_key=True),
|
38 |
+
Column("price", Float),
|
39 |
+
Column("tip", Float),
|
40 |
+
)
|
41 |
+
metadata_obj.create_all(engine)
|
42 |
+
|
43 |
+
rows = [
|
44 |
+
{"receipt_id": 1, "customer_name": "Alan Payne", "price": 12.06, "tip": 1.20},
|
45 |
+
{"receipt_id": 2, "customer_name": "Alex Mason", "price": 23.86, "tip": 0.24},
|
46 |
+
{"receipt_id": 3, "customer_name": "Woodrow Wilson", "price": 53.43, "tip": 5.43},
|
47 |
+
{"receipt_id": 4, "customer_name": "Margaret James", "price": 21.11, "tip": 1.00},
|
48 |
+
]
|
49 |
+
for row in rows:
|
50 |
+
stmt = insert(receipts).values(**row)
|
51 |
+
with engine.begin() as connection:
|
52 |
+
cursor = connection.execute(stmt)
|
53 |
+
|
54 |
+
inspector = inspect(engine)
|
55 |
+
columns_info = [(col["name"], col["type"]) for col in inspector.get_columns("receipts")]
|
56 |
+
|
57 |
+
table_description = "Columns:\n" + "\n".join([f" - {name}: {col_type}" for name, col_type in columns_info])
|
58 |
+
|
59 |
+
###########
|
60 |
+
|
61 |
+
|
62 |
+
###########
|
63 |
+
|
64 |
@tool
|
65 |
+
def sql_engine(query: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
66 |
"""
|
67 |
+
Allows you to perform SQL queries on the table. Returns a string representation of the result.
|
68 |
+
The table is named 'receipts'. Its description is as follows:
|
69 |
+
Columns:
|
70 |
+
- receipt_id: INTEGER
|
71 |
+
- customer_name: VARCHAR(16)
|
72 |
+
- price: FLOAT
|
73 |
+
- tip: FLOAT
|
74 |
|
|
|
|
|
|
|
75 |
Args:
|
76 |
+
query: The query to perform. This should be correct SQL.
|
77 |
"""
|
78 |
+
output = ""
|
79 |
+
with engine.connect() as con:
|
80 |
+
rows = con.execute(text(query))
|
81 |
+
for row in rows:
|
82 |
+
output += "\n" + str(row)
|
83 |
+
return output
|
84 |
+
|
85 |
+
###########
|
86 |
|
87 |
|
88 |
final_answer = FinalAnswerTool()
|
|
|
106 |
|
107 |
agent = CodeAgent(
|
108 |
model=model,
|
109 |
+
tools=[DuckDuckGoSearchTool(), sql_engine], ## add your tools here (don't remove final answer)
|
110 |
max_steps=6,
|
111 |
verbosity_level=1,
|
112 |
grammar=None,
|