File size: 2,432 Bytes
bd61f34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Simplified test for the DroneAssistant with proper smolagents format support
"""

import os
import sys
from drone.drone_chat import DroneAssistant, generate_mission_plan
from drone.hf_model import Message

def final_answer(answer):
    """Final answer function for smolagents"""
    print(f"FINAL ANSWER: {answer}")
    return answer

class SimplePlaceholderModel:
    """A very simple placeholder model that always returns a properly formatted response"""
    
    def __call__(self, messages):
        """Called when used as a function"""
        return self.generate(messages)
    
    def generate(self, messages, **kwargs):
        """Generate a response with proper smolagents formatting"""
        mission_type = "survey"
        duration = 15
        
        # Format the response in the way smolagents expects with proper code formatting
        response = f"""Thought: I will create a {mission_type} mission plan for {duration} minutes and execute it on the simulator.
Code:
```py
mission_plan = generate_mission_plan(mission_type="{mission_type}", duration_minutes={duration})
print(f"Generated mission plan: {{mission_plan}}")
final_answer(f"I've created a {mission_type} mission plan that will take approximately {duration} minutes to execute. The plan includes waypoints for a square pattern around your current position.")
```<end_code>"""
        
        return Message(response)

def test_simple_agent():
    """Test the drone assistant with a simple model"""
    print("\n=== Testing Simple Agent ===")
    
    # Create placeholder model
    model = SimplePlaceholderModel()
    
    # Create drone assistant
    assistant = DroneAssistant(
        tools=[generate_mission_plan],
        model=model
    )
    
    # Test a simple mission planning request
    user_message = "Plan a simple square pattern mission around my current position."
    
    print(f"\nUser: {user_message}")
    
    try:
        response = assistant.chat(user_message)
        print(f"\nAgent response: {response}")
        return True
    except Exception as e:
        print(f"\nError: {str(e)}")
        print(f"Error type: {type(e)}")
        import traceback
        traceback.print_exc()
        return False

if __name__ == "__main__":
    success = test_simple_agent()
    if success:
        print("\nTest passed!")
        sys.exit(0)
    else:
        print("\nTest failed!")
        sys.exit(1)