├── .gitignore
├── LICENSE
├── README.md
├── assets
├── icon.png
├── overall_process_crop.png
└── webvoyager_overall_res.png
├── data
├── GAIA_web.jsonl
├── WebVoyager_data.jsonl
├── reference_answer.json
└── tasks_test.jsonl
├── downloads
└── .gitkeep
├── evaluation
├── auto_eval.py
└── run_eval.sh
├── prompts.py
├── requirements.txt
├── results
└── examples
│ ├── taskAllrecipes--4
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ ├── screenshot5.png
│ └── screenshot6.png
│ ├── taskAmazon--0
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ └── screenshot3.png
│ ├── taskApple--17
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ ├── screenshot5.png
│ └── screenshot6.png
│ ├── taskArXiv--11
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ ├── screenshot5.png
│ ├── screenshot6.png
│ └── screenshot7.png
│ ├── taskBBC News--9
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ └── screenshot3.png
│ ├── taskBooking--1
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ ├── screenshot5.png
│ ├── screenshot6.png
│ ├── screenshot7.png
│ ├── screenshot8.png
│ └── screenshot9.png
│ ├── taskCambridge Dictionary--29
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot10.png
│ ├── screenshot10_no_box.png
│ ├── screenshot11.png
│ ├── screenshot11_no_box.png
│ ├── screenshot12.png
│ ├── screenshot12_no_box.png
│ ├── screenshot1_no_box.png
│ ├── screenshot2.png
│ ├── screenshot2_no_box.png
│ ├── screenshot3.png
│ ├── screenshot3_no_box.png
│ ├── screenshot4.png
│ ├── screenshot4_no_box.png
│ ├── screenshot5.png
│ ├── screenshot5_no_box.png
│ ├── screenshot6.png
│ ├── screenshot6_no_box.png
│ ├── screenshot7.png
│ ├── screenshot7_no_box.png
│ ├── screenshot8.png
│ ├── screenshot8_no_box.png
│ ├── screenshot9.png
│ └── screenshot9_no_box.png
│ ├── taskCoursera--16
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ └── screenshot5.png
│ ├── taskESPN--11
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ └── screenshot5.png
│ ├── taskGitHub--0
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ └── screenshot5.png
│ ├── taskGoogle Flights--8
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot10.png
│ ├── screenshot11.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ ├── screenshot5.png
│ ├── screenshot6.png
│ ├── screenshot7.png
│ ├── screenshot8.png
│ └── screenshot9.png
│ ├── taskGoogle Map--4
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ └── screenshot4.png
│ ├── taskGoogle Search--3
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ └── screenshot5.png
│ ├── taskHuggingface--3
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ ├── screenshot3.png
│ ├── screenshot4.png
│ ├── screenshot5.png
│ └── screenshot6.png
│ └── taskWolfram Alpha--6
│ ├── interact_messages.json
│ ├── screenshot1.png
│ ├── screenshot2.png
│ └── screenshot3.png
├── run.py
├── run.sh
├── utils.py
└── utils_webarena.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 | downloads/*.pdf
3 | results/2024*
4 | test_code.py
5 | __pycache__
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
WebVoyager
3 |
4 |
Building an End-to-End Web Agent with Large Multimodal Models
5 |
6 |
7 |
8 |
9 | 
10 | 
11 | 
12 |
13 |
14 |
15 |
16 |

17 |
18 |
19 |
20 |
21 | ## Introduction
22 |
23 | This repo contains the data and implementation of our paper [WebVoyager](https://arxiv.org/abs/2401.13919). WebVoyager is an innovative Large Multimodal Model (LMM) powered web agent that can complete user instructions end-to-end by interacting with real-world websites.
24 |
25 | - **Multimodal Web Agent**. We implement WebVoyager that integrates textual and visual information to address web tasks end-to-end and introduce a generalist planning approach for navigation.
26 | - **Online Environment**. We build an online web browsing environment using Selenium.
27 | - **Diverse Web Tasks** We offer a variety of tasks centered on widely used websites and introduce a
28 | method for expanding these tasks.
29 | - **Evaluation Tool** We propose an automated evaluation protocol using GPT-4V.
30 |
31 | ## Setup Environment
32 |
33 | We use Selenium to build the online web browsing environment.
34 | - Make sure you have installed Chrome. (Using the latest version of Selenium, there is no need to install ChromeDriver.)
35 | - If you choose to run your code on a Linux server, we recommend installing chromium. (eg, for CentOS: ```yum install chromium-browser```)
36 | - Create a conda environment for WebVoyager and install the dependencies.
37 | ```bash
38 | conda create -n webvoyager python=3.10
39 | conda activate webvoyager
40 | pip install -r requirements.txt
41 | ```
42 |
43 | ## Data
44 |
45 | ### Overview
46 |
47 | To test WebVoyager, we utilize a semi-automated approach to generate and filter 643 task queries, covering 15 websites, with each website containing 40+ queries. The dataset can be found in `data/WebVoyager_data.jsonl`.
48 |
49 | - For each data entry, we provide a task description along with its corresponding website.
50 | - Some tasks are time-sensitive and are primarily distributed in Booking and Google Flights. Currently, we need to **manually update** the time before running.
51 | - We have labelled each task with a brief reference answer, which is placed in `data/reference_answer.json`.
52 |
53 | Additionally, we extract 90 web browsing tasks (Level 1 and Level 2) from the [GAIA dataset (validation)](https://huggingface.co/datasets/gaia-benchmark/GAIA). View the tasks in `data/GAIA_web.jsonl`
54 |
55 | - In GAIA validation set, the authors provide Annotator Metadata and specify the tools ("web browser" or "search engine"). We extract tasks based on this information.
56 | - GAIA does not provide a corresponding website for each task, so we set the starting website for each task to be Google Search.
57 |
58 | ### Expand tasks
59 |
60 | The existing data can form a relatively rich task pool, and we recommend using GPT-4 (https://chat.openai.com) to expand the data. Below is a sample prompt, you can modify or redesign the prompt to meet your demands.
61 |
62 | ```
63 | Here are some example tasks and the websites that need to be interacted with to solve these tasks.
64 | """
65 |
66 |
67 | """
68 |
69 | Please carefully analyze the above TASKs and then generate new TASKs for {website}. Please use diverse descriptions and do not repeat the task descriptions in examples.
70 |
71 | Pay attention:
72 | 1. Do not include the requirement to view videos in the task.
73 | 2. In the generated task, if you need to declare a specific date in the future (such as booking, flights ...), you can choose the date in the range of to .
74 | 3. The generated task should have a clear goal and should not require complicated web page operations.
75 | 4. When looking for real-time information in the past (such as ArXiv, BBC News ...), don't ask for too much information for a certain period of time in the past, as this requires a lot of web scrolling and page flipping. But you may request information for certain points in time, e.g. latest.
76 | 5. To improve randomness and diversity, please try not to repeat entities that were asked about in examples.
77 |
78 | Think carefully about the functions of given websites, and please note that the generated TASK can be solved by the corresponding website. The format of the answer must be: TASK: {Generated-task}|||WEB: {Website-name, https-address}
79 | ```
80 |
81 | ## Running
82 |
83 | ### Running WebVoyager
84 | After setting up the environment, you can start running WebVoyager.
85 |
86 | 1. Copy the examples you want to test into `data/tasks_test.jsonl`. For Booking and Google Flights tasks, please manually update the date in the task if it is outdated.
87 | 2. Modify the api_key in `run.sh`
88 |
89 | You can run WebVoyager with the following command:
90 | ```bash
91 | bash run.sh
92 | ```
93 |
94 | The details of `run.sh`:
95 | ```bash
96 | #!/bin/bash
97 | nohup python -u run.py \
98 | --test_file ./data/tasks_test.jsonl \
99 | --api_key YOUR_OPENAI_API_KEY \
100 | --headless \
101 | --max_iter 15 \
102 | --max_attached_imgs 3 \
103 | --temperature 1 \
104 | --fix_box_color \
105 | --seed 42 > test_tasks.log &
106 | ```
107 |
108 | For WebVoyager (Text only), an example script can be:
109 | ```bash
110 | #!/bin/bash
111 | nohup python -u run.py \
112 | --test_file ./data/tasks_test.jsonl \
113 | --api_key YOUR_OPENAI_API_KEY \
114 | --headless \
115 | --max_iter 15 \
116 | --max_attached_imgs 1 \
117 | --temperature 1 \
118 | --text_only \
119 | --api_model gpt-4-1106-preview \
120 | --seed 42 > test_tasks_text_only.log &
121 | ```
122 |
123 |
124 | ### Parameters
125 |
126 | General:
127 | - `--test_file`: The task file to be evaluated. Please refer to the format of the data file in the `data`.
128 | - `--max_iter`: The maximum number of online interactions for each task. Exceeding max_iter without completing the task means failure.
129 | - `--api_key`: Your OpenAI API key.
130 | - `--output_dir`: We should save the trajectory of the web browsing.
131 | - `--download_dir`: Sometimes Agent downloads PDF files for analysis.
132 |
133 | Model:
134 | - `--api_model`: The agent that receives observations and makes decisions. In our experiments, we use `gpt-4-vision-preview`. For text-only setting, models without vision input can be used, such as `gpt-4-1106-preview`.
135 | - `seed`: This feature is in Beta according to the OpenAI [Document](https://platform.openai.com/docs/api-reference/chat).
136 | - `--temperature`: To control the diversity of the model, note that setting it to 0 here does not guarantee consistent results over multiple runs.
137 | - `--max_attached_imgs`: We perform context clipping to remove outdated web page information and only keep the most recent k screenshots.
138 | - `--text_only`: Text only setting, observation will be accessibility tree.
139 |
140 | Web navigation:
141 | - `--headless`: The headless model does not explicitly open the browser, which makes it easier to deploy on Linux servers and more resource-efficient. Notice: headless will affect the **size of the saved screenshot**, because in non-headless mode, there will be an address bar.
142 | - `--save_accessibility_tree`: Whether you need to save the Accessibility Tree for the current page. We mainly refer to [WebArena](https://github.com/web-arena-x/webarena) to build the Accessibility Tree.
143 | - `--force_device_scale`: Set device scale factor to 1. If we need accessibility tree, we should use this parameter.
144 | - `--window_width`: Width, default is 1024.
145 | - `--window_height`: Height, default is 768. (1024 * 768 image is equal to 765 tokens according to [OpenAI pricing](https://openai.com/pricing).)
146 | - `--fix_box_color`: We utilize [GPT-4-ACT](https://github.com/ddupont808/GPT-4V-Act), a Javascript tool to extracts the interactive elements based on web element types and then overlays bounding boxes. This option fixes the color of the boxes to black. Otherwise it is random.
147 |
148 | ### Develop Your Prompt
149 |
150 | Prompt optimisation is a complex project which directly affects the performance of the Agent. You can find the system prompt we designed in `prompts.py`.
151 |
152 | The prompt we provide has been tweaked many times, but it is not perfect, and if you are interested, you can **do your own optimisation** without compromising its generality (i.e. not giving specific instructions for specific sites in the prompt). If you just need the Agent for some specific websites, then giving specific instructions is fine.
153 |
154 | If you want to add Action to the prompt, or change the Action format, it is relatively easy to change the code. You can design your own `extract_information` function to parse the model's output and modify `run.py` to add or modify the way of action execution.
155 |
156 | ## Results and Evaluation
157 |
158 | The results will be saved in the output dir you set, in this experiment we use `results` and we put some of the results in `results/examples`. The results folder for each task contains interact messages and several screenshots.
159 |
160 |
161 |
162 |
163 |

164 |
165 |
166 |
167 | ### Human Evaluation
168 | We can look at the screenshots, supplemented by the agent's thought and action in interact_messages, to determine whether the path meets the requirements of the task.
169 |
170 | ### GPT-4V Based Auto Evaluation
171 | We provide the task, the responses from WebVoyager, and the last k screenshots to the GPT-4V and ask it to judge whether the agent has successfully completed the task.
172 |
173 | We provide our evaluation tool in `evaluation`.
174 | You can perform auto evaluation by executing `evaluation/run_eval.sh`.
175 |
176 | ```bash
177 | #!/bin/bash
178 | nohup python -u auto_eval.py \
179 | --api_key YOUR_OPENAI_API_KEY \
180 | --process_dir ../results/examples \
181 | --max_attached_imgs 15 > evaluation.log &
182 | ```
183 |
184 | Please update the `api_key` and `process_dir` in the above script and then run the following command.
185 | ```bash
186 | cd evaluation
187 | bash run_eval.sh
188 | ```
189 |
190 | ## Citation
191 | If you find our work helpful, please consider citing our paper:
192 | ```
193 | @article{he2024webvoyager,
194 | title={WebVoyager: Building an End-to-End Web Agent with Large Multimodal Models},
195 | author={He, Hongliang and Yao, Wenlin and Ma, Kaixin and Yu, Wenhao and Dai, Yong and Zhang, Hongming and Lan, Zhenzhong and Yu, Dong},
196 | journal={arXiv preprint arXiv:2401.13919},
197 | year={2024}
198 | }
199 | ```
200 |
201 | ## Disclaimer
202 | This is not an officially supported Tencent product. The content generated by the model is influenced by factors such as the non deterministic output of the OpenAI API, changes in prompts, and style changes or pop-ups on website pages, and the project does not guarantee its accuracy. The project does not assume any legal responsibility for any content output from the model, any web pages viewed, or any data obtained, and does not assume any responsibility for any losses that may arise from the use of the relevant resources and output results.
--------------------------------------------------------------------------------
/assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MinorJerry/WebVoyager/5a7896738c10bfb8b9edccce6bb0e0411f8ae569/assets/icon.png
--------------------------------------------------------------------------------
/assets/overall_process_crop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MinorJerry/WebVoyager/5a7896738c10bfb8b9edccce6bb0e0411f8ae569/assets/overall_process_crop.png
--------------------------------------------------------------------------------
/assets/webvoyager_overall_res.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MinorJerry/WebVoyager/5a7896738c10bfb8b9edccce6bb0e0411f8ae569/assets/webvoyager_overall_res.png
--------------------------------------------------------------------------------
/data/tasks_test.jsonl:
--------------------------------------------------------------------------------
1 | {"web_name": "Cambridge Dictionary", "id": "Cambridge Dictionary--29", "ques": "Go to the Plus section of Cambridge Dictionary, find Image quizzes and do an easy quiz about Animals and tell me your final score.", "web": "https://dictionary.cambridge.org/"}
--------------------------------------------------------------------------------
/downloads/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MinorJerry/WebVoyager/5a7896738c10bfb8b9edccce6bb0e0411f8ae569/downloads/.gitkeep
--------------------------------------------------------------------------------
/evaluation/auto_eval.py:
--------------------------------------------------------------------------------
1 | import argparse
2 | import os
3 | import json
4 | import time
5 | import re
6 | import base64
7 |
8 | from openai import OpenAI
9 |
10 | SYSTEM_PROMPT = """As an evaluator, you will be presented with three primary components to assist you in your role:
11 |
12 | 1. Web Task Instruction: This is a clear and specific directive provided in natural language, detailing the online activity to be carried out. These requirements may include conducting searches, verifying information, comparing prices, checking availability, or any other action relevant to the specified web service (such as Amazon, Apple, ArXiv, BBC News, Booking etc).
13 |
14 | 2. Result Screenshots: This is a visual representation of the screen showing the result or intermediate state of performing a web task. It serves as visual proof of the actions taken in response to the instruction.
15 |
16 | 3. Result Response: This is a textual response obtained after the execution of the web task. It serves as textual result in response to the instruction.
17 |
18 | -- You DO NOT NEED to interact with web pages or perform actions such as booking flights or conducting searches on websites.
19 | -- You SHOULD NOT make assumptions based on information not presented in the screenshot when comparing it to the instructions.
20 | -- Your primary responsibility is to conduct a thorough assessment of the web task instruction against the outcome depicted in the screenshot and in the response, evaluating whether the actions taken align with the given instructions.
21 | -- NOTE that the instruction may involve more than one task, for example, locating the garage and summarizing the review. Failing to complete either task, such as not providing a summary, should be considered unsuccessful.
22 | -- NOTE that the screenshot is authentic, but the response provided by LLM is generated at the end of web browsing, and there may be discrepancies between the text and the screenshots.
23 | -- Note the difference: 1) Result response may contradict the screenshot, then the content of the screenshot prevails, 2) The content in the Result response is not mentioned on the screenshot, choose to believe the content.
24 |
25 | You should elaborate on how you arrived at your final evaluation and then provide a definitive verdict on whether the task has been successfully accomplished, either as 'SUCCESS' or 'NOT SUCCESS'."""
26 | USER_PROMPT = """TASK:
27 | Result Response:
28 | screenshots at the end: """
29 |
30 |
31 | def encode_image(image_path):
32 | with open(image_path, "rb") as image_file:
33 | return base64.b64encode(image_file.read()).decode('utf-8')
34 |
35 |
36 | def auto_eval_by_gpt4v(process_dir, openai_client, api_model, img_num):
37 | print(f'--------------------- {process_dir} ---------------------')
38 | res_files = sorted(os.listdir(process_dir))
39 | with open(os.path.join(process_dir, 'interact_messages.json')) as fr:
40 | it_messages = json.load(fr)
41 |
42 | if len(it_messages) == 1:
43 | print('Not find answer for ' + process_dir + ' only system messages')
44 | print()
45 | return 0
46 |
47 | task_info = it_messages[1]["content"]
48 | if type(task_info) == list:
49 | task_info = task_info[0]["text"]
50 | assert 'Now given a task' in task_info
51 | pattern = r"Now given a task:(.+?)Please interact with"
52 | matches = re.search(pattern, task_info)
53 | task_content = matches.group(1).strip()
54 |
55 | ans_info = it_messages[-1]["content"]
56 | if 'Action: ANSWER' not in ans_info:
57 | print('Not find answer for ' + process_dir)
58 | print()
59 | return 0
60 | pattern_ans = r"ANSWER[; ]+\[?(.[^\]]*)\]?"
61 | matches_ans = re.search(pattern_ans, ans_info)
62 | answer_content = matches_ans.group(1).strip()
63 |
64 | # max_screenshot_id = max([int(f[10:].split('.png')[0]) for f in os.listdir(process_dir) if '.png' in f])
65 | # final_screenshot = f'screenshot{max_screenshot_id}.png'
66 | # b64_img = encode_image(os.path.join(process_dir, final_screenshot))
67 | whole_content_img = []
68 | pattern_png = r'screenshot(\d+)\.png'
69 | matches = [(filename, int(re.search(pattern_png, filename).group(1))) for filename in res_files if re.search(pattern_png, filename)]
70 | matches.sort(key=lambda x: x[1])
71 | end_files = matches[-img_num:]
72 | for png_file in end_files:
73 | b64_img = encode_image(os.path.join(process_dir, png_file[0]))
74 | whole_content_img.append(
75 | {
76 | 'type': 'image_url',
77 | 'image_url': {"url": f"data:image/png;base64,{b64_img}"}
78 | }
79 | )
80 |
81 | user_prompt_tmp = USER_PROMPT.replace('', task_content)
82 | user_prompt_tmp = user_prompt_tmp.replace('', answer_content)
83 | user_prompt_tmp = user_prompt_tmp.replace('', str(img_num))
84 | messages = [
85 | {'role': 'system', 'content': SYSTEM_PROMPT},
86 | {
87 | 'role': 'user',
88 | 'content': [
89 | {'type': 'text', 'text': user_prompt_tmp}
90 | ]
91 | + whole_content_img
92 | + [{'type': 'text', 'text': "Your verdict:\n"}]
93 | }
94 | ]
95 | while True:
96 | try:
97 | print('Calling gpt4v API to get the auto evaluation......')
98 | openai_response = openai_client.chat.completions.create(
99 | model=api_model, messages=messages, max_tokens=1000, seed=42, temperature=0
100 | )
101 | print('Prompt Tokens:', openai_response.usage.prompt_tokens, ';',
102 | 'Completion Tokens:', openai_response.usage.completion_tokens)
103 | print('Cost:', openai_response.usage.prompt_tokens/1000 * 0.01
104 | + openai_response.usage.completion_tokens / 1000 * 0.03)
105 |
106 | print('API call complete...')
107 | break
108 | except Exception as e:
109 | print(e)
110 | if type(e).__name__ == 'RateLimitError':
111 | time.sleep(10)
112 | elif type(e).__name__ == 'APIError':
113 | time.sleep(15)
114 | elif type(e).__name__ == 'InvalidRequestError':
115 | exit(0)
116 | else:
117 | time.sleep(10)
118 | gpt_4v_res = openai_response.choices[0].message.content
119 | print_message = messages[1]
120 | for idx in range(len(print_message['content'])):
121 | if print_message['content'][idx]['type'] == 'image_url':
122 | print_message['content'][idx]['image_url'] = {"url": "data:image/png;base64, b64_img"}
123 |
124 | # print_message[1]['content'][1]['image_url'] = {"url": "data:image/png;base64, b64_img"}
125 | print(print_message)
126 | print(gpt_4v_res)
127 |
128 | auto_eval_res = 0 if 'NOT SUCCESS' in gpt_4v_res else 1
129 | if 'SUCCESS' not in gpt_4v_res:
130 | auto_eval_res = None
131 | print('Auto_eval_res:', auto_eval_res)
132 | print()
133 | return auto_eval_res
134 |
135 |
136 | def main():
137 | parser = argparse.ArgumentParser()
138 | parser.add_argument('--process_dir', type=str, default='results')
139 | parser.add_argument('--lesson_dir', type=str, default='results')
140 | parser.add_argument("--api_key", default="key", type=str, help="YOUR_OPENAI_API_KEY")
141 | parser.add_argument("--api_model", default="gpt-4-vision-preview", type=str, help="api model name")
142 | parser.add_argument("--max_attached_imgs", type=int, default=1)
143 | args = parser.parse_args()
144 |
145 | client = OpenAI(api_key=args.api_key)
146 | webs = ['Allrecipes', 'Amazon', 'Apple', 'ArXiv', 'BBC News', 'Booking', 'Cambridge Dictionary',
147 | 'Coursera', 'ESPN', 'GitHub', 'Google Flights', 'Google Map', 'Google Search', 'Huggingface', 'Wolfram Alpha']
148 |
149 | for web in webs:
150 | web_task_res = []
151 | for idx in range(0, 46):
152 | file_dir = os.path.join(args.process_dir, 'task'+web+'--'+str(idx))
153 | if os.path.exists(file_dir):
154 | response = auto_eval_by_gpt4v(file_dir, client, args.api_model, args.max_attached_imgs)
155 | web_task_res.append(response)
156 | else:
157 | pass
158 | if web_task_res:
159 | print(web_task_res)
160 | if __name__ == '__main__':
161 | main()
162 |
--------------------------------------------------------------------------------
/evaluation/run_eval.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | nohup python -u auto_eval.py \
3 | --api_key YOUR_OPENAI_API_KEY \
4 | --process_dir ../results/examples \
5 | --max_attached_imgs 15 > evaluation.log &
--------------------------------------------------------------------------------
/prompts.py:
--------------------------------------------------------------------------------
1 | SYSTEM_PROMPT = """Imagine you are a robot browsing the web, just like humans. Now you need to complete a task. In each iteration, you will receive an Observation that includes a screenshot of a webpage and some texts. This screenshot will feature Numerical Labels placed in the TOP LEFT corner of each Web Element.
2 | Carefully analyze the visual information to identify the Numerical Label corresponding to the Web Element that requires interaction, then follow the guidelines and choose one of the following actions:
3 | 1. Click a Web Element.
4 | 2. Delete existing content in a textbox and then type content.
5 | 3. Scroll up or down. Multiple scrolls are allowed to browse the webpage. Pay attention!! The default scroll is the whole window. If the scroll widget is located in a certain area of the webpage, then you have to specify a Web Element in that area. I would hover the mouse there and then scroll.
6 | 4. Wait. Typically used to wait for unfinished webpage processes, with a duration of 5 seconds.
7 | 5. Go back, returning to the previous webpage.
8 | 6. Google, directly jump to the Google search page. When you can't find information in some websites, try starting over with Google.
9 | 7. Answer. This action should only be chosen when all questions in the task have been solved.
10 |
11 | Correspondingly, Action should STRICTLY follow the format:
12 | - Click [Numerical_Label]
13 | - Type [Numerical_Label]; [Content]
14 | - Scroll [Numerical_Label or WINDOW]; [up or down]
15 | - Wait
16 | - GoBack
17 | - Google
18 | - ANSWER; [content]
19 |
20 | Key Guidelines You MUST follow:
21 | * Action guidelines *
22 | 1) To input text, NO need to click textbox first, directly type content. After typing, the system automatically hits `ENTER` key. Sometimes you should click the search button to apply search filters. Try to use simple language when searching.
23 | 2) You must Distinguish between textbox and search button, don't type content into the button! If no textbox is found, you may need to click the search button first before the textbox is displayed.
24 | 3) Execute only one action per iteration.
25 | 4) STRICTLY Avoid repeating the same action if the webpage remains unchanged. You may have selected the wrong web element or numerical label. Continuous use of the Wait is also NOT allowed.
26 | 5) When a complex Task involves multiple questions or steps, select "ANSWER" only at the very end, after addressing all of these questions (steps). Flexibly combine your own abilities with the information in the web page. Double check the formatting requirements in the task when ANSWER.
27 | * Web Browsing Guidelines *
28 | 1) Don't interact with useless web elements like Login, Sign-in, donation that appear in Webpages. Pay attention to Key Web Elements like search textbox and menu.
29 | 2) Vsit video websites like YouTube is allowed BUT you can't play videos. Clicking to download PDF is allowed and will be analyzed by the Assistant API.
30 | 3) Focus on the numerical labels in the TOP LEFT corner of each rectangle (element). Ensure you don't mix them up with other numbers (e.g. Calendar) on the page.
31 | 4) Focus on the date in task, you must look for results that match the date. It may be necessary to find the correct year, month and day at calendar.
32 | 5) Pay attention to the filter and sort functions on the page, which, combined with scroll, can help you solve conditions like 'highest', 'cheapest', 'lowest', 'earliest', etc. Try your best to find the answer that best fits the task.
33 |
34 | Your reply should strictly follow the format:
35 | Thought: {Your brief thoughts (briefly summarize the info that will help ANSWER)}
36 | Action: {One Action format you choose}
37 |
38 | Then the User will provide:
39 | Observation: {A labeled screenshot Given by User}"""
40 |
41 |
42 | SYSTEM_PROMPT_TEXT_ONLY = """Imagine you are a robot browsing the web, just like humans. Now you need to complete a task. In each iteration, you will receive an Accessibility Tree with numerical label representing information about the page, then follow the guidelines and choose one of the following actions:
43 | 1. Click a Web Element.
44 | 2. Delete existing content in a textbox and then type content.
45 | 3. Scroll up or down. Multiple scrolls are allowed to browse the webpage. Pay attention!! The default scroll is the whole window. If the scroll widget is located in a certain area of the webpage, then you have to specify a Web Element in that area. I would hover the mouse there and then scroll.
46 | 4. Wait. Typically used to wait for unfinished webpage processes, with a duration of 5 seconds.
47 | 5. Go back, returning to the previous webpage.
48 | 6. Google, directly jump to the Google search page. When you can't find information in some websites, try starting over with Google.
49 | 7. Answer. This action should only be chosen when all questions in the task have been solved.
50 |
51 | Correspondingly, Action should STRICTLY follow the format:
52 | - Click [Numerical_Label]
53 | - Type [Numerical_Label]; [Content]
54 | - Scroll [Numerical_Label or WINDOW]; [up or down]
55 | - Wait
56 | - GoBack
57 | - Google
58 | - ANSWER; [content]
59 |
60 | Key Guidelines You MUST follow:
61 | * Action guidelines *
62 | 1) To input text, NO need to click textbox first, directly type content. After typing, the system automatically hits `ENTER` key. Sometimes you should click the search button to apply search filters. Try to use simple language when searching.
63 | 2) You must Distinguish between textbox and search button, don't type content into the button! If no textbox is found, you may need to click the search button first before the textbox is displayed.
64 | 3) Execute only one action per iteration.
65 | 4) STRICTLY Avoid repeating the same action if the webpage remains unchanged. You may have selected the wrong web element or numerical label. Continuous use of the Wait is also NOT allowed.
66 | 5) When a complex Task involves multiple questions or steps, select "ANSWER" only at the very end, after addressing all of these questions (steps). Flexibly combine your own abilities with the information in the web page. Double check the formatting requirements in the task when ANSWER.
67 | * Web Browsing Guidelines *
68 | 1) Don't interact with useless web elements like Login, Sign-in, donation that appear in Webpages. Pay attention to Key Web Elements like search textbox and menu.
69 | 2) Vsit video websites like YouTube is allowed BUT you can't play videos. Clicking to download PDF is allowed and will be analyzed by the Assistant API.
70 | 3) Focus on the date in task, you must look for results that match the date. It may be necessary to find the correct year, month and day at calendar.
71 | 4) Pay attention to the filter and sort functions on the page, which, combined with scroll, can help you solve conditions like 'highest', 'cheapest', 'lowest', 'earliest', etc. Try your best to find the answer that best fits the task.
72 |
73 | Your reply should strictly follow the format:
74 | Thought: {Your brief thoughts (briefly summarize the info that will help ANSWER)}
75 | Action: {One Action format you choose}
76 |
77 | Then the User will provide:
78 | Observation: {Accessibility Tree of a web page}"""
79 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | openai==1.1.1
2 | selenium==4.15.2
3 | pillow==10.1.0
--------------------------------------------------------------------------------
/results/examples/taskAllrecipes--4/interact_messages.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "role": "system",
4 | "content": "Imagine you are a robot browsing the web, just like humans. Now you need to complete a task. In each iteration, you will receive an Observation that includes a screenshot of a webpage and some texts. This screenshot will feature Numerical Labels placed in the TOP LEFT corner of each Web Element.\nCarefully analyze the visual information to identify the Numerical Label corresponding to the Web Element that requires interaction, then follow the guidelines and choose one of the following actions:\n1. Click a Web Element.\n2. Delete existing content in a textbox and then type content. \n3. Scroll up or down. Multiple scrolls are allowed to browse the webpage. Pay attention!! The default scroll is the whole window. If the scroll widget is located in a certain area of the webpage, then you have to specify a Web Element in that area. I would hover the mouse there and then scroll.\n4. Wait. Typically used to wait for unfinished webpage processes, with a duration of 5 seconds.\n5. Go back, returning to the previous webpage.\n6. Google, directly jump to the Google search page. When you can't find information in some websites, try starting over with Google.\n7. Answer. This action should only be chosen when all questions in the task have been solved.\n\nCorrespondingly, Action should STRICTLY follow the format:\n- Click [Numerical_Label]\n- Type [Numerical_Label]; [Content]\n- Scroll [Numerical_Label or WINDOW]; [up or down]\n- Wait\n- GoBack\n- Google\n- ANSWER; [content]\n\nKey Guidelines You MUST follow:\n* Action guidelines *\n1) To input text, NO need to click textbox first, directly type content. After typing, the system automatically hits `ENTER` key. Sometimes you should click the search button to apply search filters. Try to use simple language when searching. \n2) You must Distinguish between textbox and search button, don't type content into the button! If no textbox is found, you may need to click the search button first before the textbox is displayed. \n3) Execute only one action per iteration. \n4) STRICTLY Avoid repeating the same action if the webpage remains unchanged. You may have selected the wrong web element or numerical label. Continuous use of the Wait is also NOT allowed.\n5) When a complex Task involves multiple questions or steps, select \"ANSWER\" only at the very end, after addressing all of these questions (steps). Flexibly combine your own abilities with the information in the web page. Double check the formatting requirements in the task when ANSWER. \n* Web Browsing Guidelines *\n1) Don't interact with useless web elements like Login, Sign-in, donation that appear in Webpages. Pay attention to Key Web Elements like search textbox and menu.\n2) Vsit video websites like YouTube is allowed BUT you can't play videos. Clicking to download PDF is allowed and will be analyzed by the Assistant API.\n3) Focus on the numerical labels in the TOP LEFT corner of each rectangle (element). Ensure you don't mix them up with other numbers (e.g. Calendar) on the page.\n4) Focus on the date in task, you must look for results that match the date. It may be necessary to find the correct year, month and day at calendar.\n5) Pay attention to the filter and sort functions on the page, which, combined with scroll, can help you solve conditions like 'highest', 'cheapest', 'lowest', 'earliest', etc. Try your best to find the answer that best fits the task.\n\nYour reply should strictly follow the format:\nThought: {Your brief thoughts (briefly summarize the info that will help ANSWER)}\nAction: {One Action format you choose}\n\nThen the User will provide:\nObservation: {A labeled screenshot Given by User}"
5 | },
6 | {
7 | "role": "user",
8 | "content": "Now given a task: Find a recipe for Baked Salmon that takes less than 30 minutes to prepare and has at least a 4 star rating based on user reviews. Please interact with https://www.allrecipes.com/ and get the answer.Observation: A screenshot and some texts. (Omitted in context.)"
9 | },
10 | {
11 | "role": "assistant",
12 | "content": "Thought: To find a Baked Salmon recipe that meets the specified criteria, I need to use the search function on the website. In the screenshot, there is a search button indicated with label [2], which I can use to begin the search for recipes.\n\nAction: Click [2]"
13 | },
14 | {
15 | "role": "user",
16 | "content": "Observation: A screenshot and some texts. (Omitted in context.)"
17 | },
18 | {
19 | "role": "assistant",
20 | "content": "Thought: The element labeled [2] appears to be a textbox where I can type a search query to find a recipe. In order to find a recipe for Baked Salmon that meets the user's criteria, I should use this search feature. Since the task requires the recipe to have at least a 4-star rating and a preparation time of less than 30 minutes, I will start the search by typing \"Baked Salmon\" into the search box.\n\nAction: Type [2]; Baked Salmon"
21 | },
22 | {
23 | "role": "user",
24 | "content": "Observation: A screenshot and some texts. (Omitted in context.)"
25 | },
26 | {
27 | "role": "assistant",
28 | "content": "Thought: The search results for \"Baked Salmon\" are displayed, with various recipes visible. However, the screenshot does not show the preparation time for the recipes, and while it shows ratings for some options, I must ensure that I select a recipe with at least a 4-star rating. Since the recipes themselves are not clickable, I need to find a way to further refine the search or access individual recipes to check their preparation times. The screenshot does not provide clear next steps for refining the search based on preparation time and ratings, so I may need to scroll down to see if there are additional filter options or more information.\n\nAction: Scroll [WINDOW]; down"
29 | },
30 | {
31 | "role": "user",
32 | "content": [
33 | {
34 | "type": "text",
35 | "text": "Observation: please analyze the attached screenshot and give the Thought and Action. I've provided the tag name of each element and the text it contains (if text exists). Note that