dvwn commited on
Commit
31c1d8c
·
1 Parent(s): 7ce8a1d

Folder and Files Structure Refactor

Browse files
.env DELETED
@@ -1 +0,0 @@
1
- HF_TOKEN='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'
 
 
.gitignore → backend/.gitignore RENAMED
File without changes
{app → backend/app}/main.py RENAMED
@@ -2,8 +2,8 @@
2
  # Main entry point for the NL2SQL application
3
  import os
4
  from dotenv import load_dotenv
5
- from src.scripts.interactive_mode import run_interactiveMode
6
- from src.scripts.evaluation_mode import run_evaluation
7
 
8
  load_dotenv()
9
  # Load HuggingFace API token from environment variable
 
2
  # Main entry point for the NL2SQL application
3
  import os
4
  from dotenv import load_dotenv
5
+ from backend.src.scripts.interactive_mode import run_interactiveMode
6
+ from backend.src.scripts.evaluation_mode import run_evaluation
7
 
8
  load_dotenv()
9
  # Load HuggingFace API token from environment variable
hf_evaluation_results.json → backend/hf_evaluation_results.json RENAMED
File without changes
hf_test_bench.py → backend/hf_test_bench.py RENAMED
@@ -1,6 +1,6 @@
1
  # Test the Hugging Face inference
2
- from src.nl2sql.hf_engine import generate_sql
3
- from src.database.db_manager import get_db_connection, get_schema_context
4
  import pandas as pd
5
 
6
  def test_single_query():
 
1
  # Test the Hugging Face inference
2
+ from backend.src.nl2sql.hf_engine import generate_sql
3
+ from backend.src.database.db_manager import get_db_connection, get_schema_context
4
  import pandas as pd
5
 
6
  def test_single_query():
requirements.txt → backend/requirements.txt RENAMED
File without changes
{src → backend/src}/database/Chinook_Sqlite.sqlite RENAMED
File without changes
{src → backend/src}/database/db_manager.py RENAMED
File without changes
{src → backend/src}/nl2sql/hf_engine.py RENAMED
File without changes
{src → backend/src}/nl2sql/qwen_engine.py RENAMED
File without changes
{src → backend/src}/nl2sql/sql_agent.py RENAMED
@@ -1,8 +1,8 @@
1
  # Path: src/nl2sql/sql_agent.py
2
  # SQL Agent for handling NL2SQL conversion with Auto-Correct functionality
3
- from src.database.db_manager import get_db_connection, get_schema_context
4
  from langchain_core.prompts import PromptTemplate
5
- from src.nl2sql.hf_engine import get_llm
6
 
7
  # Craft the Prompt Template to instruct LLM on its persona
8
  SQL_PROMPT_TEMPLATE = """You are an expert SQLite developer.
 
1
  # Path: src/nl2sql/sql_agent.py
2
  # SQL Agent for handling NL2SQL conversion with Auto-Correct functionality
3
+ from backend.src.database.db_manager import get_db_connection, get_schema_context
4
  from langchain_core.prompts import PromptTemplate
5
+ from backend.src.nl2sql.hf_engine import get_llm
6
 
7
  # Craft the Prompt Template to instruct LLM on its persona
8
  SQL_PROMPT_TEMPLATE = """You are an expert SQLite developer.
{src → backend/src}/scripts/evaluate.py RENAMED
@@ -2,8 +2,8 @@
2
 
3
  import json
4
  import pandas as pd
5
- from src.database.db_manager import get_db_connection, get_schema_context
6
- from src.nl2sql.qwen_engine import query_qwen, build_qwen_prompt
7
 
8
  def compare_results(df_generated_sql, df_gold_sql):
9
  """Compares the generated SQL query with the expected SQL query."""
 
2
 
3
  import json
4
  import pandas as pd
5
+ from backend.src.database.db_manager import get_db_connection, get_schema_context
6
+ from backend.src.nl2sql.qwen_engine import query_qwen, build_qwen_prompt
7
 
8
  def compare_results(df_generated_sql, df_gold_sql):
9
  """Compares the generated SQL query with the expected SQL query."""
{src → backend/src}/scripts/evaluation_mode.py RENAMED
@@ -3,8 +3,8 @@
3
  import json
4
  from pathlib import Path
5
  import pandas as pd
6
- from src.database.db_manager import get_db_connection
7
- from src.nl2sql.sql_agent import nl2sql_agent
8
 
9
  TEST_CASES_PATH = Path("src/scripts/test_cases.json")
10
  RESULTS_PATH = Path("hf_evaluation_results.json")
 
3
  import json
4
  from pathlib import Path
