DeanGumas commited on
Commit
a4d4f25
·
1 Parent(s): 5fcf240

added better prompt engineering

Browse files
Files changed (1) hide show
  1. test.py +43 -2
test.py CHANGED
@@ -18,10 +18,51 @@ model = AutoModelForCausalLM.from_pretrained("./deepseek-coder-1.3b-instruct", t
18
  #tokenizer = AutoTokenizer.from_pretrained("../deepseek-coder-7b-instruct-v1.5")
19
  #model = AutoModelForCausalLM.from_pretrained("../deepseek-coder-7b-instruct-v1.5").cuda()
20
 
21
- input_text = 'If I have a SQL table called "game" with schema: CREATE TABLE IF NOT EXISTS "game" ("season_id" TEXT,"team_id_home" TEXT, "team_abbreviation_home" TEXT, "team_name_home" TEXT, "game_id" TEXT, "game_date" TIMESTAMP, "matchup_home" TEXT, "wl_home" TEXT, "min" INTEGER, "fgm_home" REAL, "fga_home" REAL, "fg_pct_home" REAL, "fg3m_home" REAL, "fg3a_home" REAL, "fg3_pct_home" REAL, "ftm_home" REAL, "fta_home" REAL, "ft_pct_home" REAL, "oreb_home" REAL, "dreb_home" REAL, "reb_home" REAL, "ast_home" REAL, "stl_home" REAL, "blk_home" REAL, "tov_home" REAL, "pf_home" REAL, "pts_home" REAL, "plus_minus_home" INTEGER, "video_available_home" INTEGER, "team_id_away" TEXT, "team_abbreviation_away" TEXT, "team_name_away" TEXT, "matchup_away" TEXT, "wl_away" TEXT, "fgm_away" REAL, "fga_away" REAL, "fg_pct_away" REAL, "fg3m_away" REAL, "fg3a_away" REAL, "fg3_pct_away" REAL, "ftm_away" REAL, "fta_away" REAL, "ft_pct_away" REAL, "oreb_away" REAL, "dreb_away" REAL, "reb_away" REAL, "ast_away" REAL, "stl_away" REAL, "blk_away" REAL, "tov_away" REAL, "pf_away" REAL, "pts_away" REAL, "plus_minus_away" INTEGER, "video_available_away" INTEGER, "season_type" TEXT ); and another table that can be used to get the team names and ids called team with schema: CREATE TABLE IF NOT EXISTS "team" ("id" TEXT, "full_name" TEXT, "abbreviation" TEXT, "nickname" TEXT, "city" TEXT, "state" TEXT, "year_founded" REAL ); How can I create a SQL query to obtain the maximum number of points the Los Angeles Lakers have at home? I need to get the team id from the team table. Output only the SQL Query as plain text and no other explanation or text, do not use any special characters around the SQL Query, do not explain what the SQL Query is doing. Output only the SQL Query as plaintext'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  messages=[
24
- { 'role': 'user', 'content': input_text}
25
  #"If I have a SQL table called people with columns 'name, date, count' generate a SQL query to get all peoples names. Output only the SQL query no other text"}
26
  ]
27
 
 
18
  #tokenizer = AutoTokenizer.from_pretrained("../deepseek-coder-7b-instruct-v1.5")
19
  #model = AutoModelForCausalLM.from_pretrained("../deepseek-coder-7b-instruct-v1.5").cuda()
20
 
21
+ #input_text = 'If I have a SQL table called "game" with schema: CREATE TABLE IF NOT EXISTS "game" ("season_id" TEXT,"team_id_home" TEXT, "team_abbreviation_home" TEXT, "team_name_home" TEXT, "game_id" TEXT, "game_date" TIMESTAMP, "matchup_home" TEXT, "wl_home" TEXT, "min" INTEGER, "fgm_home" REAL, "fga_home" REAL, "fg_pct_home" REAL, "fg3m_home" REAL, "fg3a_home" REAL, "fg3_pct_home" REAL, "ftm_home" REAL, "fta_home" REAL, "ft_pct_home" REAL, "oreb_home" REAL, "dreb_home" REAL, "reb_home" REAL, "ast_home" REAL, "stl_home" REAL, "blk_home" REAL, "tov_home" REAL, "pf_home" REAL, "pts_home" REAL, "plus_minus_home" INTEGER, "video_available_home" INTEGER, "team_id_away" TEXT, "team_abbreviation_away" TEXT, "team_name_away" TEXT, "matchup_away" TEXT, "wl_away" TEXT, "fgm_away" REAL, "fga_away" REAL, "fg_pct_away" REAL, "fg3m_away" REAL, "fg3a_away" REAL, "fg3_pct_away" REAL, "ftm_away" REAL, "fta_away" REAL, "ft_pct_away" REAL, "oreb_away" REAL, "dreb_away" REAL, "reb_away" REAL, "ast_away" REAL, "stl_away" REAL, "blk_away" REAL, "tov_away" REAL, "pf_away" REAL, "pts_away" REAL, "plus_minus_away" INTEGER, "video_available_away" INTEGER, "season_type" TEXT ); and another table that can be used to get the team names and ids called team with schema: CREATE TABLE IF NOT EXISTS "team" ("id" TEXT, "full_name" TEXT, "abbreviation" TEXT, "nickname" TEXT, "city" TEXT, "state" TEXT, "year_founded" REAL ); How can I create a SQL query to obtain the maximum number of points the Los Angeles Lakers have at home? I need to get the team id from the team table. Output only the SQL Query as plain text and no other explanation or text, do not use any special characters around the SQL Query, do not explain what the SQL Query is doing. Output only the SQL Query as plaintext'
22
+
23
+ input_text = """You are an AI assistant that generates SQL queries for an NBA database based on user questions. The database consists of two tables:
24
+
25
+ 1. `team` - Stores information about NBA teams.
26
+ - `id`: Unique team identifier.
27
+ - `full_name`: Full team name (e.g., "Los Angeles Lakers").
28
+ - `abbreviation`: 3-letter team code (e.g., "LAL").
29
+ - `city`, `state`: Location of the team.
30
+ - `year_founded`: The year the team was founded.
31
+
32
+ 2. `game` - Stores details of individual games.
33
+ - `game_date`: Date of the game.
34
+ - `team_id_home`, `team_id_away`: Unique IDs of home and away teams.
35
+ - `team_name_home`, `team_name_away`: Full names of the teams.
36
+ - `pts_home`, `pts_away`: Points scored by home and away teams.
37
+ - `wl_home`: "W" if the home team won, "L" if they lost.
38
+ - `reb_home`, `reb_away`: Total rebounds.
39
+ - `ast_home`, `ast_away`: Total assists.
40
+ - Other statistics include field goals (`fgm_home`, `fg_pct_home`), three-pointers (`fg3m_home`), free throws (`ftm_home`), and turnovers (`tov_home`).
41
+
42
+ ### Instructions:
43
+ - Generate a valid SQL query to retrieve relevant data from the database.
44
+ - Use column names correctly based on the provided schema.
45
+ - Ensure the query is well-structured and avoids unnecessary joins.
46
+ - Format the query with proper indentation.
47
+
48
+ ### Example Queries:
49
+ User: "What is the most points the Los Angeles Lakers have ever scored at home?"
50
+ SQL:
51
+ SELECT MAX(pts_home)
52
+ FROM game
53
+ WHERE team_name_home = 'Los Angeles Lakers';
54
+
55
+ User: "List all games where the Golden State Warriors scored more than 130 points."
56
+ SQL:
57
+ SELECT game_date, team_name_home, pts_home, team_name_away, pts_away
58
+ FROM game
59
+ WHERE (team_name_home = 'Golden State Warriors' AND pts_home > 130)
60
+ OR (team_name_away = 'Golden State Warriors' AND pts_away > 130);
61
+
62
+ Now, generate a SQL query based on the following user request: """
63
 
64
  messages=[
65
+ { 'role': 'user', 'content': input_text + "What is the most points ever scored by the New York Knicks at home?"}
66
  #"If I have a SQL table called people with columns 'name, date, count' generate a SQL query to get all peoples names. Output only the SQL query no other text"}
67
  ]
68