uumerrr684 commited on
Commit
25a8945
·
verified ·
1 Parent(s): 3d66778

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -15
app.py CHANGED
@@ -345,22 +345,27 @@ class ProductionRAGSystem:
345
  context = "\n\n".join([f"Source: {r['metadata']['source_file']}\nContent: {r['content']}"
346
  for r in search_results[:3]])
347
 
348
- # Create comprehensive prompt for unlimited tokens
349
  if unlimited_tokens:
350
- prompt = f"""Based on the following document context, provide a comprehensive and detailed answer to the user's question.
351
 
352
- Context from documents:
353
  {context}
354
 
355
- User Question: {query}
356
 
357
- Please provide a thorough, well-structured answer that directly addresses the question using the information from the documents. If the documents contain specific details, include them in your response."""
358
- max_tokens = 500 # Higher token limit for detailed responses
359
- temperature = 0.3
 
 
 
 
 
360
  else:
361
- # Fallback to shorter prompt
362
- prompt = f"Context: {extracted_answer}\n\nQuestion: {query}\n\nImprove the answer:"
363
- max_tokens = 150
364
  temperature = 0.1
365
 
366
  try:
@@ -429,13 +434,19 @@ def get_general_ai_response(query, unlimited_tokens=False):
429
  try:
430
  # Adjust parameters based on token availability
431
  if unlimited_tokens:
432
- max_tokens = 500
433
  temperature = 0.7
434
- prompt = f"Please provide a helpful and detailed answer to this question: {query}"
 
 
 
 
 
 
435
  else:
436
- max_tokens = 150
437
- temperature = 0.7
438
- prompt = query[:200] # Limit input length for token conservation
439
 
440
  response = requests.post(
441
  "https://openrouter.ai/api/v1/chat/completions",
 
345
  context = "\n\n".join([f"Source: {r['metadata']['source_file']}\nContent: {r['content']}"
346
  for r in search_results[:3]])
347
 
348
+ # Create focused prompt for concise, professional answers
349
  if unlimited_tokens:
350
+ prompt = f"""Act as a helpful HR assistant for this company. Based on the document context below, provide a clear, concise, and professional answer to the employee's question.
351
 
352
+ Document Context:
353
  {context}
354
 
355
+ Employee Question: {query}
356
 
357
+ Instructions:
358
+ - Give a direct, actionable answer
359
+ - Use specific details from the documents
360
+ - Keep it professional but friendly
361
+ - Be concise and to the point
362
+ - If policies have conditions or exceptions, mention them clearly"""
363
+ max_tokens = 300 # Balanced token limit
364
+ temperature = 0.2
365
  else:
366
+ # Shorter prompt for conservative mode
367
+ prompt = f"Act as an HR assistant. Based on this info: {extracted_answer}\n\nEmployee asks: {query}\n\nGive a clear, helpful answer:"
368
+ max_tokens = 50 # Minimum token limit
369
  temperature = 0.1
370
 
371
  try:
 
434
  try:
435
  # Adjust parameters based on token availability
436
  if unlimited_tokens:
437
+ max_tokens = 300 # Balanced limit for good answers
438
  temperature = 0.7
439
+ prompt = f"""Act as a knowledgeable assistant. Provide a helpful, clear, and concise answer to this question: {query}
440
+
441
+ Keep your response:
442
+ - Direct and actionable
443
+ - Professional but conversational
444
+ - Focused on the main points
445
+ - Under 300 tokens"""
446
  else:
447
+ max_tokens = 50 # Minimum for conservative mode
448
+ temperature = 0.5
449
+ prompt = f"Briefly answer: {query[:100]}" # Limit input length for token conservation
450
 
451
  response = requests.post(
452
  "https://openrouter.ai/api/v1/chat/completions",