Spaces:
Sleeping
Sleeping
Commit ·
f11af9a
1
Parent(s): c187541
Improve prompt: force data-specific responses, add context logging
Browse files
app.py
CHANGED
|
@@ -409,31 +409,42 @@ def build_llm_prompt(query: str, context: Dict, history: List[Dict] = None) -> s
|
|
| 409 |
# Combine into full prompt
|
| 410 |
context_str = "\n\n".join(context_parts)
|
| 411 |
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
-
#
|
| 415 |
-
{persona.get('description', '')}
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
- Tone: {persona.get('tone', '')}
|
| 420 |
-
- Recommendations: {persona.get('recommendations', '')}
|
| 421 |
|
| 422 |
-
#
|
| 423 |
{context_str}
|
| 424 |
{history_text}
|
| 425 |
|
| 426 |
-
# USER
|
| 427 |
{query}
|
| 428 |
|
| 429 |
-
#
|
| 430 |
-
1.
|
| 431 |
-
2.
|
| 432 |
-
3.
|
| 433 |
-
4.
|
| 434 |
-
5.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
-
Provide your
|
| 437 |
|
| 438 |
return prompt
|
| 439 |
|
|
|
|
| 409 |
# Combine into full prompt
|
| 410 |
context_str = "\n\n".join(context_parts)
|
| 411 |
|
| 412 |
+
# Log context for debugging
|
| 413 |
+
logger.info(f"Context sections: {len(context_parts)}")
|
| 414 |
+
for i, part in enumerate(context_parts[:2]): # Log first 2 sections
|
| 415 |
+
logger.info(f"Context[{i}]: {part[:100]}...")
|
| 416 |
+
|
| 417 |
+
prompt = f"""You are AGROW AI, an expert agricultural advisor analyzing REAL satellite data for an Indian farmer's field.
|
| 418 |
+
|
| 419 |
+
# CRITICAL INSTRUCTION
|
| 420 |
+
You MUST analyze the ACTUAL data provided below. DO NOT give generic farming advice.
|
| 421 |
+
ALWAYS cite specific values from the analysis (e.g., "Your NDVI of 0.65 indicates...").
|
| 422 |
|
| 423 |
+
# FARMER PROFILE
|
| 424 |
+
{persona.get('description', 'Experienced farmer')}
|
| 425 |
+
Response Style: {persona.get('style', 'Practical')}
|
| 426 |
+
Tone: {persona.get('tone', 'Friendly')}
|
| 427 |
+
Focus: {persona.get('focus', 'Actionable advice')}
|
|
|
|
|
|
|
| 428 |
|
| 429 |
+
# SATELLITE & FIELD DATA (ACTUAL VALUES FROM TODAY'S ANALYSIS)
|
| 430 |
{context_str}
|
| 431 |
{history_text}
|
| 432 |
|
| 433 |
+
# USER'S QUESTION
|
| 434 |
{query}
|
| 435 |
|
| 436 |
+
# RESPONSE REQUIREMENTS
|
| 437 |
+
1. START by acknowledging the specific field and crop being analyzed
|
| 438 |
+
2. CITE exact values from the data (NDVI, moisture levels, stress scores)
|
| 439 |
+
3. EXPLAIN what these values mean for THIS specific crop
|
| 440 |
+
4. PROVIDE 2-3 actionable recommendations based on the data
|
| 441 |
+
5. If any stress zones detected, address them FIRST
|
| 442 |
+
6. Keep response under 300 words
|
| 443 |
+
7. Use simple language the farmer understands
|
| 444 |
+
|
| 445 |
+
IMPORTANT: Your response MUST reference at least 3 specific data points from the analysis above.
|
| 446 |
|
| 447 |
+
Provide your analysis:"""
|
| 448 |
|
| 449 |
return prompt
|
| 450 |
|