Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
312 |
-
|
313 |
-
|
314 |
-
{
|
315 |
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
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 |
-
|
334 |
-
--------
|
335 |
{user_question}
|
336 |
-
|
337 |
"""
|
338 |
|
339 |
-
formatted_guide = guide.format(
|
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)
|