Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,13 +13,17 @@ initialize_database()
|
|
13 |
@tool
|
14 |
def sql_engine(query: str) -> str:
|
15 |
"""
|
16 |
-
Executes an SQL SELECT query
|
17 |
|
18 |
-
|
19 |
-
query (str): The SQL query
|
20 |
|
21 |
Returns:
|
22 |
-
str:
|
|
|
|
|
|
|
|
|
23 |
"""
|
24 |
try:
|
25 |
with engine.connect() as con:
|
@@ -30,11 +34,6 @@ def sql_engine(query: str) -> str:
|
|
30 |
except Exception as e:
|
31 |
return f"Error: {str(e)}"
|
32 |
|
33 |
-
# Initialize CodeAgent for SQL query generation
|
34 |
-
agent = CodeAgent(
|
35 |
-
tools=[sql_engine],
|
36 |
-
model=HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
|
37 |
-
)
|
38 |
|
39 |
# Function to execute an uploaded SQL script
|
40 |
def execute_sql_script(file_path):
|
|
|
13 |
@tool
|
14 |
def sql_engine(query: str) -> str:
|
15 |
"""
|
16 |
+
Executes an SQL SELECT query and returns the results.
|
17 |
|
18 |
+
Parameters:
|
19 |
+
query (str): The SQL query string that should be executed.
|
20 |
|
21 |
Returns:
|
22 |
+
str: The result of the SQL query formatted as a string.
|
23 |
+
|
24 |
+
Example:
|
25 |
+
>>> sql_engine("SELECT * FROM users")
|
26 |
+
'1, Alice, 30, 100.50\\n2, Bob, 24, 250.75\\n3, Charlie, 35, 80.00'
|
27 |
"""
|
28 |
try:
|
29 |
with engine.connect() as con:
|
|
|
34 |
except Exception as e:
|
35 |
return f"Error: {str(e)}"
|
36 |
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Function to execute an uploaded SQL script
|
39 |
def execute_sql_script(file_path):
|