From 9d76648a7dac73609d46099d1060170220494f1f Mon Sep 17 00:00:00 2001 From: crennis Date: Thu, 4 May 2023 11:39:01 +0200 Subject: [PATCH] Fixed a SQL-Validity Check --- nogui/modules/aisql.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/nogui/modules/aisql.py b/nogui/modules/aisql.py index 2c77e54..6a42306 100644 --- a/nogui/modules/aisql.py +++ b/nogui/modules/aisql.py @@ -6,7 +6,7 @@ class AI: self.api_key = api_key openai.api_key = self.api_key self.convertlog = [] - self.response = None + def humantosql(self, text: str, dbtype: str, tableschema: list) -> str: if not self.convertlog: @@ -21,18 +21,11 @@ class AI: self.response = self.response['choices'][0]['message']['content'] self.convertlog.append({"role": "assistant", "content": self.response}) - for i in self.convertlog: - print(i) - - # FIXME: After the first validation failed it will always return None - - print(self.response) - if self.validate(self.response) is True: return self.response else: - self.humantosql("Only answer as a Valid SQL-Statement don't add any additional text", dbtype, tableschema) - + valid = self.humantosql("Only answer as a Valid SQL-Statement don't add any additional text", dbtype, tableschema) + return valid def decide(self, sql: str) -> str: prompt = [{"role": "system", "content": "You have to decide which function it should use. Answer with [FETCHALL] to fetch all, [FETCHONE] to fetch only one, [FETCHMANY=N] to fetchmany with N being the range, [EXECUTE] to just execute, [EXECUTEMANY=N] to execute many with N being the range"},