File size: 3,652 Bytes
b30f068 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | """
Test script for Soil Tool
Run this to verify the soil tool is working correctly
"""
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from tools.soil_tool import execute_soil_tool
from tools.tool_executor import ToolExecutor
def test_soil_tool():
"""Test the soil tool with sample questions"""
print("="* 70)
print("π§ͺ TESTING SOIL TOOL")
print("=" * 70)
test_questions = [
"Show me soil data for Iowa",
"What's the soil composition in California?",
"Tell me about soil in Texas",
"Soil pH for New York"
]
for i, question in enumerate(test_questions, 1):
print(f"\n{'β' * 70}")
print(f"Test {i}/4")
print(f"{'β' * 70}")
print(f"π Question: {question}")
print()
# Execute the soil tool
result = execute_soil_tool(question)
if result["success"]:
print("β
Tool execution: SUCCESS")
print()
# Display raw data
data = result["data"]
location = data["location"]
print(f"π Location: Lat {location['lat']}, Lon {location['lon']}")
print()
print(f"π± Soil Properties:")
for prop_name, prop_data in data["properties"].items():
print(f" β’ {prop_data['label']}: {prop_data['value']} {prop_data['unit']}")
else:
print("β Tool execution: FAILED")
print(f" Error: {result['error']}")
print(f"\n{'=' * 70}")
print("β
Testing complete!")
print("=" * 70)
def test_with_llm():
"""Test soil tool with LLM response generation"""
print("\n" + "="* 70)
print("π§ͺ TESTING SOIL TOOL WITH LLM RESPONSE")
print("=" * 70)
try:
executor = ToolExecutor()
test_questions = [
"Show me soil data for Iowa",
"What's the soil pH in California?",
]
for question in test_questions:
print(f"\n{'β' * 70}")
print(f"π Question: {question}")
print("β" * 70)
result = executor.execute("soil", question)
if result["success"]:
print("β
Success!")
print(f"\nπ€ LLM Response:")
print(f" {result['llm_response']}")
print(f"\nπ Raw Data:")
data = result["raw_data"]
print(f" Location: {data['location']}")
print(f" Properties: {len(data.get('properties', {}))} found")
else:
print(f"β Failed: {result['error']}")
print("\n" + "=" * 70)
print("β
LLM Testing complete!")
print("=" * 70)
except Exception as e:
print(f"β Error: {e}")
print("\nπ‘ Make sure you have:")
print(" 1. OPENAI_API_KEY in .env")
print(" 2. OPENWEATHER_API_KEY in .env (for geocoding)")
if __name__ == "__main__":
print("\n" + "π± SOIL TOOL TEST SUITE" + "\n")
# Test 1: Basic soil tool
test_soil_tool()
# Test 2: With LLM (if OpenAI key is available)
print("\n" + "β" * 70)
response = input("\nTest with LLM response generation? (y/n): ").strip().lower()
if response == 'y':
test_with_llm()
else:
print("\nπ‘ To test LLM responses:")
print(" 1. Add OPENAI_API_KEY to .env")
print(" 2. Run: python src/tools/tool_executor.py")
|