Skip to content

Commit 3611c93

Browse files
committed
samples of how to add custom tasks to workarena
1 parent 638fcf2 commit 3611c93

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

src/browsergym/workarena/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .tasks.navigation import __TASKS__ as NAVIGATION_TASKS
2626
from .tasks.service_catalog import __TASKS__ as SERVICE_CATALOG_TASKS
2727
from .tasks.compositional.base import CompositionalTask
28+
from .tasks.other import __TASKS__ as OTHER_TASKS
2829

2930
ALL_WORKARENA_TASKS = [
3031
*ALL_COMPOSITIONAL_TASKS_L2,
@@ -36,6 +37,7 @@
3637
*NAVIGATION_TASKS,
3738
*SERVICE_CATALOG_TASKS,
3839
*UPDATE_TASKS,
40+
*OTHER_TASKS,
3941
]
4042
ATOMIC_TASKS = [
4143
task
@@ -92,6 +94,10 @@
9294
"workarena.servicenow.single-chart-min-max-retrieval": "dashboard",
9395
}
9496

97+
TASK_CATEGORY_MAP["other.search-samsung-galaxy-phone"] = "other"
98+
TASK_CATEGORY_MAP["other.search-samsung-galaxy-tab-active5"] = "other"
99+
TASK_CATEGORY_MAP["other.search-samsung-oled-tvs"] = "other"
100+
95101

96102
workarena_tasks_l1 = list(TASK_CATEGORY_MAP.keys())
97103
workarena_task_categories = {}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import inspect
2+
from browsergym.core.task import OpenEndedTask
3+
from playwright.sync_api._generated import Page
4+
from typing import Tuple
5+
6+
7+
class SearchSamsungTask(OpenEndedTask):
8+
def setup(self, page: Page) -> tuple[str, dict]:
9+
page.goto(self.start_url, timeout=10000)
10+
return self.goal, {}
11+
12+
def setup_goal(self, page: Page) -> tuple[str, dict]:
13+
super().setup_goal(page=page)
14+
15+
def teardown(self) -> None:
16+
pass
17+
18+
def validate(
19+
self, page: Page, chat_messages: list[str]
20+
) -> Tuple[float, bool, str, dict]:
21+
reward, done, msg, info = 0, False, "", {}
22+
23+
answer_str = "YES".lower()
24+
25+
if chat_messages and chat_messages[-1]["role"] == "assistant":
26+
answer = chat_messages[-1]["message"].lower()
27+
28+
if answer_str in answer:
29+
return 1.0, True, "Thank you for giving me the answer", {"message": f"Thank you for giving me the answer: {answer}"}
30+
else:
31+
return (
32+
0,
33+
False,
34+
"",
35+
{"message": "The assistant did not provide an answer."},
36+
)
37+
38+
return 0.0, False, "", {"message": "The assistant did not provide an answer."}
39+
40+
41+
class SearchSamsungGalaxyPhone(SearchSamsungTask):
42+
@classmethod
43+
def get_task_id(cls):
44+
return "other.search-samsung-galaxy-phone"
45+
46+
def __init__(self, seed: int, start_url: str = "http://www.samsung.com/", goal: str = "Tell me how I replace the hard drive in my thinkpad t440") -> None:
47+
product = "galaxy s23 phones"
48+
goal = f"Please tell me whether {product} have AI features. Accept all cookies, if needed. Once you have the answer, send me a message with only YES or NO, and the URL where you found the answer."
49+
super().__init__(seed, start_url, goal)
50+
51+
52+
class SearchSamsungGalaxyTabActive5(SearchSamsungTask):
53+
@classmethod
54+
def get_task_id(cls):
55+
return "other.search-samsung-galaxy-tab-active5"
56+
57+
def __init__(self, seed: int, start_url: str = "http://www.samsung.com/", goal: str = "Tell me how I replace the hard drive in my thinkpad t440") -> None:
58+
product = "galaxy tab active5"
59+
goal = f"Please tell me whether {product} have AI features. Accept all cookies, if needed. Once you have the answer, send me a message with only YES or NO, and the URL where you found the answer."
60+
super().__init__(seed, start_url, goal)
61+
62+
def validate(
63+
self, page: Page, chat_messages: list[str]
64+
) -> Tuple[float, bool, str, dict]:
65+
reward, done, msg, info = 0, False, "", {}
66+
67+
answer_str = "NO".lower()
68+
69+
if chat_messages and chat_messages[-1]["role"] == "assistant":
70+
answer = chat_messages[-1]["message"].lower()
71+
72+
if answer_str in answer:
73+
return 1.0, True, "Thank you for giving me the answer", {"message": f"Thank you for giving me the answer: {answer}"}
74+
else:
75+
return (
76+
0,
77+
False,
78+
"",
79+
{"message": "The assistant did not provide an answer."},
80+
)
81+
82+
return 0.0, False, "", {"message": "The assistant did not provide an answer."}
83+
84+
85+
class SearchSamsungOledTvs(SearchSamsungTask):
86+
87+
@classmethod
88+
def get_task_id(cls):
89+
return "other.search-samsung-oled-tvs"
90+
91+
def __init__(self, seed: int, start_url: str = "http://www.samsung.com/", goal: str = "Tell me how I replace the hard drive in my thinkpad t440") -> None:
92+
product = "oled tvs"
93+
goal = f"Please tell me whether {product} have AI features. Accept all cookies, if needed. Once you have the answer, send me a message with only YES or NO, and the URL where you found the answer."
94+
super().__init__(seed, start_url, goal)
95+
96+
97+
local_vars = locals().copy()
98+
99+
100+
__TASKS__ = [
101+
var
102+
for var in local_vars.values()
103+
if inspect.isclass(var)
104+
and (issubclass(var, SearchSamsungGalaxyPhone) or issubclass(var, SearchSamsungGalaxyTabActive5) or issubclass(var, SearchSamsungOledTvs))
105+
]

0 commit comments

Comments
 (0)