Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import pandas as pd
|
|
|
|
| 2 |
from sentence_transformers import SentenceTransformer
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
import numpy as np
|
|
@@ -116,7 +117,24 @@ def extract_table_name(llm, query):
|
|
| 116 |
for table in metadata_df.table.unique():
|
| 117 |
if table in pred:
|
| 118 |
return table
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
warnings.filterwarnings('ignore', message="pandas only supports SQLAlchemy connectable.*", category=UserWarning, module='chain')
|
| 121 |
|
| 122 |
intermediate_steps_KEY = "intermediate_steps"
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
from ast import literal_eval
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 5 |
import numpy as np
|
|
|
|
| 117 |
for table in metadata_df.table.unique():
|
| 118 |
if table in pred:
|
| 119 |
return table
|
| 120 |
+
|
| 121 |
+
def extract_question_list(llm, query):
|
| 122 |
+
sys_prompt = """You are an AI assistant that determines if multiple questions are stacked in a single question and split the question into sub questions and return a list of them. Make sure the response is a valid Python list.
|
| 123 |
+
If the question is a single question and return the original question."""
|
| 124 |
+
|
| 125 |
+
message1 = SystemMessage(content=sys_prompt)
|
| 126 |
+
|
| 127 |
+
message2 = HumanMessage(
|
| 128 |
+
content=query
|
| 129 |
+
)
|
| 130 |
+
message_log = [message1, message2]
|
| 131 |
+
|
| 132 |
+
output = llm.invoke(message_log)
|
| 133 |
+
pred = output.content
|
| 134 |
+
|
| 135 |
+
return pred
|
| 136 |
+
|
| 137 |
+
|
| 138 |
warnings.filterwarnings('ignore', message="pandas only supports SQLAlchemy connectable.*", category=UserWarning, module='chain')
|
| 139 |
|
| 140 |
intermediate_steps_KEY = "intermediate_steps"
|