MCPcopy Create free account
hub / github.com/CL-lau/SQL-GPT / generateSQL

Method generateSQL

gpt/llm.py:136–149  ·  view source on GitHub ↗
(self, question: Optional[str], dbID: Optional[str], need_operate: Optional[bool] = False, only_sql: Optional[bool] = True)

Source from the content-addressed store, hash-verified

134 )
135
136 def generateSQL(self, question: Optional[str], dbID: Optional[str], need_operate: Optional[bool] = False, only_sql: Optional[bool] = True):
137 question = self.sql_prompt_template.format(question=question)
138
139 sql = self.llm.generate_response(input_text=question)
140
141 sql = self.processSQL(sql)
142
143 # only for update and select and insert
144 if need_operate:
145 operator_type = get_db_operation_class(sql)
146 if operator_type == SQL_class.SELECT or operator_type == SQL_class.INSERT:
147 result = self.sqlHelper.operate(sql=sql, dbID=dbID)
148 return sql, result
149 return sql
150
151 def SQL_ERROR_CHECK(self, sql: Optional[str], error: Optional[str], need_operate: Optional[bool] = False, only_sql: Optional[bool] = True, dbID: Optional[str] = None):
152 question = self.error_prompt_template.format(sql=sql, error=error, structure="")

Callers 1

sql_chatFunction · 0.95

Calls 4

processSQLMethod · 0.95
get_db_operation_classFunction · 0.90
generate_responseMethod · 0.80
operateMethod · 0.80

Tested by

no test coverage detected