forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_browsing_agent_parser.py
More file actions
82 lines (77 loc) · 3.53 KB
/
test_browsing_agent_parser.py
File metadata and controls
82 lines (77 loc) · 3.53 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
76
77
78
79
80
81
82
import pytest
from openhands.agenthub.browsing_agent.response_parser import (
BrowseInteractiveAction,
BrowsingResponseParser,
)
@pytest.mark.parametrize(
'action_str, expected',
[
("click('81'", "click('81')```"),
(
'"We need to search the internet\n```goto("google.com")',
'"We need to search the internet\n```goto("google.com")```',
),
("```click('81'", "```click('81')```"),
("click('81')", "click('81')```"),
(
"send_msg_to_user('The server might not be running or accessible. Please check the server status and try again.')",
"send_msg_to_user('The server might not be running or accessible. Please check the server status and try again.')```",
),
],
)
def test_parse_response(action_str: str, expected: str) -> None:
# BrowsingResponseParser.parse_response
parser = BrowsingResponseParser()
response = {'choices': [{'message': {'content': action_str}}]}
result = parser.parse_response(response)
assert result == expected
@pytest.mark.parametrize(
'action_str, expected_browser_actions, expected_thought, expected_msg_content',
[
("click('81')```", "click('81')", '', ''),
("```click('81')```", "click('81')", '', ''),
(
"We need to perform a click\n```click('81')",
"click('81')",
'We need to perform a click',
'',
),
(
'Tell the user that the city was built in 1751.\n```send_msg_to_user("Based on the results of my search, the city was built in 1751.")',
'send_msg_to_user("Based on the results of my search, the city was built in 1751.")',
'Tell the user that the city was built in 1751.',
'Based on the results of my search, the city was built in 1751.',
),
(
'Tell the user that the city was built in 1751.\n```send_msg_to_user("Based on the results of my search, the city was built in 1751.")```',
'send_msg_to_user("Based on the results of my search, the city was built in 1751.")',
'Tell the user that the city was built in 1751.',
'Based on the results of my search, the city was built in 1751.',
),
(
"Tell the user that the city was built in 1751.\n```send_msg_to_user('Based on the results of my search, the city was built in 1751.')```",
"send_msg_to_user('Based on the results of my search, the city was built in 1751.')",
'Tell the user that the city was built in 1751.',
'Based on the results of my search, the city was built in 1751.',
),
(
"send_msg_to_user('The server might not be running or accessible. Please check the server status and try again.'))```",
"send_msg_to_user('The server might not be running or accessible. Please check the server status and try again.'))",
'',
'The server might not be running or accessible. Please check the server status and try again.',
),
],
)
def test_parse_action(
action_str: str,
expected_browser_actions: str,
expected_thought: str,
expected_msg_content: str,
) -> None:
# BrowsingResponseParser.parse_action
parser = BrowsingResponseParser()
action = parser.parse_action(action_str)
assert isinstance(action, BrowseInteractiveAction)
assert action.browser_actions == expected_browser_actions
assert action.thought == expected_thought
assert action.browsergym_send_msg_to_user == expected_msg_content