Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 349 |
if unlimited_tokens:
|
| 350 |
-
prompt = f"""Based on the
|
| 351 |
|
| 352 |
-
Context
|
| 353 |
{context}
|
| 354 |
|
| 355 |
-
|
| 356 |
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
else:
|
| 361 |
-
#
|
| 362 |
-
prompt = f"
|
| 363 |
-
max_tokens =
|
| 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 =
|
| 433 |
temperature = 0.7
|
| 434 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
else:
|
| 436 |
-
max_tokens =
|
| 437 |
-
temperature = 0.
|
| 438 |
-
prompt = query[:
|
| 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",
|