-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtesting_framework.py
More file actions
75 lines (62 loc) · 3.22 KB
/
testing_framework.py
File metadata and controls
75 lines (62 loc) · 3.22 KB
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
import unittest
from typing import Any, Callable, Dict, List
from hypothesis import given, strategies as st
class AgentZeroTestSuite(unittest.TestCase):
def __init__(self, methodName: str = "runTest"):
super().__init__(methodName)
self.agent_zero = None # Initialize your Agent Zero instance here
def test_nlu_understanding(self):
test_cases = [
("What's the weather like in New York?", {
"intent": "get_weather",
"entities": [{"type": "location", "value": "New York"}]
}),
("Book a flight to London for tomorrow", {
"intent": "book_flight",
"entities": [
{"type": "location", "value": "London"},
{"type": "date", "value": "tomorrow"}
]
})
]
for input_text, expected_output in test_cases:
result = self.agent_zero.nlu.understand(input_text)
self.assertEqual(result['intent'], expected_output['intent'])
self.assertCountEqual(result['entities'], expected_output['entities'])
@given(st.text(min_size=1, max_size=200))
def test_nlu_robustness(self, input_text):
result = self.agent_zero.nlu.understand(input_text)
self.assertIsNotNone(result['intent'])
self.assertIsInstance(result['entities'], list)
def test_memory_retrieval(self):
# Test case: Store and retrieve a memory
test_memory = "The capital of France is Paris"
memory_id = self.agent_zero.vector_db.insert([self.agent_zero._embed(test_memory)], [test_memory], [{}])[0]
retrieved_memories = self.agent_zero.vector_db.search(self.agent_zero._embed(test_memory), top_k=1)
self.assertEqual(retrieved_memories[0][0], test_memory)
def test_tool_execution(self):
# Test case: Execute a simple tool
test_tool = "echo_tool"
test_input = "Hello, World!"
self.agent_zero.dynamic_tool_manager.create_tool({
"name": test_tool,
"code": f"def tool_{test_tool}(text): return text"
})
result = self.agent_zero.dynamic_tool_manager.execute_tool(test_tool, text=test_input)
self.assertEqual(result, test_input)
def test_ethical_decision_making(self):
test_actions = [
{"name": "Action A", "positive_impact": 5, "negative_impact": 2, "harm": 1, "user_choice": 3, "fairness": 4},
{"name": "Action B", "positive_impact": 3, "negative_impact": 1, "harm": 0, "user_choice": 5, "fairness": 3},
{"name": "Action C", "positive_impact": 7, "negative_impact": 4, "harm": 2, "user_choice": 2, "fairness": 5},
]
best_action = self.agent_zero.ethical_decision_maker.make_decision(test_actions)
self.assertEqual(best_action['name'], "Action B") # Assuming this is the most ethical action
def test_end_to_end_processing(self):
test_input = "What's the population of Tokyo?"
response = self.agent_zero.process_input(test_input)
self.assertIsInstance(response, str)
self.assertIn("Tokyo", response)
self.assertIn("population", response.lower())
if __name__ == "__main__":
unittest.main()