Update app.py
Browse files
app.py
CHANGED
|
@@ -7,58 +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
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
"""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
Main Ingredients: Lemon juice, lemon zest, sugar, rum or vodka
|
| 24 |
-
|
| 25 |
-
Directions: In a large saucepan, combine sugar, water and lemon zest.
|
| 26 |
-
Cook and stir until the sugar is dissolved.
|
| 27 |
-
Refrigerate until chilled.
|
| 28 |
-
Stir in rum or vodka and serve over ice.
|
| 29 |
-
"""
|
| 30 |
-
elif "Red Sangria" in arg1:
|
| 31 |
-
output="""
|
| 32 |
-
This sangria is perfect for relaxed get-togethers.
|
| 33 |
-
It’s a great make-ahead recipe, as it tastes even better if you let the flavors steep overnight.
|
| 34 |
-
|
| 35 |
-
Main Ingredients: Red wine, orange liqueur, brandy, sliced fruit
|
| 36 |
-
|
| 37 |
-
Directions: In a pitcher, stir together red wine, orange liqueur and brandy.
|
| 38 |
-
If desired, add sugar and stir until the sugar has dissolved.
|
| 39 |
-
Stir in sliced fruit and serve over ice.
|
| 40 |
-
"""
|
| 41 |
-
elif "Chocolate Martini" in arg1:
|
| 42 |
-
output="""
|
| 43 |
-
Is it a beverage or a dessert?
|
| 44 |
-
No matter how you classify it, we can all agree it’s downright tasty.
|
| 45 |
-
|
| 46 |
-
Main Ingredients: Half-and-half cream, vodka, chocolate liqueur, creme de cacao
|
| 47 |
-
|
| 48 |
-
Directions: If desired, give your martini glass a chocolate rim and drizzle chocolate syrup in the glass.
|
| 49 |
-
Then, fill a cocktail shaker with ice.
|
| 50 |
-
Add half-and-half cream, vodka, chocolate liqueur and creme de cacao. Stir,
|
| 51 |
-
then strain into a martini glass.
|
| 52 |
-
"""
|
| 53 |
-
else:
|
| 54 |
-
output="""
|
| 55 |
-
Lassi is an indian drink.
|
| 56 |
-
|
| 57 |
-
Main Ingredinents: Curd, sugar
|
| 58 |
-
|
| 59 |
-
Directions: Put curd and sugar in blender and stear for five minutes and a delicious drink is ready.
|
| 60 |
-
"""
|
| 61 |
-
|
| 62 |
return output
|
| 63 |
|
| 64 |
@tool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from sqlalchemy import (
|
| 11 |
+
create_engine,
|
| 12 |
+
MetaData,
|
| 13 |
+
Table,
|
| 14 |
+
Column,
|
| 15 |
+
String,
|
| 16 |
+
Integer,
|
| 17 |
+
Float,
|
| 18 |
+
insert,
|
| 19 |
+
inspect,
|
| 20 |
+
text,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
engine = create_engine("sqlite:///:memory:")
|
| 24 |
+
metadata_obj = MetaData()
|
| 25 |
+
|
| 26 |
+
# create city SQL table
|
| 27 |
+
table_name = "receipts"
|
| 28 |
+
receipts = Table(
|
| 29 |
+
table_name,
|
| 30 |
+
metadata_obj,
|
| 31 |
+
Column("receipt_id", Integer, primary_key=True),
|
| 32 |
+
Column("customer_name", String(16), primary_key=True),
|
| 33 |
+
Column("price", Float),
|
| 34 |
+
Column("tip", Float),
|
| 35 |
+
)
|
| 36 |
+
metadata_obj.create_all(engine)
|
| 37 |
+
|
| 38 |
+
rows = [
|
| 39 |
+
{"receipt_id": 1, "customer_name": "Alan Payne", "price": 12.06, "tip": 1.20},
|
| 40 |
+
{"receipt_id": 2, "customer_name": "Alex Mason", "price": 23.86, "tip": 0.24},
|
| 41 |
+
{"receipt_id": 3, "customer_name": "Woodrow Wilson", "price": 53.43, "tip": 5.43},
|
| 42 |
+
{"receipt_id": 4, "customer_name": "Margaret James", "price": 21.11, "tip": 1.00},
|
| 43 |
+
]
|
| 44 |
+
for row in rows:
|
| 45 |
+
stmt = insert(receipts).values(**row)
|
| 46 |
+
with engine.begin() as connection:
|
| 47 |
+
cursor = connection.execute(stmt)
|
| 48 |
+
|
| 49 |
+
inspector = inspect(engine)
|
| 50 |
+
columns_info = [(col["name"], col["type"]) for col in inspector.get_columns("receipts")]
|
| 51 |
+
|
| 52 |
+
table_description = "Columns:\n" + "\n".join([f" - {name}: {col_type}" for name, col_type in columns_info])
|
| 53 |
+
print(table_description)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 57 |
@tool
|
| 58 |
+
def sql_engine(query: str) -> str:
|
| 59 |
+
"""
|
| 60 |
+
Allows you to perform SQL queries on the table. Returns a string representation of the result.
|
| 61 |
+
The table is named 'receipts'. Its description is as follows:
|
| 62 |
+
Columns:
|
| 63 |
+
- receipt_id: INTEGER
|
| 64 |
+
- customer_name: VARCHAR(16)
|
| 65 |
+
- price: FLOAT
|
| 66 |
+
- tip: FLOAT
|
| 67 |
+
|
| 68 |
Args:
|
| 69 |
+
query: The query to perform. This should be correct SQL.
|
| 70 |
"""
|
| 71 |
+
output = ""
|
| 72 |
+
with engine.connect() as con:
|
| 73 |
+
rows = con.execute(text(query))
|
| 74 |
+
for row in rows:
|
| 75 |
+
output += "\n" + str(row)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
return output
|
| 77 |
|
| 78 |
@tool
|