-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_participant_oregon_trail.py
123 lines (80 loc) · 3.35 KB
/
test_participant_oregon_trail.py
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
import time
import pytest
from langchain_core.messages import HumanMessage
from participant_agent.app import ParticipantApp
print("\n\n\n Welcome to the Oregon Trail! \n\n\n")
@pytest.fixture
def app():
return ParticipantApp()
def format_multi_choice_question(q):
question = q["question"]
options = q.get("options", "")
formatted = f"{question}, options: {' '.join(options)}"
return [HumanMessage(content=formatted)]
def test_1_wagon_leader(app):
scenario = {
"question": "What is the first name of the wagon leader?",
"answer": "Art",
"type": "free-form",
}
print(f"\n {scenario['question']} \n")
graph = app.graph()
res = graph.invoke({"messages": scenario["question"]})
assert res["messages"][-1].content == scenario["answer"]
print(f"\n response: {scenario['answer']}")
def test_2_restocking_tool(app):
scenario = {
"question": "In order to survive the trail ahead, you'll need to have a restocking strategy for when you need to get more supplies or risk starving. If it takes you an estimated 3 days to restock your food and you plan to start with 200lbs of food, budget 10lbs/day to eat, and keep a safety stock of at least 50lbs of back up... at what point should you restock?",
"answer": "D",
"options": ["A: 100lbs", "B: 20lbs", "C: 5lbs", "D: 80lbs"],
"type": "multi-choice",
}
graph = app.graph()
print(f"\n question: {scenario['question']} \n")
res = graph.invoke({"messages": format_multi_choice_question(scenario)})
assert res["multi_choice_response"] == scenario["answer"]
print(f"\n response: {scenario['answer']}")
def test_3_retrieval_tool(app):
scenario = {
"question": "You’ve encountered a dense forest near the Blue Mountains, and your party is unsure how to proceed. There is a fork in the road, and you must choose a path. Which way will you go?",
"answer": "B",
"options": [
"A: take the northern trail",
"B: take the southern trail",
"C: turn around",
"D: go fishing",
],
"type": "multi-choice",
}
graph = app.graph()
print(f"\n {scenario['question']} \n")
res = graph.invoke({"messages": format_multi_choice_question(scenario)})
assert res["multi_choice_response"] == scenario["answer"]
print(f"\n response: {scenario['answer']}")
def test_4_semantic_cache(app):
scenario = {
"question": "There's a deer. You're hungry. You know what you have to do...",
"answer": "bang",
"type": "action",
}
print(f"\n {scenario['question']} \n")
semantic_cache = app.semantic_cache()
start = time.time()
cache_hit = semantic_cache.check(
prompt=scenario["question"], return_fields=["response"]
)
end = time.time() - start
assert cache_hit[-1]["response"] == scenario["answer"]
assert end < 1
print(f"\n response: {scenario['answer']}")
def test_5_router(app):
scenario = {
"question": "Tell me about the S&P 500?",
"answer": "you shall not pass",
"type": "action",
}
print(f"\n {scenario['question']} \n")
router = app.router()
blocked_topic_match = router(scenario["question"], distance_threshold=0.2)
assert blocked_topic_match.name == "block_list"
print(f"\n response: {scenario['answer']}")