(self, input_dict, mode)
| 387 | return input_dict |
| 388 | |
| 389 | def step_get_sql(self, input_dict, mode): |
| 390 | limitation = ",".join(input_dict["ner_results"]["limitation"]) |
| 391 | metric = ",".join(input_dict["ner_results"]["metric"]) |
| 392 | main_metric = input_dict["ner_results"]["query"] |
| 393 | few_shots = input_dict["few_shots"] |
| 394 | query = input_dict["query"] |
| 395 | |
| 396 | if self.question_type == QuestionType.EASY.value: |
| 397 | table_info_sql = input_dict["table_info"] |
| 398 | else: |
| 399 | table_info_sql = input_dict["add_table_info"] |
| 400 | # Pre-prompt is empty |
| 401 | input_dict["suggestions"] = "" |
| 402 | sc_results = self.get_sql_by_llm(query, table_info_sql, limitation, metric, |
| 403 | main_metric, input_dict["suggestions"], few_shots) |
| 404 | input_dict["init_sql_results"] = sc_results[0] |
| 405 | input_dict["sql_results"] = {} |
| 406 | |
| 407 | # self-check |
| 408 | if input_dict["init_sql_results"].get("sql", "") != "": |
| 409 | init_sql = input_dict["init_sql_results"]["sql"] |
| 410 | elif list(input_dict["init_sql_results"].values()): |
| 411 | init_sql = list(input_dict["init_sql_results"].values())[0] |
| 412 | elif input_dict["features"].get("sql", "") != "": |
| 413 | init_sql = input_dict["features"]["sql"] |
| 414 | else: |
| 415 | init_sql = "error" |
| 416 | input_dict["init_sql_results"]["sql"] = init_sql |
| 417 | try: |
| 418 | correct_sql = correct_sql_self(query, table_info_sql, init_sql) |
| 419 | except: |
| 420 | init_sql = "error" |
| 421 | correct_sql = correct_sql_self(query, table_info_sql, init_sql) |
| 422 | if "error" not in correct_sql: |
| 423 | input_dict["sql_results"]["sql"] = f"SELECT {correct_sql}" |
| 424 | |
| 425 | if mode == "debug": |
| 426 | print("---------------The result of sc is---------------------") |
| 427 | print(sc_results) |
| 428 | print("---------------The result of correct-sql is---------------------") |
| 429 | print(input_dict["sql_results"]) |
| 430 | |
| 431 | try: |
| 432 | final_sql = input_dict["init_sql_results"]["sql"] |
| 433 | except Exception as e: |
| 434 | print(f"1、Generated sql_results json parsing error:{e.__str__()}") |
| 435 | final_sql = "error" |
| 436 | |
| 437 | try: |
| 438 | if "CAST" in correct_sql: # trick |
| 439 | final_correct_sql = final_sql |
| 440 | else: |
| 441 | final_correct_sql = input_dict["sql_results"]["sql"] |
| 442 | except Exception as e: |
| 443 | print(f"2、Generated sql_results json parsing error:{e.__str__()}") |
| 444 | final_correct_sql = final_sql |
| 445 | |
| 446 | input_dict["sql_results"]["sql"] = final_correct_sql |
no test coverage detected