blesspearl commited on
Commit
c8240ef
·
verified ·
1 Parent(s): a9921fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -24
app.py CHANGED
@@ -308,35 +308,25 @@ def upload_file(files) -> List[str]:
308
 
309
  def user_prompt_sanitization(user_prompt:str)->str:
310
  guide = """
311
- You are a Groq advisor. Your task is to collect user prompts and, using the available SQL tables, tailor the questions to the data. Use the table descriptions below to sanitize the user's prompt.
312
-
313
- **Table Descriptions:**
314
- {table_description}
315
 
316
- **Organization Tips for Queries:**
317
- - When an ID is requested but not explicitly defined, reference a proper ID from the table.
318
- - Example: User prompt: "Get the amount of the purchase with the id 5"
319
- - Response: "Get the purchase with the purchase_id 5"
320
- - Example: User prompt: "Find the review for product 3"
321
- - Response: "Find the review with the product_id 3"
322
- - Example: User prompt: "Show details for user 7"
323
- - Response: "Show details for the user with the user_id 7"
324
- - For numeric or quantifiable attributes:
325
- - Example: User prompt: "Get the top 3 purchases"
326
- - Response: "Get the 3 purchases with the highest amount"
327
- - Example: User prompt: "Show the 5 most recent orders"
328
- - Response: "Show the 5 orders with the most recent created_at date"
329
- - Example: User prompt: "List the top 10 rated products"
330
- - Response: "List the 10 products with the highest rating"
331
- - Ensure you do not query a table that does not exist.
332
 
333
- **Question:**
334
- --------
335
  {user_question}
336
- --------
337
  """
338
 
339
- formatted_guide = guide.format(table_description=table_description,user_question=user_prompt)
340
  api_key:str=userdata.get("GROQ_API_KEY")
341
  client = groq.Groq(api_key=api_key)
342
  return chat_with_groq(client,formatted_guide,"llama3-70b-8192",None)
 
308
 
309
  def user_prompt_sanitization(user_prompt:str)->str:
310
  guide = """
311
+ You are an AI assistant specializing in database queries. Your task is to interpret user questions about a database and refine them based on the available table structures. Use the following table descriptions to guide your responses:
312
+
313
+ Database Schema:
314
+ {database_schema}
315
 
316
+ Instructions:
317
+ 1. Interpret the user's question and identify the relevant tables and columns.
318
+ 2. Refine the query to use correct table and column names as per the schema.
319
+ 3. Ensure all IDs are properly referenced (e.g., user_id instead of just id).
320
+ 4. For quantitative queries (e.g., "top 5"), specify the ordering criteria.
321
+ 5. Infer necessary joins between tables when the query spans multiple tables.
322
+ 6. Provide a clear, concise refinement of the user's query that accurately reflects the database structure.
 
 
 
 
 
 
 
 
 
323
 
324
+ Now, please refine the following user query:
 
325
  {user_question}
326
+
327
  """
328
 
329
+ formatted_guide = guide.format(database_schema=table_description,user_question=user_prompt)
330
  api_key:str=userdata.get("GROQ_API_KEY")
331
  client = groq.Groq(api_key=api_key)
332
  return chat_with_groq(client,formatted_guide,"llama3-70b-8192",None)