Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,16 +41,16 @@ def ask_question(user_db, question):
|
|
| 41 |
# Create a Text-to-SQL prompt
|
| 42 |
prompt = f"Translate this question into an SQLite query.\nReturn only SQL (no text):\nQuestion: {question}\nSQL:"
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
response = sqlcoder_llm(prompt)
|
| 46 |
|
| 47 |
-
#
|
| 48 |
if isinstance(response, dict) and "text" in response:
|
| 49 |
response = response["text"]
|
| 50 |
elif isinstance(response, list):
|
| 51 |
response = response[0]["generated_text"]
|
| 52 |
|
| 53 |
-
#
|
| 54 |
sql_query = response.strip().split("SQL:")[-1].strip()
|
| 55 |
sql_query = sql_query.split("\n")[0].strip()
|
| 56 |
if not sql_query.endswith(";"):
|
|
|
|
| 41 |
# Create a Text-to-SQL prompt
|
| 42 |
prompt = f"Translate this question into an SQLite query.\nReturn only SQL (no text):\nQuestion: {question}\nSQL:"
|
| 43 |
|
| 44 |
+
# ✅ Use .invoke() instead of calling the object directly
|
| 45 |
+
response = sqlcoder_llm.invoke(prompt)
|
| 46 |
|
| 47 |
+
# Ensure we get plain string
|
| 48 |
if isinstance(response, dict) and "text" in response:
|
| 49 |
response = response["text"]
|
| 50 |
elif isinstance(response, list):
|
| 51 |
response = response[0]["generated_text"]
|
| 52 |
|
| 53 |
+
# Clean and finalize SQL
|
| 54 |
sql_query = response.strip().split("SQL:")[-1].strip()
|
| 55 |
sql_query = sql_query.split("\n")[0].strip()
|
| 56 |
if not sql_query.endswith(";"):
|