Spaces:
Runtime error
Runtime error
Commit ·
ff7bbd5
1
Parent(s): 5747d78
Update queryHelperManagerCoT.py
Browse files- queryHelperManagerCoT.py +14 -1
queryHelperManagerCoT.py
CHANGED
|
@@ -57,13 +57,16 @@ class QueryHelperChainOfThought:
|
|
| 57 |
return extracted_json
|
| 58 |
|
| 59 |
def getQueryForUserInputCoT(self, userInput):
|
|
|
|
|
|
|
| 60 |
#1. Is the input complete to create a query, or ask user to reask with more detailed input
|
| 61 |
systemPromptForInputClarification = """Given an input text, user want to generate sql query. Please answer if the user input is complete or user needs to ask in more detailed way. Answer in following format. 'Yes' ; if yes, break the userinput into smaller subtask for query generation. Formatted into
|
| 62 |
{
|
| 63 |
"Task 1": "task 1 description",
|
| 64 |
"Task 2": "task 2 description"
|
| 65 |
}
|
| 66 |
-
'No' ; if no, then Reason- please be more detailed about customer details; if more modification needed"""
|
|
|
|
| 67 |
cotStep1 = self.gptInstance.getResponseForUserInput(userInput, systemPromptForInputClarification)
|
| 68 |
if "yes" in cotStep1.lower()[:5]:
|
| 69 |
print("User input sufficient")
|
|
@@ -139,4 +142,14 @@ ORDER BY chandelier_count DESC"""
|
|
| 139 |
for idx, tableName in enumerate(selectedTablesAndCols.keys(), start=1):
|
| 140 |
prompt += f"table name {tableName} {', '.join(selectedTablesAndCols[tableName])}"
|
| 141 |
prompt += "XXXX"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
return prompt.replace("\n"," ").replace("\\"," ").replace(" "," ").replace("XXXX", " ")
|
|
|
|
| 57 |
return extracted_json
|
| 58 |
|
| 59 |
def getQueryForUserInputCoT(self, userInput):
|
| 60 |
+
selectedTablesAndCols = self.metadataLayout.getSelectedTablesAndCols()
|
| 61 |
+
systemPromptTail = self.getSystemPromptTailForCoTStep1(selectedTablesAndCols)
|
| 62 |
#1. Is the input complete to create a query, or ask user to reask with more detailed input
|
| 63 |
systemPromptForInputClarification = """Given an input text, user want to generate sql query. Please answer if the user input is complete or user needs to ask in more detailed way. Answer in following format. 'Yes' ; if yes, break the userinput into smaller subtask for query generation. Formatted into
|
| 64 |
{
|
| 65 |
"Task 1": "task 1 description",
|
| 66 |
"Task 2": "task 2 description"
|
| 67 |
}
|
| 68 |
+
'No' ; if no, then Reason- please be more detailed about customer details; if more modification needed."""
|
| 69 |
+
systemPromptForInputClarification = systemPromptForInputClarification + '\n' + systemPromptTail
|
| 70 |
cotStep1 = self.gptInstance.getResponseForUserInput(userInput, systemPromptForInputClarification)
|
| 71 |
if "yes" in cotStep1.lower()[:5]:
|
| 72 |
print("User input sufficient")
|
|
|
|
| 142 |
for idx, tableName in enumerate(selectedTablesAndCols.keys(), start=1):
|
| 143 |
prompt += f"table name {tableName} {', '.join(selectedTablesAndCols[tableName])}"
|
| 144 |
prompt += "XXXX"
|
| 145 |
+
return prompt.replace("\n"," ").replace("\\"," ").replace(" "," ").replace("XXXX", " ")
|
| 146 |
+
|
| 147 |
+
def getSystemPromptTailForCoTStep1(self, selectedTablesAndCols):
|
| 148 |
+
schemaName = self.schemaName
|
| 149 |
+
platform = self.platform
|
| 150 |
+
|
| 151 |
+
prompt = f"""schema name is {schemaName}. And sql platform is {platform}. and table info are below.\n"""
|
| 152 |
+
for idx, tableName in enumerate(selectedTablesAndCols.keys(), start=1):
|
| 153 |
+
prompt += f"table name {tableName} {', '.join(selectedTablesAndCols[tableName])}"
|
| 154 |
+
prompt += "XXXX"
|
| 155 |
return prompt.replace("\n"," ").replace("\\"," ").replace(" "," ").replace("XXXX", " ")
|