File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 186186 };
187187
188188 try {
189+ // Get API key from localStorage
190+ const apiKey = localStorage .getItem (' openai_api_key' );
191+
192+ if (! apiKey ) {
193+ queryModalData .error = ' Please add your OpenAI API key in Settings to use the query feature.' ;
194+ queryModalData .isLoading = false ;
195+ return ;
196+ }
197+
189198 // Chart-specific prompts for SQL generation - use explicit SQL templates for guaranteed compatibility
190199 const leagueFilter = selectedDateRange === ' all' ? ' ' : ` AND div = '${selectedDateRange }' ` ;
191200
203212
204213 const prompt = prompts [chartType ] || ` Generate this exact SQL query: SELECT * FROM matches WHERE season = '${selectedSeason }' LIMIT 100 ` ;
205214
206- // Generate SQL using the RAG API
215+ // Generate SQL using the RAG API with API key
207216 const queryResponse = await apiService .convertToSQL ({
208217 question: prompt ,
209- season: selectedSeason
218+ season: selectedSeason ,
219+ api_key: apiKey
210220 });
211221
212222 queryModalData .sql = queryResponse .sql ;
You can’t perform that action at this time.
0 commit comments