5
  import pandas as pd
6
+ from backend.src.database.db_manager import get_db_connection
7
+ from backend.src.nl2sql.sql_agent import nl2sql_agent
8
 
9
  TEST_CASES_PATH = Path("src/scripts/test_cases.json")
10
  RESULTS_PATH = Path("hf_evaluation_results.json")
{src → backend/src}/scripts/interactive_mode.py RENAMED
@@ -1,6 +1,6 @@
1
  # Path: src/scripts/interactive_mode.py
2
  # Interactive mode: Allows user to manually type questions and see the agent's response
3
- from src.nl2sql.sql_agent import nl2sql_agent
4
 
5
  def run_interactiveMode():
6
  """ Allows user to manually type questions and get agent's response."""
 
1
  # Path: src/scripts/interactive_mode.py
2
  # Interactive mode: Allows user to manually type questions and see the agent's response
3
+ from backend.src.nl2sql.sql_agent import nl2sql_agent
4
 
5
  def run_interactiveMode():
6
  """ Allows user to manually type questions and get agent's response."""
{src → backend/src}/scripts/test_cases.json RENAMED
File without changes
evaluation_results.json DELETED
@@ -1,72 +0,0 @@
1
- [
2
- {
3
- "id": 1,
4
- "status": "ERROR: Execution failed on sql 'SELECT t.Genre, COUNT(t.TrackId) AS TrackCount FROM Track t GROUP BY t.Genre;': no such column: t.Genre"
5
- },
6
- {
7
- "id": 2,
8
- "status": "PASS",
9
- "generated": "SELECT t1.Title, ar.Name FROM Album AS t1 INNER JOIN Artist AS ar ON t1.ArtistId = ar.ArtistId;"
10
- },
11
- {
12
- "id": 3,
13
- "status": "ERROR: Execution failed on sql 'SELECT T4.Country, SUM(T3.UnitPrice * T3.Quantity) as TotalRevenue\nFROM InvoiceLine AS T1\nJOIN Track AS T2 ON T1.TrackId = T2.TrackId\nJOIN Album AS T3 ON T2.AlbumId = T3.AlbumId\nJOIN Genre AS T4 ON T2.GenreId = T4.GenreId\nGROUP BY T4.Country;': no such column: T4.Country"
14
- },
15
- {
16
- "id": 4,
17
- "status": "ERROR: Execution failed on sql 'SELECT e.FirstName, e.LastName FROM Employee AS e JOIN Customer AS c ON e.SupportRepId = c.CustomerId WHERE c.Company LIKE 'Sales Support';': no such column: e.SupportRepId"
18
- },
19
- {
20
- "id": 5,
21
- "status": "FAIL",
22
- "generated": "SELECT c.FirstName, c.LastName, SUM(il.UnitPrice * il.Quantity) as TotalSpent\nFROM Customer c\nJOIN Invoice i ON c.CustomerId = i.CustomerId\nJOIN InvoiceLine il ON i.InvoiceId = il.InvoiceId\nGROUP BY c.CustomerId\nORDER BY TotalSpent DESC\nLIMIT 5;"
23
- },
24
- {
25
- "id": 6,
26
- "status": "FAIL",
27
- "generated": "SELECT T3.Name AS ArtistName, T1.Name AS SongName\nFROM Track AS T1\nJOIN Album AS T2 ON T1.AlbumId = T2.AlbumId\nJOIN Genre AS T3 ON T1.GenreId = T3.GenreId\nWHERE T3.Name = 'Rock'\nGROUP BY T1.TrackId;"
28
- },
29
- {
30
- "id": 7,
31
- "status": "ERROR: Execution failed on sql 'SELECT T3.Name AS MediaTypeName, COUNT(T1.TrackId) AS TotalTracksSold\nFROM Track AS T1\nJOIN MediaType AS T2 ON T1.MediaTypeId = T2.MediaTypeId\nGROUP BY T2.Name;': no such column: T3.Name"
32
- },
33
- {
34
- "id": 8,
35
- "status": "PASS",
36
- "generated": "SELECT T3.Name FROM Playlist AS T1 INNER JOIN PlaylistTrack AS T2 ON T1.PlaylistId = T2.PlaylistId INNER JOIN Track AS T3 ON T2.TrackId = T3.TrackId WHERE T1.Name = 'TV Shows';"
37
- },
38
- {
39
- "id": 9,
40
- "status": "PASS",
41
- "generated": "SELECT a.Name, COUNT(t.TrackId) AS TrackCount\nFROM Artist a\nJOIN Album ar ON a.ArtistId = ar.ArtistId\nJOIN Track t ON ar.AlbumId = t.AlbumId\nGROUP BY a.ArtistId\nORDER BY TrackCount DESC\nLIMIT 1;"
42
- },
43
- {
44
- "id": 10,
45
- "status": "FAIL",
46
- "generated": "SELECT g.Name FROM Genre g JOIN Track t ON g.GenreId = t.GenreId GROUP BY g.Name HAVING COUNT(t.TrackId) > 100;"
47
- },
48
- {
49
- "id": 11,
50
- "status": "FAIL",
51
- "generated": "SELECT a.Name, SUM(il.UnitPrice * il.Quantity) as TotalRevenue\nFROM Artist a\nJOIN Album al ON a.ArtistId = al.ArtistId\nJOIN Track tr ON al.AlbumId = tr.AlbumId\nJOIN InvoiceLine il ON tr.TrackId = il.TrackId\nGROUP BY a.ArtistId\nORDER BY TotalRevenue DESC\nLIMIT 1;"
52
- },
53
- {
54
- "id": 12,
55
- "status": "FAIL",
56
- "generated": "SELECT a.Title, AVG(t.Milliseconds) / 1000 AS AverageLengthInSeconds\nFROM Album a\nJOIN Track t ON a.AlbumId = t.AlbumId\nGROUP BY a.AlbumId;"
57
- },
58
- {
59
- "id": 13,
60
- "status": "PASS",
61
- "generated": "SELECT c.FirstName, c.LastName, e.FirstName, e.LastName\nFROM Customer c\nJOIN Employee e ON c.SupportRepId = e.EmployeeId\nWHERE e.LastName = 'Peacock';"
62
- },
63
- {
64
- "id": 14,
65
- "status": "PASS",
66
- "generated": "SELECT t2.City FROM Invoice AS t1 INNER JOIN Customer AS t2 ON t1.CustomerId = t2.CustomerId WHERE strftime('%Y', t1.InvoiceDate) = '2013' GROUP BY t2.City ORDER BY COUNT(*) DESC LIMIT 1;"
67
- },
68
- {
69
- "id": 15,
70
- "status": "ERROR: Execution failed on sql 'SELECT T1.Title FROM Album AS T1 INNER JOIN InvoiceLine AS T2 ON T1.AlbumId = T2.AlbumId GROUP BY T1.AlbumId HAVING SUM(T2.UnitPrice * T2.Quantity) > 20;': no such column: T2.AlbumId"
71
- }
72
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontend/App.vue ADDED
File without changes
src/database/__pycache__/db_manager.cpython-313.pyc DELETED
Binary file (3.88 kB)
 
src/nl2sql/__pycache__/hf_engine.cpython-313.pyc DELETED
Binary file (2.41 kB)
 
src/nl2sql/__pycache__/qwen_engine.cpython-313.pyc DELETED
Binary file (2.4 kB)
 
src/scripts/__pycache__/evaluate.cpython-313.pyc DELETED
Binary file (3.31 kB)
 
src/scripts/__pycache__/evaluate_hf.cpython-313.pyc DELETED
Binary file (5.03 kB)
 
test_bench.py DELETED
@@ -1,36 +0,0 @@
1
- # Test the database connection and schema extraction
2
-
3
- import pandas as pd
4
- from src.database.db_manager import get_db_connection, get_schema_context
5
- from src.nl2sql.qwen_engine import query_qwen, build_qwen_prompt
6
-
7
- def run_test(question):
8
- print(f"\n[USER QUESTION]: {question}")
9
-
10
- # Step 1: Get the database schema context from db_manager
11
- schema = get_schema_context()
12
-
13
- # Step 2: Build the prompt and Generate SQL query
14
- prompt = build_qwen_prompt(question, schema)
15
- generated_sql = query_qwen(prompt)
16
- print(f"\n[GENERATED SQL]:\n{generated_sql}")
17
-
18
- # Step 3: Execute the generated SQL query against the database
19
- try:
20
- connection = get_db_connection()
21
- # Use pandas to execute the SQL query and display results
22
- result_df = pd.read_sql_query(generated_sql, connection)
23
- connection.close()
24
-
25
- print("[EXECUTION SUCCESS]:")
26
- if result_df.empty:
27
- print("Query returned no results.")
28
- else:
29
- print(result_df.head(5)) # Display the first 5 rows of the result
30
- except Exception as e:
31
- print(f"[EXECUTION ERROR]: {e}")
32
-
33
- if __name__ == "__main__":
34
- # Example test question
35
- test_question = "What is the total revenue generated from each country?"
36
- run_test(test_question)