Aigenthix commited on
Commit
8ca9383
·
verified ·
1 Parent(s): 82007d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -51,7 +51,6 @@ def execute_ai_query(provider, api_key, user_question):
51
  if not user_question.strip():
52
  return None, "⚠️ Please type a question or scenario."
53
 
54
- # FIXED: Replaced raw triple backticks with clean textual descriptions to prevent Hugging Face parsing errors
55
  system_prompt = (
56
  "You are an expert SQL assistant. The database table is called 'project_tasks' with columns: "
57
  "[id, timestamp, phase, task_name, owner, timeline, priority]. "
@@ -82,19 +81,19 @@ def execute_ai_query(provider, api_key, user_question):
82
  }
83
  payload = {
84
  "model": "meta-llama/llama-3-8b-instruct:free",
85
- "messages=[
86
  {"role": "system", "content": system_prompt},
87
  {"role": "user", "content": user_question}
88
  ],
89
  "temperature": 0.0
90
  }
91
- response = requests.post("[https://openrouter.ai/api/v1/chat/completions](https://openrouter.ai/api/v1/chat/completions)", headers=headers, json=payload)
92
  if response.status_code == 200:
93
  sql_query = response.json()['choices'][0]['message']['content'].strip()
94
  else:
95
  return None, f"❌ OpenRouter Error: {response.text}"
96
 
97
- # Defensive stripping of markdown in case the model returns code blocks anyway
98
  sql_query = sql_query.replace("```sql", "").replace("```", "").replace("`", "").strip()
99
 
100
  conn = sqlite3.connect(DB_NAME)
 
51
  if not user_question.strip():
52
  return None, "⚠️ Please type a question or scenario."
53
 
 
54
  system_prompt = (
55
  "You are an expert SQL assistant. The database table is called 'project_tasks' with columns: "
56
  "[id, timestamp, phase, task_name, owner, timeline, priority]. "
 
81
  }
82
  payload = {
83
  "model": "meta-llama/llama-3-8b-instruct:free",
84
+ "messages": [
85
  {"role": "system", "content": system_prompt},
86
  {"role": "user", "content": user_question}
87
  ],
88
  "temperature": 0.0
89
  }
90
+ response = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload)
91
  if response.status_code == 200:
92
  sql_query = response.json()['choices'][0]['message']['content'].strip()
93
  else:
94
  return None, f"❌ OpenRouter Error: {response.text}"
95
 
96
+ # Clean any potential accidental formatting artifacts from LLM outputs
97
  sql_query = sql_query.replace("```sql", "").replace("```", "").replace("`", "").strip()
98
 
99
  conn = sqlite3.connect(DB_NAME)