生成SQL语句
(self, question: str)
| 101 | return sql.strip() |
| 102 | |
| 103 | def _generate_sql(self, question: str) -> str: |
| 104 | """生成SQL语句""" |
| 105 | schema = self._get_schema() |
| 106 | prompt = get_few_shot_prompt( |
| 107 | question=question, |
| 108 | schema=schema, |
| 109 | num_examples=self.num_examples |
| 110 | ) |
| 111 | sql = self._llm_to_str(self.llm.invoke(prompt)).strip() |
| 112 | return self._clean_sql(sql) |
| 113 | |
| 114 | def _correct_sql(self, question: str, original_sql: str, error_msg: str, attempt: int) -> str: |
| 115 | """SQL 自动纠错(Reflection 模式) |
no test coverage detected