| """ |
| Test script for Soil Tool |
| Run this to verify the soil tool is working correctly |
| """ |
|
|
| import sys |
| from pathlib import 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() |
| |
| |
| result = execute_soil_tool(question) |
| |
| if result["success"]: |
| print("β
Tool execution: SUCCESS") |
| print() |
| |
| |
| 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_soil_tool() |
| |
| |
| 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") |
|
|
|
|