alokik29 commited on
Commit
e6e05c7
·
verified ·
1 Parent(s): d29a670

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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
- # Generate text
45
- response = sqlcoder_llm(prompt)
46
 
47
- # Some models return objects, ensure it's 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
- # Extract SQL from response (clean any extra text)
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(";"):