Spaces:
Sleeping
Sleeping
Upload 140 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +6 -0
- .gitignore +185 -0
- LICENSE +203 -0
- README.md +9 -4
- __pycache__/app.cpython-313.pyc +0 -0
- app.py +725 -0
- app_v1.py +807 -0
- autoreview/__init__.py +8 -0
- autoreview/__pycache__/__init__.cpython-311.pyc +0 -0
- autoreview/__pycache__/__init__.cpython-312.pyc +0 -0
- autoreview/__pycache__/agent.cpython-311.pyc +0 -0
- autoreview/__pycache__/agent.cpython-312.pyc +0 -0
- autoreview/__pycache__/arena.cpython-311.pyc +0 -0
- autoreview/__pycache__/arena.cpython-312.pyc +0 -0
- autoreview/__pycache__/arguments.cpython-311.pyc +0 -0
- autoreview/__pycache__/arguments.cpython-312.pyc +0 -0
- autoreview/__pycache__/config.cpython-311.pyc +0 -0
- autoreview/__pycache__/config.cpython-312.pyc +0 -0
- autoreview/__pycache__/const.cpython-311.pyc +0 -0
- autoreview/__pycache__/const.cpython-312.pyc +0 -0
- autoreview/__pycache__/message.cpython-311.pyc +0 -0
- autoreview/__pycache__/message.cpython-312.pyc +0 -0
- autoreview/__pycache__/paper_review_arena.cpython-311.pyc +0 -0
- autoreview/__pycache__/paper_review_arena.cpython-312.pyc +0 -0
- autoreview/__pycache__/paper_review_message.cpython-311.pyc +0 -0
- autoreview/__pycache__/paper_review_message.cpython-312.pyc +0 -0
- autoreview/__pycache__/paper_review_player.cpython-311.pyc +0 -0
- autoreview/__pycache__/paper_review_player.cpython-312.pyc +0 -0
- autoreview/__pycache__/paper_type_classifier.cpython-311.pyc +0 -0
- autoreview/__pycache__/paper_type_classifier.cpython-312.pyc +0 -0
- autoreview/__pycache__/role_descriptions.cpython-311.pyc +0 -0
- autoreview/__pycache__/role_descriptions.cpython-312.pyc +0 -0
- autoreview/__pycache__/utils.cpython-311.pyc +0 -0
- autoreview/__pycache__/utils.cpython-312.pyc +0 -0
- autoreview/agent.py +255 -0
- autoreview/arena.py +201 -0
- autoreview/arguments.py +171 -0
- autoreview/backends/__init__.py +30 -0
- autoreview/backends/__pycache__/__init__.cpython-311.pyc +0 -0
- autoreview/backends/__pycache__/__init__.cpython-312.pyc +0 -0
- autoreview/backends/__pycache__/anthropic.cpython-311.pyc +0 -0
- autoreview/backends/__pycache__/anthropic.cpython-312.pyc +0 -0
- autoreview/backends/__pycache__/base.cpython-311.pyc +0 -0
- autoreview/backends/__pycache__/base.cpython-312.pyc +0 -0
- autoreview/backends/__pycache__/cohere.cpython-311.pyc +0 -0
- autoreview/backends/__pycache__/cohere.cpython-312.pyc +0 -0
- autoreview/backends/__pycache__/dummy.cpython-311.pyc +0 -0
- autoreview/backends/__pycache__/dummy.cpython-312.pyc +0 -0
- autoreview/backends/__pycache__/hf_transformers.cpython-311.pyc +0 -0
- autoreview/backends/__pycache__/hf_transformers.cpython-312.pyc +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
static/img/Accept_Reject_Reasons_Distribution.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
static/img/Average_Ratings_Biased_Reviewers.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
static/img/ICLR2025_uses_agents.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
static/img/Overview.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
static/img/ReviewPipeline.jpg filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
static/img/ReviewPipeline.png filter=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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
key.py
|
| 4 |
+
|
| 5 |
+
*.pdf
|
| 6 |
+
*.json
|
| 7 |
+
*.png
|
| 8 |
+
*.jpg
|
| 9 |
+
*.jpeg
|
| 10 |
+
*.gif
|
| 11 |
+
data/
|
| 12 |
+
unused_data/
|
| 13 |
+
demo/
|
| 14 |
+
Summary/
|
| 15 |
+
|
| 16 |
+
# Byte-compiled / optimized / DLL files
|
| 17 |
+
__pycache__/
|
| 18 |
+
*.py[cod]
|
| 19 |
+
*$py.class
|
| 20 |
+
|
| 21 |
+
# C extensions
|
| 22 |
+
*.so
|
| 23 |
+
|
| 24 |
+
outputs
|
| 25 |
+
|
| 26 |
+
# Distribution / packaging
|
| 27 |
+
.Python
|
| 28 |
+
build/
|
| 29 |
+
develop-eggs/
|
| 30 |
+
dist/
|
| 31 |
+
downloads/
|
| 32 |
+
eggs/
|
| 33 |
+
.eggs/
|
| 34 |
+
lib/
|
| 35 |
+
lib64/
|
| 36 |
+
parts/
|
| 37 |
+
sdist/
|
| 38 |
+
var/
|
| 39 |
+
wheels/
|
| 40 |
+
pip-wheel-metadata/
|
| 41 |
+
share/python-wheels/
|
| 42 |
+
*.egg-info/
|
| 43 |
+
.installed.cfg
|
| 44 |
+
*.egg
|
| 45 |
+
MANIFEST
|
| 46 |
+
|
| 47 |
+
# PyInstaller
|
| 48 |
+
# Usually these files are written by a python script from a template
|
| 49 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 50 |
+
*.manifest
|
| 51 |
+
*.spec
|
| 52 |
+
|
| 53 |
+
# Installer logs
|
| 54 |
+
pip-log.txt
|
| 55 |
+
pip-delete-this-directory.txt
|
| 56 |
+
|
| 57 |
+
# Unit test / coverage reports
|
| 58 |
+
htmlcov/
|
| 59 |
+
.tox/
|
| 60 |
+
.nox/
|
| 61 |
+
.coverage
|
| 62 |
+
.coverage.*
|
| 63 |
+
.cache
|
| 64 |
+
nosetests.xml
|
| 65 |
+
coverage.xml
|
| 66 |
+
*.cover
|
| 67 |
+
*.py,cover
|
| 68 |
+
.hypothesis/
|
| 69 |
+
.pytest_cache/
|
| 70 |
+
|
| 71 |
+
# Translations
|
| 72 |
+
*.mo
|
| 73 |
+
*.pot
|
| 74 |
+
|
| 75 |
+
# Django stuff:
|
| 76 |
+
*.log
|
| 77 |
+
local_settings.py
|
| 78 |
+
db.sqlite3
|
| 79 |
+
db.sqlite3-journal
|
| 80 |
+
|
| 81 |
+
# Flask stuff:
|
| 82 |
+
instance/
|
| 83 |
+
.webassets-cache
|
| 84 |
+
|
| 85 |
+
# Scrapy stuff:
|
| 86 |
+
.scrapy
|
| 87 |
+
|
| 88 |
+
# Sphinx documentation
|
| 89 |
+
docs/_build/
|
| 90 |
+
|
| 91 |
+
# PyBuilder
|
| 92 |
+
.pybuilder/
|
| 93 |
+
target/
|
| 94 |
+
|
| 95 |
+
# Jupyter Notebook
|
| 96 |
+
.ipynb_checkpoints
|
| 97 |
+
|
| 98 |
+
# IPython
|
| 99 |
+
profile_default/
|
| 100 |
+
ipython_config.py
|
| 101 |
+
|
| 102 |
+
# pyenv
|
| 103 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 104 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 105 |
+
.python-version
|
| 106 |
+
|
| 107 |
+
# pipenv
|
| 108 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 109 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 110 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 111 |
+
# install all needed dependencies.
|
| 112 |
+
#Pipfile.lock
|
| 113 |
+
|
| 114 |
+
# poetry
|
| 115 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 116 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 117 |
+
# commonly ignored for libraries.
|
| 118 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 119 |
+
#poetry.lock
|
| 120 |
+
|
| 121 |
+
# pdm
|
| 122 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 123 |
+
#pdm.lock
|
| 124 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 125 |
+
# in version control.
|
| 126 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 127 |
+
.pdm.toml
|
| 128 |
+
|
| 129 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 130 |
+
__pypackages__/
|
| 131 |
+
|
| 132 |
+
# Celery stuff
|
| 133 |
+
celerybeat-schedule
|
| 134 |
+
celerybeat.pid
|
| 135 |
+
|
| 136 |
+
# SageMath parsed files
|
| 137 |
+
*.sage.py
|
| 138 |
+
|
| 139 |
+
# Environments
|
| 140 |
+
.env
|
| 141 |
+
.venv
|
| 142 |
+
env/
|
| 143 |
+
venv/
|
| 144 |
+
ENV/
|
| 145 |
+
env.bak/
|
| 146 |
+
venv.bak/
|
| 147 |
+
|
| 148 |
+
# Spyder project settings
|
| 149 |
+
.spyderproject
|
| 150 |
+
.spyproject
|
| 151 |
+
|
| 152 |
+
# Rope project settings
|
| 153 |
+
.ropeproject
|
| 154 |
+
|
| 155 |
+
# mkdocs documentation
|
| 156 |
+
/site
|
| 157 |
+
|
| 158 |
+
# mypy
|
| 159 |
+
.mypy_cache/
|
| 160 |
+
.dmypy.json
|
| 161 |
+
dmypy.json
|
| 162 |
+
|
| 163 |
+
# Pyre type checker
|
| 164 |
+
.pyre/
|
| 165 |
+
|
| 166 |
+
# pytype static type analyzer
|
| 167 |
+
.pytype/
|
| 168 |
+
|
| 169 |
+
# Cython debug symbols
|
| 170 |
+
cython_debug/
|
| 171 |
+
|
| 172 |
+
# PyCharm
|
| 173 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 174 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 175 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 176 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 177 |
+
.idea/
|
| 178 |
+
|
| 179 |
+
.DS_Store
|
| 180 |
+
hf-spaces/
|
| 181 |
+
etc/
|
| 182 |
+
.conda
|
| 183 |
+
*.xlsx
|
| 184 |
+
*.csv
|
| 185 |
+
*.zip
|
LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2023 ChatArena. All rights reserved.
|
| 2 |
+
|
| 3 |
+
Apache License
|
| 4 |
+
Version 2.0, January 2004
|
| 5 |
+
http://www.apache.org/licenses/
|
| 6 |
+
|
| 7 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 8 |
+
|
| 9 |
+
1. Definitions.
|
| 10 |
+
|
| 11 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 12 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 13 |
+
|
| 14 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 15 |
+
the copyright owner that is granting the License.
|
| 16 |
+
|
| 17 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 18 |
+
other entities that control, are controlled by, or are under common
|
| 19 |
+
control with that entity. For the purposes of this definition,
|
| 20 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 21 |
+
direction or management of such entity, whether by contract or
|
| 22 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 23 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 24 |
+
|
| 25 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 26 |
+
exercising permissions granted by this License.
|
| 27 |
+
|
| 28 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 29 |
+
including but not limited to software source code, documentation
|
| 30 |
+
source, and configuration files.
|
| 31 |
+
|
| 32 |
+
"Object" form shall mean any form resulting from mechanical
|
| 33 |
+
transformation or translation of a Source form, including but
|
| 34 |
+
not limited to compiled object code, generated documentation,
|
| 35 |
+
and conversions to other media types.
|
| 36 |
+
|
| 37 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 38 |
+
Object form, made available under the License, as indicated by a
|
| 39 |
+
copyright notice that is included in or attached to the work
|
| 40 |
+
(an example is provided in the Appendix below).
|
| 41 |
+
|
| 42 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 43 |
+
form, that is based on (or derived from) the Work and for which the
|
| 44 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 45 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 46 |
+
of this License, Derivative Works shall not include works that remain
|
| 47 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 48 |
+
the Work and Derivative Works thereof.
|
| 49 |
+
|
| 50 |
+
"Contribution" shall mean any work of authorship, including
|
| 51 |
+
the original version of the Work and any modifications or additions
|
| 52 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 53 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 54 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 55 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 56 |
+
means any form of electronic, verbal, or written communication sent
|
| 57 |
+
to the Licensor or its representatives, including but not limited to
|
| 58 |
+
communication on electronic mailing lists, source code control systems,
|
| 59 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 60 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 61 |
+
excluding communication that is conspicuously marked or otherwise
|
| 62 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 63 |
+
|
| 64 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 65 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 66 |
+
subsequently incorporated within the Work.
|
| 67 |
+
|
| 68 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 69 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 70 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 71 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 72 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 73 |
+
Work and such Derivative Works in Source or Object form.
|
| 74 |
+
|
| 75 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 76 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 77 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 78 |
+
(except as stated in this section) patent license to make, have made,
|
| 79 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 80 |
+
where such license applies only to those patent claims licensable
|
| 81 |
+
by such Contributor that are necessarily infringed by their
|
| 82 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 83 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 84 |
+
institute patent litigation against any entity (including a
|
| 85 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 86 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 87 |
+
or contributory patent infringement, then any patent licenses
|
| 88 |
+
granted to You under this License for that Work shall terminate
|
| 89 |
+
as of the date such litigation is filed.
|
| 90 |
+
|
| 91 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 92 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 93 |
+
modifications, and in Source or Object form, provided that You
|
| 94 |
+
meet the following conditions:
|
| 95 |
+
|
| 96 |
+
(a) You must give any other recipients of the Work or
|
| 97 |
+
Derivative Works a copy of this License; and
|
| 98 |
+
|
| 99 |
+
(b) You must cause any modified files to carry prominent notices
|
| 100 |
+
stating that You changed the files; and
|
| 101 |
+
|
| 102 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 103 |
+
that You distribute, all copyright, patent, trademark, and
|
| 104 |
+
attribution notices from the Source form of the Work,
|
| 105 |
+
excluding those notices that do not pertain to any part of
|
| 106 |
+
the Derivative Works; and
|
| 107 |
+
|
| 108 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 109 |
+
distribution, then any Derivative Works that You distribute must
|
| 110 |
+
include a readable copy of the attribution notices contained
|
| 111 |
+
within such NOTICE file, excluding those notices that do not
|
| 112 |
+
pertain to any part of the Derivative Works, in at least one
|
| 113 |
+
of the following places: within a NOTICE text file distributed
|
| 114 |
+
as part of the Derivative Works; within the Source form or
|
| 115 |
+
documentation, if provided along with the Derivative Works; or,
|
| 116 |
+
within a display generated by the Derivative Works, if and
|
| 117 |
+
wherever such third-party notices normally appear. The contents
|
| 118 |
+
of the NOTICE file are for informational purposes only and
|
| 119 |
+
do not modify the License. You may add Your own attribution
|
| 120 |
+
notices within Derivative Works that You distribute, alongside
|
| 121 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 122 |
+
that such additional attribution notices cannot be construed
|
| 123 |
+
as modifying the License.
|
| 124 |
+
|
| 125 |
+
You may add Your own copyright statement to Your modifications and
|
| 126 |
+
may provide additional or different license terms and conditions
|
| 127 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 128 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 129 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 130 |
+
the conditions stated in this License.
|
| 131 |
+
|
| 132 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 133 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 134 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 135 |
+
this License, without any additional terms or conditions.
|
| 136 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 137 |
+
the terms of any separate license agreement you may have executed
|
| 138 |
+
with Licensor regarding such Contributions.
|
| 139 |
+
|
| 140 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 141 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 142 |
+
except as required for reasonable and customary use in describing the
|
| 143 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 144 |
+
|
| 145 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 146 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 147 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 148 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 149 |
+
implied, including, without limitation, any warranties or conditions
|
| 150 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 151 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 152 |
+
appropriateness of using or redistributing the Work and assume any
|
| 153 |
+
risks associated with Your exercise of permissions under this License.
|
| 154 |
+
|
| 155 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 156 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 157 |
+
unless required by applicable law (such as deliberate and grossly
|
| 158 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 159 |
+
liable to You for damages, including any direct, indirect, special,
|
| 160 |
+
incidental, or consequential damages of any character arising as a
|
| 161 |
+
result of this License or out of the use or inability to use the
|
| 162 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 163 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 164 |
+
other commercial damages or losses), even if such Contributor
|
| 165 |
+
has been advised of the possibility of such damages.
|
| 166 |
+
|
| 167 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 168 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 169 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 170 |
+
or other liability obligations and/or rights consistent with this
|
| 171 |
+
License. However, in accepting such obligations, You may act only
|
| 172 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 173 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 174 |
+
defend, and hold each Contributor harmless for any liability
|
| 175 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 176 |
+
of your accepting any such warranty or additional liability.
|
| 177 |
+
|
| 178 |
+
END OF TERMS AND CONDITIONS
|
| 179 |
+
|
| 180 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 181 |
+
|
| 182 |
+
To apply the Apache License to your work, attach the following
|
| 183 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 184 |
+
replaced with your own identifying information. (Don't include
|
| 185 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 186 |
+
comment syntax for the file format. We also recommend that a
|
| 187 |
+
file or class name and description of purpose be included on the
|
| 188 |
+
same "printed page" as the copyright notice for easier
|
| 189 |
+
identification within third-party archives.
|
| 190 |
+
|
| 191 |
+
Copyright [yyyy] [name of copyright owner]
|
| 192 |
+
|
| 193 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 194 |
+
you may not use this file except in compliance with the License.
|
| 195 |
+
You may obtain a copy of the License at
|
| 196 |
+
|
| 197 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 198 |
+
|
| 199 |
+
Unless required by applicable law or agreed to in writing, software
|
| 200 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 201 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 202 |
+
See the License for the specific language governing permissions and
|
| 203 |
+
limitations under the License.
|
README.md
CHANGED
|
@@ -1,13 +1,18 @@
|
|
| 1 |
---
|
| 2 |
title: AutoReview
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: indigo
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: AutoReview
|
| 3 |
+
emoji: 😊
|
| 4 |
colorFrom: indigo
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.4.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
|
| 14 |
+
## License
|
| 15 |
+
|
| 16 |
+
This project is licensed under the Apache-2.0 License.
|
| 17 |
+
|
| 18 |
+
|
__pycache__/app.cpython-313.pyc
ADDED
|
Binary file (22.8 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,725 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
from glob import glob
|
| 6 |
+
from argparse import Namespace
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
from autoreview import const
|
| 12 |
+
from autoreview.config import AgentConfig
|
| 13 |
+
from autoreview.agent import Player
|
| 14 |
+
from autoreview.backends import BACKEND_REGISTRY
|
| 15 |
+
from autoreview.environments import PaperReview
|
| 16 |
+
from autoreview.paper_review_arena import PaperReviewArena
|
| 17 |
+
from autoreview.utility.experiment_utils import initialize_players
|
| 18 |
+
from autoreview.paper_review_player import PaperExtractorPlayer, Reviewer
|
| 19 |
+
from autoreview.role_descriptions import (get_reviewer_description, get_paper_extractor_config)
|
| 20 |
+
|
| 21 |
+
# 该文件的使命是前端交互:构建前端页面,从页面中获取用户的配置,传入后端运行,将结果实时展示到相应模块
|
| 22 |
+
|
| 23 |
+
css = """
|
| 24 |
+
/* 全局样式 */
|
| 25 |
+
* {
|
| 26 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/* 主容器 */
|
| 30 |
+
#col-container {
|
| 31 |
+
max-width: 95%;
|
| 32 |
+
margin: 0 auto;
|
| 33 |
+
display: flex;
|
| 34 |
+
flex-direction: column;
|
| 35 |
+
background: #e3f2fd;
|
| 36 |
+
min-height: 100vh;
|
| 37 |
+
padding: 20px;
|
| 38 |
+
border-radius: 15px;
|
| 39 |
+
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* 头部样式 */
|
| 43 |
+
#header {
|
| 44 |
+
text-align: center;
|
| 45 |
+
background: rgba(255,255,255,0.95);
|
| 46 |
+
padding: 30px;
|
| 47 |
+
border-radius: 15px;
|
| 48 |
+
margin-bottom: 20px;
|
| 49 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
#header h1 {
|
| 53 |
+
color: #2c3e50;
|
| 54 |
+
font-size: 2.5em;
|
| 55 |
+
margin: 0 0 10px 0;
|
| 56 |
+
font-weight: 700;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
#header p {
|
| 60 |
+
color: #7f8c8d;
|
| 61 |
+
font-size: 1.1em;
|
| 62 |
+
margin: 0;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/* 聊天区域 */
|
| 66 |
+
#col-chatbox {
|
| 67 |
+
flex: 1;
|
| 68 |
+
max-height: min(900px, 100%);
|
| 69 |
+
background: rgba(255,255,255,0.95);
|
| 70 |
+
border-radius: 15px;
|
| 71 |
+
padding: 20px;
|
| 72 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
/* 配置区域 */
|
| 77 |
+
#col-config {
|
| 78 |
+
background: rgba(255,255,255,0.95);
|
| 79 |
+
border-radius: 15px;
|
| 80 |
+
padding: 20px;
|
| 81 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
| 82 |
+
margin-left: 20px;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/* 标签样式 */
|
| 86 |
+
#label {
|
| 87 |
+
font-size: 2em;
|
| 88 |
+
padding: 0.5em;
|
| 89 |
+
margin: 0;
|
| 90 |
+
color: #2c3e50;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/* 消息样式 */
|
| 94 |
+
.message {
|
| 95 |
+
font-size: 1.1em;
|
| 96 |
+
line-height: 1.6;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.message-wrap {
|
| 100 |
+
max-height: min(700px, 100vh);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
/* 按钮样式 */
|
| 104 |
+
button {
|
| 105 |
+
background: #FFFFFF;
|
| 106 |
+
border: none;
|
| 107 |
+
color: black;
|
| 108 |
+
padding: 12px 24px;
|
| 109 |
+
border-radius: 25px;
|
| 110 |
+
font-weight: 600;
|
| 111 |
+
transition: all 0.3s ease;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
button:hover {
|
| 115 |
+
transform: translateY(-2px);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/* 下拉框样式 */
|
| 119 |
+
select, .gr-dropdown {
|
| 120 |
+
border-radius: 10px;
|
| 121 |
+
border: 2px solid #e0e0e0;
|
| 122 |
+
padding: 8px 12px;
|
| 123 |
+
transition: all 0.3s ease;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
select:focus, .gr-dropdown:focus {
|
| 127 |
+
border-color: #FFFFFF;
|
| 128 |
+
box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.1);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/* 文本框样式 */
|
| 132 |
+
textarea, .gr-textbox {
|
| 133 |
+
border-radius: 10px;
|
| 134 |
+
border: 2px solid #e0e0e0;
|
| 135 |
+
padding: 12px;
|
| 136 |
+
transition: all 0.3s ease;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
textarea:focus, .gr-textbox:focus {
|
| 140 |
+
border-color: #FFFFFF;
|
| 141 |
+
box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.1);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/* 滑块样式 */
|
| 145 |
+
.gr-slider {
|
| 146 |
+
border-radius: 10px;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/* 标签页样式 */
|
| 150 |
+
.tabs {
|
| 151 |
+
background: rgba(255,255,255,0.9);
|
| 152 |
+
border-radius: 10px;
|
| 153 |
+
padding: 15px;
|
| 154 |
+
margin-bottom: 15px;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/* 文件上传区域 */
|
| 158 |
+
.gr-file, .file-upload, .file-upload-area, .file-drop-zone {
|
| 159 |
+
border: 2px dashed #FFFFFF;
|
| 160 |
+
border-radius: 15px;
|
| 161 |
+
padding: 20px;
|
| 162 |
+
text-align: center;
|
| 163 |
+
background: rgba(100, 181, 246, 0.05);
|
| 164 |
+
transition: all 0.3s ease;
|
| 165 |
+
color: white !important;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.gr-file:hover, .file-upload:hover, .file-upload-area:hover, .file-drop-zone:hover {
|
| 169 |
+
background: rgba(100, 181, 246, 0.1);
|
| 170 |
+
border-color: #42a5f5;
|
| 171 |
+
color: white !important;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/* 文件上传组件内的文本 */
|
| 175 |
+
.gr-file *, .file-upload *, .file-upload-area *, .file-drop-zone * {
|
| 176 |
+
color: white !important;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
/* 响应式设计 */
|
| 180 |
+
@media (max-width: 768px) {
|
| 181 |
+
#col-container {
|
| 182 |
+
max-width: 100%;
|
| 183 |
+
padding: 10px;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
#col-config {
|
| 187 |
+
margin-left: 0;
|
| 188 |
+
margin-top: 20px;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
"""
|
| 192 |
+
# .wrap {min-width: min(640px, 100vh)}
|
| 193 |
+
# #env-desc {max-height: 100px; overflow-y: auto;}
|
| 194 |
+
# .textarea {height: 100px; max-height: 100px;}
|
| 195 |
+
# #chatbot-tab-all {height: 750px; max-height: min(750px, 100%);}
|
| 196 |
+
# #chatbox {height: min(750px, 100%); max-height: min(750px, 100%);}
|
| 197 |
+
# #chatbox.block {height: 730px}
|
| 198 |
+
# .wrap {max-height: 680px;}
|
| 199 |
+
# .scroll-hide {overflow-y: scroll; max-height: 100px;}
|
| 200 |
+
|
| 201 |
+
DEBUG = False
|
| 202 |
+
|
| 203 |
+
DEFAULT_BACKEND = "openai-chat"
|
| 204 |
+
MAX_NUM_PLAYERS = 3 # Changed from 5 to 3 - only reviewers
|
| 205 |
+
DEFAULT_NUM_PLAYERS = 3 # Changed from 5 to 3 - only reviewers
|
| 206 |
+
CURRENT_STEP_INDEX = 0
|
| 207 |
+
|
| 208 |
+
os.environ['OPENAI_API_KEY'] = 'sk-Aors1iVXAbgd7sGwC9Ff781c75D14b74A71d4e63F1E46b68'
|
| 209 |
+
os.environ['OPENAI_BASEURL'] = 'https://api2.aigcbest.top/v1'
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def load_examples():
|
| 214 |
+
example_configs = {}
|
| 215 |
+
# Load json config files from examples folder
|
| 216 |
+
example_files = glob("examples/*.json")
|
| 217 |
+
for example_file in example_files:
|
| 218 |
+
with open(example_file, encoding="utf-8") as f:
|
| 219 |
+
example = json.load(f)
|
| 220 |
+
try:
|
| 221 |
+
example_configs[example["name"]] = example
|
| 222 |
+
except KeyError:
|
| 223 |
+
print(f"Example {example_file} is missing a name field. Skipping.")
|
| 224 |
+
return example_configs
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
EXAMPLE_REGISTRY = load_examples()
|
| 228 |
+
|
| 229 |
+
# DB = SupabaseDB() if supabase_available else None
|
| 230 |
+
|
| 231 |
+
def get_player_components(name, visible):
|
| 232 |
+
with gr.Row():
|
| 233 |
+
with gr.Column():
|
| 234 |
+
role_name = gr.Textbox(
|
| 235 |
+
lines=1,
|
| 236 |
+
show_label=False,
|
| 237 |
+
interactive=True,
|
| 238 |
+
visible=False,
|
| 239 |
+
value=name,
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
# is benign, is_knowledgeable, is_responsible,
|
| 243 |
+
# player_config = gr.CheckboxGroup(
|
| 244 |
+
# choices=["Benign", "Knowledgeable", "Responsible"],
|
| 245 |
+
# label="Reviewer Type",
|
| 246 |
+
# visible=visible,
|
| 247 |
+
# )
|
| 248 |
+
|
| 249 |
+
gr.Markdown(f"### 👨💼 {name} Settings")
|
| 250 |
+
with gr.Row():
|
| 251 |
+
Expertise_config = gr.Dropdown(
|
| 252 |
+
choices=["Machine Learning", "Natural Language Processing", "Computer Vision", "Robotics", "Data Science", "Software Engineering",
|
| 253 |
+
"Bioinformatics", "Computational Biology", "Genomics", "Proteomics", "Systems Biology", "Synthetic Biology",
|
| 254 |
+
"Biomedical Engineering", "Neuroscience", "Drug Discovery", "Medical Imaging", "General"],
|
| 255 |
+
interactive=True,
|
| 256 |
+
label = "🎯 Expertise Area",
|
| 257 |
+
show_label=True,
|
| 258 |
+
value="General",
|
| 259 |
+
allow_custom_value=True
|
| 260 |
+
)
|
| 261 |
+
paper_type_box = gr.Dropdown(
|
| 262 |
+
choices=["Technical Paper", "Survey Paper", "Application Paper", "Dataset Paper", "Tool Paper"],
|
| 263 |
+
interactive=True,
|
| 264 |
+
label="📝 Paper Type",
|
| 265 |
+
show_label=True,
|
| 266 |
+
value="Technical Paper",
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
role_desc = gr.Textbox(
|
| 272 |
+
lines=8,
|
| 273 |
+
max_lines=8,
|
| 274 |
+
show_label=True,
|
| 275 |
+
label="📋 Reviewer Description",
|
| 276 |
+
interactive=True,
|
| 277 |
+
visible=visible,
|
| 278 |
+
autoscroll=False,
|
| 279 |
+
value=get_reviewer_description()
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
def update_role_desc(Expertise_config, paper_type):
|
| 283 |
+
|
| 284 |
+
# Always use reviewer_write_reviews phase since we're only doing Phase I
|
| 285 |
+
phase = 'reviewer_write_reviews'
|
| 286 |
+
return get_reviewer_description(expertise=Expertise_config, paper_type=paper_type, phase=phase)
|
| 287 |
+
|
| 288 |
+
Expertise_config.select(fn=update_role_desc, inputs=[Expertise_config, paper_type_box], outputs=[role_desc])
|
| 289 |
+
paper_type_box.select(fn=update_role_desc, inputs=[Expertise_config, paper_type_box], outputs=[role_desc])
|
| 290 |
+
|
| 291 |
+
with gr.Column():
|
| 292 |
+
with gr.Accordion(
|
| 293 |
+
f"⚙️ {name} Configuration", open=True, visible=visible
|
| 294 |
+
) as accordion:
|
| 295 |
+
temperature = gr.Slider(
|
| 296 |
+
minimum=0.,
|
| 297 |
+
maximum=2.0,
|
| 298 |
+
step=0.1,
|
| 299 |
+
interactive=True,
|
| 300 |
+
visible=visible,
|
| 301 |
+
label="🌡️ Temperature (Creativity)",
|
| 302 |
+
value=1.0,
|
| 303 |
+
)
|
| 304 |
+
max_tokens = gr.Slider(
|
| 305 |
+
minimum=10,
|
| 306 |
+
maximum=600,
|
| 307 |
+
step=10,
|
| 308 |
+
interactive=True,
|
| 309 |
+
visible=visible,
|
| 310 |
+
label="📏 Max Tokens",
|
| 311 |
+
value=600,
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
return [role_name, Expertise_config, paper_type_box, accordion, temperature, max_tokens]
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def get_empty_state():
|
| 321 |
+
return gr.State({"arena": None})
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
with (gr.Blocks(css=css) as demo):
|
| 325 |
+
state = get_empty_state()
|
| 326 |
+
all_components = []
|
| 327 |
+
|
| 328 |
+
with gr.Column(elem_id="col-container"):
|
| 329 |
+
gr.Markdown(
|
| 330 |
+
"""
|
| 331 |
+
# 🤖 AI Paper Review System
|
| 332 |
+
## Intelligent Manuscript Evaluation with Multi-Agent Reviewers
|
| 333 |
+
|
| 334 |
+
**Transform your paper review process with AI-powered reviewers that provide comprehensive feedback.**
|
| 335 |
+
|
| 336 |
+
---
|
| 337 |
+
""",
|
| 338 |
+
elem_id="header",
|
| 339 |
+
)
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
with gr.Row():
|
| 344 |
+
with gr.Column(elem_id="col-chatbox"):
|
| 345 |
+
gr.Markdown("### 💬 Review Progress")
|
| 346 |
+
|
| 347 |
+
player_chatbots = []
|
| 348 |
+
for i in range(MAX_NUM_PLAYERS):
|
| 349 |
+
player_name = f"Reviewer {i + 1}"
|
| 350 |
+
|
| 351 |
+
with gr.Tab(f"👨💼 {player_name}", visible=(i < DEFAULT_NUM_PLAYERS)):
|
| 352 |
+
player_chatbot = gr.Chatbot(
|
| 353 |
+
elem_id=f"chatbox-{i}",
|
| 354 |
+
visible=i < DEFAULT_NUM_PLAYERS,
|
| 355 |
+
label=player_name,
|
| 356 |
+
show_label=False,
|
| 357 |
+
height=600 # FIXME: this parameter is not working
|
| 358 |
+
)
|
| 359 |
+
player_chatbots.append(player_chatbot)
|
| 360 |
+
|
| 361 |
+
all_components += [*player_chatbots]
|
| 362 |
+
|
| 363 |
+
with gr.Column(elem_id="col-config"):
|
| 364 |
+
gr.Markdown("### ⚙️ Configuration Panel")
|
| 365 |
+
# gr.Markdown("Player Configuration")
|
| 366 |
+
|
| 367 |
+
# parallel_checkbox = gr.Checkbox(
|
| 368 |
+
# label="Parallel Actions", value=False, visible=True
|
| 369 |
+
# )
|
| 370 |
+
|
| 371 |
+
all_players_components, players_idx2comp = [], {}
|
| 372 |
+
with gr.Blocks():
|
| 373 |
+
for i in range(MAX_NUM_PLAYERS):
|
| 374 |
+
player_name = f"Reviewer {i + 1}"
|
| 375 |
+
|
| 376 |
+
with gr.Tab(
|
| 377 |
+
f"👨💼 {player_name}", visible=(i < DEFAULT_NUM_PLAYERS)
|
| 378 |
+
) as tab:
|
| 379 |
+
player_comps = get_player_components(
|
| 380 |
+
player_name, visible=(i < DEFAULT_NUM_PLAYERS)
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
players_idx2comp[i] = player_comps + [tab]
|
| 384 |
+
all_players_components += player_comps + [tab]
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
all_components += all_players_components
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
gr.Markdown("### 📄 Upload Your Paper")
|
| 391 |
+
upload_file_box = gr.File(
|
| 392 |
+
visible=True,
|
| 393 |
+
height=120,
|
| 394 |
+
label="Choose PDF file",
|
| 395 |
+
file_types=[".pdf"],
|
| 396 |
+
file_count="single"
|
| 397 |
+
)
|
| 398 |
+
|
| 399 |
+
with gr.Row():
|
| 400 |
+
btn_step = gr.Button("🚀 Start Review", variant="primary", size="lg")
|
| 401 |
+
btn_restart = gr.Button("🔄 Reset", variant="secondary", size="lg")
|
| 402 |
+
|
| 403 |
+
all_components += [upload_file_box, btn_step, btn_restart]
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def _convert_to_chatbot_output(all_messages, display_recv=False):
|
| 407 |
+
chatbot_output = []
|
| 408 |
+
try:
|
| 409 |
+
for i, message in enumerate(all_messages):
|
| 410 |
+
# Handle case where message might be None or invalid
|
| 411 |
+
if not hasattr(message, 'agent_name') or not hasattr(message, 'content'):
|
| 412 |
+
print(f"Warning: Invalid message at index {i}: {message}")
|
| 413 |
+
continue
|
| 414 |
+
|
| 415 |
+
agent_name, msg, recv = (
|
| 416 |
+
message.agent_name,
|
| 417 |
+
message.content,
|
| 418 |
+
str(message.visible_to),
|
| 419 |
+
)
|
| 420 |
+
|
| 421 |
+
# Handle empty or None content
|
| 422 |
+
if not msg or msg.strip() == "":
|
| 423 |
+
print(f"Warning: Empty message from {agent_name}")
|
| 424 |
+
continue
|
| 425 |
+
|
| 426 |
+
new_msg = re.sub(
|
| 427 |
+
r"\n+", "<br>", msg.strip()
|
| 428 |
+
) # Preprocess message for chatbot output
|
| 429 |
+
if display_recv:
|
| 430 |
+
new_msg = f"**{agent_name} (-> {recv})**: {new_msg}" # Add role to the message
|
| 431 |
+
else:
|
| 432 |
+
new_msg = f"**{agent_name}**: {new_msg}"
|
| 433 |
+
|
| 434 |
+
# Convert to Gradio Chatbot format: list of [user_message, bot_message] tuples
|
| 435 |
+
if agent_name == "Moderator":
|
| 436 |
+
chatbot_output.append([new_msg, None])
|
| 437 |
+
else:
|
| 438 |
+
chatbot_output.append([None, new_msg])
|
| 439 |
+
except Exception as e:
|
| 440 |
+
print(f"Error in _convert_to_chatbot_output: {e}")
|
| 441 |
+
print(f"all_messages type: {type(all_messages)}")
|
| 442 |
+
print(f"all_messages content: {all_messages}")
|
| 443 |
+
# Return empty list as fallback
|
| 444 |
+
return []
|
| 445 |
+
return chatbot_output
|
| 446 |
+
|
| 447 |
+
def _create_arena_config_from_components(all_comps: dict):
|
| 448 |
+
|
| 449 |
+
env_desc = const.GLOBAL_PROMPT
|
| 450 |
+
paper_pdf_path = all_comps[upload_file_box]
|
| 451 |
+
|
| 452 |
+
# Step 1: Initialize the players
|
| 453 |
+
num_players = MAX_NUM_PLAYERS
|
| 454 |
+
|
| 455 |
+
# You can ignore these fields for the demo
|
| 456 |
+
conference = "EMNLP2024"
|
| 457 |
+
paper_decision = "Accept"
|
| 458 |
+
data_dir = ''
|
| 459 |
+
paper_id = "12345"
|
| 460 |
+
|
| 461 |
+
args = Namespace(openai_client_type="openai",
|
| 462 |
+
experiment_name="test",
|
| 463 |
+
max_num_words=16384)
|
| 464 |
+
|
| 465 |
+
# Phase I: Only reviewers are active
|
| 466 |
+
players = []
|
| 467 |
+
|
| 468 |
+
# 不能直接获取role_desc,需要根据Intention_config, Knowledge_config, Responsibility_config生成一个配置
|
| 469 |
+
# self.environment.experiment_setting["players"]['Reviewer'][reviewer_index - 1]
|
| 470 |
+
|
| 471 |
+
experiment_setting = {
|
| 472 |
+
"paper_id": paper_id,
|
| 473 |
+
"paper_decision": paper_decision,
|
| 474 |
+
"players": {
|
| 475 |
+
|
| 476 |
+
# Paper Extractor is a special player that extracts a paper from the dataset.
|
| 477 |
+
# Its constructor does not take any arguments.
|
| 478 |
+
"Paper Extractor": [{}],
|
| 479 |
+
|
| 480 |
+
# Reviewer settings are generated based on reviewer types provided in the settings.
|
| 481 |
+
"Reviewer": [],
|
| 482 |
+
},
|
| 483 |
+
# "global_settings": setting['global_settings']
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
for i in range(num_players):
|
| 488 |
+
|
| 489 |
+
role_name = role_desc = temperature = max_tokens = None
|
| 490 |
+
|
| 491 |
+
# All players are reviewers in Phase I only
|
| 492 |
+
role_name, expertise_config, paper_type, temperature, max_tokens = (
|
| 493 |
+
all_comps[c]
|
| 494 |
+
for c in players_idx2comp[i]
|
| 495 |
+
if not isinstance(c, (gr.Accordion, gr.Tab))
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
# Use default backend
|
| 499 |
+
backend_type = DEFAULT_BACKEND
|
| 500 |
+
|
| 501 |
+
# Use default values for other attributes since we removed them from UI
|
| 502 |
+
experiment_setting["players"]['Reviewer'].append({"is_benign": None,
|
| 503 |
+
"is_knowledgeable": None,
|
| 504 |
+
"is_responsible": None,
|
| 505 |
+
"knows_authors": 'unfamous'})
|
| 506 |
+
|
| 507 |
+
role_desc = get_reviewer_description(expertise=expertise_config, paper_type=paper_type)
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
# common config for all players
|
| 512 |
+
player_config = {
|
| 513 |
+
"name": role_name,
|
| 514 |
+
"role_desc": role_desc,
|
| 515 |
+
"global_prompt": env_desc,
|
| 516 |
+
"backend": {
|
| 517 |
+
"backend_type": backend_type,
|
| 518 |
+
"temperature": temperature,
|
| 519 |
+
"max_tokens": max_tokens,
|
| 520 |
+
},
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
player_config = AgentConfig(**player_config)
|
| 524 |
+
|
| 525 |
+
# All players are reviewers in Phase I only
|
| 526 |
+
player = Reviewer(data_dir=data_dir, conference=conference, args=args, **player_config)
|
| 527 |
+
|
| 528 |
+
players.append(player)
|
| 529 |
+
|
| 530 |
+
# Phase I: Create paper extractor for reviewer assessment
|
| 531 |
+
|
| 532 |
+
# Add paper extractor
|
| 533 |
+
paper_extractor_config = get_paper_extractor_config(max_tokens=2048)
|
| 534 |
+
|
| 535 |
+
paper_extractor = PaperExtractorPlayer(paper_pdf_path=paper_pdf_path,
|
| 536 |
+
data_dir=data_dir, paper_id=paper_id,
|
| 537 |
+
paper_decision=paper_decision, args=args,
|
| 538 |
+
conference=conference, **paper_extractor_config)
|
| 539 |
+
players.append(paper_extractor)
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
player_names = [player.name for player in players]
|
| 543 |
+
|
| 544 |
+
# Step 2: Initialize the environment
|
| 545 |
+
env = PaperReview(player_names=player_names, paper_decision=paper_decision, paper_id=paper_id,
|
| 546 |
+
args=args, experiment_setting=experiment_setting)
|
| 547 |
+
|
| 548 |
+
# Step 3: Initialize the Arena
|
| 549 |
+
arena = PaperReviewArena(players=players, environment=env, args=args, global_prompt=env_desc)
|
| 550 |
+
|
| 551 |
+
return arena
|
| 552 |
+
|
| 553 |
+
def step_game(all_comps: dict):
|
| 554 |
+
global CURRENT_STEP_INDEX
|
| 555 |
+
|
| 556 |
+
yield {
|
| 557 |
+
btn_step: gr.update(value="Running...", interactive=False),
|
| 558 |
+
btn_restart: gr.update(interactive=False),
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
cur_state = all_comps[state]
|
| 562 |
+
|
| 563 |
+
# If arena is not yet created, create it
|
| 564 |
+
if cur_state["arena"] is None:
|
| 565 |
+
# Create the Arena
|
| 566 |
+
arena = _create_arena_config_from_components(all_comps)
|
| 567 |
+
cur_state["arena"] = arena
|
| 568 |
+
else:
|
| 569 |
+
arena = cur_state["arena"]
|
| 570 |
+
|
| 571 |
+
# TODO: 连续运行
|
| 572 |
+
|
| 573 |
+
timestep = arena.step()
|
| 574 |
+
|
| 575 |
+
CURRENT_STEP_INDEX = int(arena.environment.phase_index)
|
| 576 |
+
|
| 577 |
+
# 更新前端信息
|
| 578 |
+
if timestep:
|
| 579 |
+
try:
|
| 580 |
+
all_messages = timestep.observation
|
| 581 |
+
|
| 582 |
+
# Initialize update dictionary
|
| 583 |
+
update_dict = {
|
| 584 |
+
btn_step: gr.update(
|
| 585 |
+
value="Next Step", interactive=not timestep.terminal
|
| 586 |
+
),
|
| 587 |
+
btn_restart: gr.update(interactive=True),
|
| 588 |
+
state: cur_state,
|
| 589 |
+
}
|
| 590 |
+
except Exception as e:
|
| 591 |
+
print(f"Error updating main chatbot: {e}")
|
| 592 |
+
# Initialize update dictionary with empty chatbot output
|
| 593 |
+
update_dict = {
|
| 594 |
+
btn_step: gr.update(
|
| 595 |
+
value="Next Step", interactive=not timestep.terminal
|
| 596 |
+
),
|
| 597 |
+
btn_restart: gr.update(interactive=True),
|
| 598 |
+
state: cur_state,
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
# Define a mapping of player names to their respective chatbots
|
| 602 |
+
player_name_to_chatbot = {
|
| 603 |
+
"Reviewer 1": player_chatbots[0],
|
| 604 |
+
"Reviewer 2": player_chatbots[1],
|
| 605 |
+
"Reviewer 3": player_chatbots[2]
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
# Update each player's chatbot output
|
| 609 |
+
for player in arena.players:
|
| 610 |
+
player_name = player.name
|
| 611 |
+
if player_name in player_name_to_chatbot:
|
| 612 |
+
try:
|
| 613 |
+
player_messages = arena.environment.get_messages_from_player(player_name)
|
| 614 |
+
# player_messages[0].content = 'Paper content has been extracted.'
|
| 615 |
+
player_output = _convert_to_chatbot_output(player_messages)
|
| 616 |
+
update_dict[player_name_to_chatbot[player_name]] = player_output
|
| 617 |
+
except Exception as e:
|
| 618 |
+
print(f"Error updating player {player_name} chatbot: {e}")
|
| 619 |
+
# Set empty output as fallback
|
| 620 |
+
update_dict[player_name_to_chatbot[player_name]] = []
|
| 621 |
+
|
| 622 |
+
# # Reviewer 1, 2, 3 Area Chair, Paper Extractor, Author
|
| 623 |
+
# for i, player in enumerate(arena.players):
|
| 624 |
+
# player_name = player.name
|
| 625 |
+
# # Get the messages for the current player
|
| 626 |
+
# player_messages = arena.environment.get_observation(player_name)
|
| 627 |
+
# player_messages[0].content = 'Paper content has been extracted.'
|
| 628 |
+
#
|
| 629 |
+
# # Convert messages to chatbot output
|
| 630 |
+
# player_output = _convert_to_chatbot_output(player_messages)
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
"""
|
| 634 |
+
# Phase I only: All players are reviewers
|
| 635 |
+
if 'Reviewer' in player.name:
|
| 636 |
+
player_messages = arena.environment.get_observation(player.name)
|
| 637 |
+
# 不要显示第一条长段的信息,只显示 文章内容已被抽取
|
| 638 |
+
player_messages[0].content = 'Paper content has been extracted.'
|
| 639 |
+
player_output = _convert_to_chatbot_output(player_messages)
|
| 640 |
+
# Update the player's chatbot output
|
| 641 |
+
update_dict[player_chatbots[i]] = player_output
|
| 642 |
+
"""
|
| 643 |
+
# Ahren: Auto run
|
| 644 |
+
# if not timestep.terminal:
|
| 645 |
+
# yield from step_game(all_comps)
|
| 646 |
+
|
| 647 |
+
yield update_dict
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def restart_game(all_comps: dict):
|
| 651 |
+
global CURRENT_STEP_INDEX
|
| 652 |
+
CURRENT_STEP_INDEX = 0
|
| 653 |
+
|
| 654 |
+
cur_state = all_comps[state]
|
| 655 |
+
cur_state["arena"] = None
|
| 656 |
+
yield {
|
| 657 |
+
btn_restart: gr.update(interactive=False),
|
| 658 |
+
btn_step: gr.update(interactive=False),
|
| 659 |
+
state: cur_state,
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
# arena_config = _create_arena_config_from_components(all_comps)
|
| 663 |
+
# arena = Arena.from_config(arena_config)
|
| 664 |
+
# log_arena(arena, database=DB)
|
| 665 |
+
# cur_state["arena"] = arena
|
| 666 |
+
|
| 667 |
+
yield {
|
| 668 |
+
btn_step: gr.update(value="Start", interactive=True),
|
| 669 |
+
btn_restart: gr.update(interactive=True),
|
| 670 |
+
upload_file_box: gr.update(value=None),
|
| 671 |
+
state: cur_state,
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
# Remove Accordion and Tab from the list of components
|
| 675 |
+
all_components = [
|
| 676 |
+
comp for comp in all_components if not isinstance(comp, (gr.Accordion, gr.Tab))
|
| 677 |
+
]
|
| 678 |
+
|
| 679 |
+
# update component
|
| 680 |
+
|
| 681 |
+
# If any of the Textbox, Slider, Checkbox, Dropdown, RadioButtons is changed, the Step button is disabled
|
| 682 |
+
for comp in all_components:
|
| 683 |
+
|
| 684 |
+
def _disable_step_button(state):
|
| 685 |
+
if state["arena"] is not None:
|
| 686 |
+
return gr.update(interactive=False)
|
| 687 |
+
else:
|
| 688 |
+
return gr.update()
|
| 689 |
+
|
| 690 |
+
if (
|
| 691 |
+
isinstance(
|
| 692 |
+
comp, (gr.Textbox, gr.Slider, gr.Checkbox, gr.Dropdown, gr.Radio)
|
| 693 |
+
)
|
| 694 |
+
and comp is not upload_file_box
|
| 695 |
+
):
|
| 696 |
+
comp.change(_disable_step_button, state, btn_step)
|
| 697 |
+
|
| 698 |
+
# Add paper type change event to update all reviewer descriptions
|
| 699 |
+
def update_all_reviewer_descriptions(paper_type, *reviewer_comps):
|
| 700 |
+
# This function will be called when paper type changes
|
| 701 |
+
# For now, we'll just disable the step button
|
| 702 |
+
return gr.update(interactive=False)
|
| 703 |
+
|
| 704 |
+
# paper_type_box.change(
|
| 705 |
+
# fn=update_all_reviewer_descriptions,
|
| 706 |
+
# inputs=[paper_type_box] + [comp for comp in all_components if "Expertise_config" in str(comp)],
|
| 707 |
+
# outputs=[btn_step]
|
| 708 |
+
# )
|
| 709 |
+
|
| 710 |
+
# Ahren: Auto run
|
| 711 |
+
btn_step.click(
|
| 712 |
+
step_game,
|
| 713 |
+
set(all_components + [state]),
|
| 714 |
+
[*player_chatbots, btn_step, btn_restart, state, upload_file_box],
|
| 715 |
+
)
|
| 716 |
+
|
| 717 |
+
btn_restart.click(
|
| 718 |
+
restart_game,
|
| 719 |
+
set(all_components + [state]),
|
| 720 |
+
[*player_chatbots, btn_step, btn_restart, state, upload_file_box],
|
| 721 |
+
)
|
| 722 |
+
|
| 723 |
+
|
| 724 |
+
demo.queue()
|
| 725 |
+
demo.launch()
|
app_v1.py
ADDED
|
@@ -0,0 +1,807 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
from glob import glob
|
| 6 |
+
from argparse import Namespace
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
from autoreview import const
|
| 12 |
+
from autoreview.config import AgentConfig
|
| 13 |
+
from autoreview.agent import Player
|
| 14 |
+
from autoreview.backends import BACKEND_REGISTRY
|
| 15 |
+
from autoreview.environments import PaperReview
|
| 16 |
+
from autoreview.paper_review_arena import PaperReviewArena
|
| 17 |
+
from autoreview.utility.experiment_utils import initialize_players
|
| 18 |
+
from autoreview.paper_review_player import PaperExtractorPlayer, Reviewer
|
| 19 |
+
from autoreview.role_descriptions import (get_reviewer_description, get_paper_extractor_config)
|
| 20 |
+
from autoreview.paper_type_classifier import PaperTypeClassifier
|
| 21 |
+
from llama_index.readers.file.docs import PDFReader
|
| 22 |
+
|
| 23 |
+
# 该文件的使命是前端交互:构建前端页面,从页面中获取用户的配置,传入后端运行,将结果实时展示到相应模块
|
| 24 |
+
|
| 25 |
+
css = """
|
| 26 |
+
/* 全局样式 */
|
| 27 |
+
* {
|
| 28 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/* 主容器 */
|
| 32 |
+
#col-container {
|
| 33 |
+
max-width: 95%;
|
| 34 |
+
margin: 0 auto;
|
| 35 |
+
display: flex;
|
| 36 |
+
flex-direction: column;
|
| 37 |
+
background: #e3f2fd;
|
| 38 |
+
min-height: 100vh;
|
| 39 |
+
padding: 20px;
|
| 40 |
+
border-radius: 15px;
|
| 41 |
+
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/* 头部样式 */
|
| 45 |
+
#header {
|
| 46 |
+
text-align: center;
|
| 47 |
+
background: rgba(255,255,255,0.95);
|
| 48 |
+
padding: 30px;
|
| 49 |
+
border-radius: 15px;
|
| 50 |
+
margin-bottom: 20px;
|
| 51 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
#header h1 {
|
| 55 |
+
color: #2c3e50;
|
| 56 |
+
font-size: 2.5em;
|
| 57 |
+
margin: 0 0 10px 0;
|
| 58 |
+
font-weight: 700;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
#header p {
|
| 62 |
+
color: #7f8c8d;
|
| 63 |
+
font-size: 1.1em;
|
| 64 |
+
margin: 0;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/* 聊天区域 */
|
| 68 |
+
#col-chatbox {
|
| 69 |
+
flex: 1;
|
| 70 |
+
max-height: min(900px, 100%);
|
| 71 |
+
background: rgba(255,255,255,0.95);
|
| 72 |
+
border-radius: 15px;
|
| 73 |
+
padding: 20px;
|
| 74 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
/* 配置区域 */
|
| 79 |
+
#col-config {
|
| 80 |
+
background: rgba(255,255,255,0.95);
|
| 81 |
+
border-radius: 15px;
|
| 82 |
+
padding: 20px;
|
| 83 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
| 84 |
+
margin-left: 20px;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/* 标签样式 */
|
| 88 |
+
#label {
|
| 89 |
+
font-size: 2em;
|
| 90 |
+
padding: 0.5em;
|
| 91 |
+
margin: 0;
|
| 92 |
+
color: #2c3e50;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/* 消息样式 */
|
| 96 |
+
.message {
|
| 97 |
+
font-size: 1.1em;
|
| 98 |
+
line-height: 1.6;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.message-wrap {
|
| 102 |
+
max-height: min(700px, 100vh);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/* 按钮样式 */
|
| 106 |
+
button {
|
| 107 |
+
background: #FFFFFF;
|
| 108 |
+
border: none;
|
| 109 |
+
color: black;
|
| 110 |
+
padding: 12px 24px;
|
| 111 |
+
border-radius: 25px;
|
| 112 |
+
font-weight: 600;
|
| 113 |
+
transition: all 0.3s ease;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
button:hover {
|
| 117 |
+
transform: translateY(-2px);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/* 下拉框样式 */
|
| 121 |
+
select, .gr-dropdown {
|
| 122 |
+
border-radius: 10px;
|
| 123 |
+
border: 2px solid #e0e0e0;
|
| 124 |
+
padding: 8px 12px;
|
| 125 |
+
transition: all 0.3s ease;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
select:focus, .gr-dropdown:focus {
|
| 129 |
+
border-color: #FFFFFF;
|
| 130 |
+
box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.1);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/* 文本框样式 */
|
| 134 |
+
textarea, .gr-textbox {
|
| 135 |
+
border-radius: 10px;
|
| 136 |
+
border: 2px solid #e0e0e0;
|
| 137 |
+
padding: 12px;
|
| 138 |
+
transition: all 0.3s ease;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
textarea:focus, .gr-textbox:focus {
|
| 142 |
+
border-color: #FFFFFF;
|
| 143 |
+
box-shadow: 0 0 0 3px rgba(100, 181, 246, 0.1);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/* 滑块样式 */
|
| 147 |
+
.gr-slider {
|
| 148 |
+
border-radius: 10px;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/* 标签页样式 */
|
| 152 |
+
.tabs {
|
| 153 |
+
background: rgba(255,255,255,0.9);
|
| 154 |
+
border-radius: 10px;
|
| 155 |
+
padding: 15px;
|
| 156 |
+
margin-bottom: 15px;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
/* 文件上传区域 */
|
| 160 |
+
.gr-file, .file-upload, .file-upload-area, .file-drop-zone {
|
| 161 |
+
border: 2px dashed #FFFFFF;
|
| 162 |
+
border-radius: 15px;
|
| 163 |
+
padding: 20px;
|
| 164 |
+
text-align: center;
|
| 165 |
+
background: rgba(100, 181, 246, 0.05);
|
| 166 |
+
transition: all 0.3s ease;
|
| 167 |
+
color: white !important;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.gr-file:hover, .file-upload:hover, .file-upload-area:hover, .file-drop-zone:hover {
|
| 171 |
+
background: rgba(100, 181, 246, 0.1);
|
| 172 |
+
border-color: #42a5f5;
|
| 173 |
+
color: white !important;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/* 文件上传组件内的文本 */
|
| 177 |
+
.gr-file *, .file-upload *, .file-upload-area *, .file-drop-zone * {
|
| 178 |
+
color: white !important;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/* 响应式设计 */
|
| 182 |
+
@media (max-width: 768px) {
|
| 183 |
+
#col-container {
|
| 184 |
+
max-width: 100%;
|
| 185 |
+
padding: 10px;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
#col-config {
|
| 189 |
+
margin-left: 0;
|
| 190 |
+
margin-top: 20px;
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
"""
|
| 194 |
+
# .wrap {min-width: min(640px, 100vh)}
|
| 195 |
+
# #env-desc {max-height: 100px; overflow-y: auto;}
|
| 196 |
+
# .textarea {height: 100px; max-height: 100px;}
|
| 197 |
+
# #chatbot-tab-all {height: 750px; max-height: min(750px, 100%);}
|
| 198 |
+
# #chatbox {height: min(750px, 100%); max-height: min(750px, 100%);}
|
| 199 |
+
# #chatbox.block {height: 730px}
|
| 200 |
+
# .wrap {max-height: 680px;}
|
| 201 |
+
# .scroll-hide {overflow-y: scroll; max-height: 100px;}
|
| 202 |
+
|
| 203 |
+
DEBUG = False
|
| 204 |
+
|
| 205 |
+
DEFAULT_BACKEND = "openai-chat"
|
| 206 |
+
MAX_NUM_PLAYERS = 3 # Changed from 5 to 3 - only reviewers
|
| 207 |
+
DEFAULT_NUM_PLAYERS = 3 # Changed from 5 to 3 - only reviewers
|
| 208 |
+
CURRENT_STEP_INDEX = 0
|
| 209 |
+
|
| 210 |
+
os.environ['OPENAI_API_KEY'] = 'sk-Aors1iVXAbgd7sGwC9Ff781c75D14b74A71d4e63F1E46b68'
|
| 211 |
+
os.environ['OPENAI_BASEURL'] = 'https://api2.aigcbest.top/v1'
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def load_examples():
|
| 216 |
+
example_configs = {}
|
| 217 |
+
# Load json config files from examples folder
|
| 218 |
+
example_files = glob("examples/*.json")
|
| 219 |
+
for example_file in example_files:
|
| 220 |
+
with open(example_file, encoding="utf-8") as f:
|
| 221 |
+
example = json.load(f)
|
| 222 |
+
try:
|
| 223 |
+
example_configs[example["name"]] = example
|
| 224 |
+
except KeyError:
|
| 225 |
+
print(f"Example {example_file} is missing a name field. Skipping.")
|
| 226 |
+
return example_configs
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
EXAMPLE_REGISTRY = load_examples()
|
| 230 |
+
|
| 231 |
+
# DB = SupabaseDB() if supabase_available else None
|
| 232 |
+
|
| 233 |
+
def auto_detect_paper_type(pdf_file):
|
| 234 |
+
"""Automatically detect paper type from uploaded PDF file."""
|
| 235 |
+
if pdf_file is None:
|
| 236 |
+
return "Technical Paper" # Default fallback
|
| 237 |
+
|
| 238 |
+
try:
|
| 239 |
+
# Create a temporary paper extractor to get paper content
|
| 240 |
+
from pathlib import Path
|
| 241 |
+
import tempfile
|
| 242 |
+
|
| 243 |
+
# Extract text from PDF
|
| 244 |
+
loader = PDFReader()
|
| 245 |
+
document_path = Path(pdf_file.name)
|
| 246 |
+
documents = loader.load_data(file=document_path)
|
| 247 |
+
|
| 248 |
+
# Combine all text
|
| 249 |
+
paper_content = ""
|
| 250 |
+
for doc in documents:
|
| 251 |
+
paper_content += doc.text + " "
|
| 252 |
+
|
| 253 |
+
# Use classifier to detect paper type
|
| 254 |
+
classifier = PaperTypeClassifier()
|
| 255 |
+
detected_type = classifier.classify_paper(paper_content[:2000], use_llm=True)
|
| 256 |
+
|
| 257 |
+
return detected_type
|
| 258 |
+
|
| 259 |
+
except Exception as e:
|
| 260 |
+
print(f"Error in auto-detecting paper type: {e}")
|
| 261 |
+
return "Technical Paper" # Default fallback
|
| 262 |
+
|
| 263 |
+
def update_all_paper_types(detected_type, *paper_type_boxes):
|
| 264 |
+
"""Update all paper type dropdowns with the detected type."""
|
| 265 |
+
# Extract the actual type from the status text
|
| 266 |
+
if isinstance(detected_type, str) and "**Paper Type:**" in detected_type:
|
| 267 |
+
# Extract type from status text like "**Paper Type:** Technical Paper (auto-detected)"
|
| 268 |
+
type_part = detected_type.split("**Paper Type:**")[1].split("(")[0].strip()
|
| 269 |
+
else:
|
| 270 |
+
type_part = detected_type
|
| 271 |
+
|
| 272 |
+
return [type_part] * len(paper_type_boxes)
|
| 273 |
+
|
| 274 |
+
def update_paper_type_status(detected_type):
|
| 275 |
+
"""Update the paper type status display."""
|
| 276 |
+
return f"**Paper Type:** {detected_type} (auto-detected)"
|
| 277 |
+
|
| 278 |
+
def get_player_components(name, visible):
|
| 279 |
+
with gr.Row():
|
| 280 |
+
with gr.Column():
|
| 281 |
+
role_name = gr.Textbox(
|
| 282 |
+
lines=1,
|
| 283 |
+
show_label=False,
|
| 284 |
+
interactive=True,
|
| 285 |
+
visible=False,
|
| 286 |
+
value=name,
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
# is benign, is_knowledgeable, is_responsible,
|
| 290 |
+
# player_config = gr.CheckboxGroup(
|
| 291 |
+
# choices=["Benign", "Knowledgeable", "Responsible"],
|
| 292 |
+
# label="Reviewer Type",
|
| 293 |
+
# visible=visible,
|
| 294 |
+
# )
|
| 295 |
+
|
| 296 |
+
gr.Markdown(f"### 👨💼 {name} Settings")
|
| 297 |
+
with gr.Row():
|
| 298 |
+
Expertise_config = gr.Dropdown(
|
| 299 |
+
choices=["Machine Learning", "Natural Language Processing", "Computer Vision", "Robotics", "Data Science", "Software Engineering",
|
| 300 |
+
"Bioinformatics", "Computational Biology", "Genomics", "Proteomics", "Systems Biology", "Synthetic Biology",
|
| 301 |
+
"Biomedical Engineering", "Neuroscience", "Drug Discovery", "Medical Imaging", "General"],
|
| 302 |
+
interactive=True,
|
| 303 |
+
label = "🎯 Expertise Area",
|
| 304 |
+
show_label=True,
|
| 305 |
+
value="General",
|
| 306 |
+
allow_custom_value=True
|
| 307 |
+
)
|
| 308 |
+
paper_type_box = gr.Dropdown(
|
| 309 |
+
choices=["Technical Paper", "Survey Paper", "Application Paper", "Dataset Paper", "Tool Paper"],
|
| 310 |
+
interactive=True,
|
| 311 |
+
label="📝 Paper Type",
|
| 312 |
+
show_label=True,
|
| 313 |
+
value="Technical Paper",
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
role_desc = gr.Textbox(
|
| 319 |
+
lines=8,
|
| 320 |
+
max_lines=8,
|
| 321 |
+
show_label=True,
|
| 322 |
+
label="📋 Reviewer Description",
|
| 323 |
+
interactive=True,
|
| 324 |
+
visible=visible,
|
| 325 |
+
autoscroll=False,
|
| 326 |
+
value=get_reviewer_description()
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
def update_role_desc(Expertise_config, paper_type):
|
| 330 |
+
|
| 331 |
+
# Always use reviewer_write_reviews phase since we're only doing Phase I
|
| 332 |
+
phase = 'reviewer_write_reviews'
|
| 333 |
+
return get_reviewer_description(expertise=Expertise_config, paper_type=paper_type, phase=phase)
|
| 334 |
+
|
| 335 |
+
Expertise_config.select(fn=update_role_desc, inputs=[Expertise_config, paper_type_box], outputs=[role_desc])
|
| 336 |
+
paper_type_box.select(fn=update_role_desc, inputs=[Expertise_config, paper_type_box], outputs=[role_desc])
|
| 337 |
+
|
| 338 |
+
with gr.Column():
|
| 339 |
+
with gr.Accordion(
|
| 340 |
+
f"⚙️ {name} Configuration", open=True, visible=visible
|
| 341 |
+
) as accordion:
|
| 342 |
+
temperature = gr.Slider(
|
| 343 |
+
minimum=0.,
|
| 344 |
+
maximum=2.0,
|
| 345 |
+
step=0.1,
|
| 346 |
+
interactive=True,
|
| 347 |
+
visible=visible,
|
| 348 |
+
label="🌡️ Temperature (Creativity)",
|
| 349 |
+
value=1.0,
|
| 350 |
+
)
|
| 351 |
+
max_tokens = gr.Slider(
|
| 352 |
+
minimum=10,
|
| 353 |
+
maximum=600,
|
| 354 |
+
step=10,
|
| 355 |
+
interactive=True,
|
| 356 |
+
visible=visible,
|
| 357 |
+
label="📏 Max Tokens",
|
| 358 |
+
value=600,
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
return [role_name, Expertise_config, paper_type_box, accordion, temperature, max_tokens]
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def get_empty_state():
|
| 368 |
+
return gr.State({"arena": None})
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
with (gr.Blocks(css=css) as demo):
|
| 372 |
+
state = get_empty_state()
|
| 373 |
+
all_components = []
|
| 374 |
+
|
| 375 |
+
with gr.Column(elem_id="col-container"):
|
| 376 |
+
gr.Markdown(
|
| 377 |
+
"""
|
| 378 |
+
# 🤖 AI Paper Review System
|
| 379 |
+
## Intelligent Manuscript Evaluation with Multi-Agent Reviewers
|
| 380 |
+
|
| 381 |
+
**Transform your paper review process with AI-powered reviewers that provide comprehensive feedback.**
|
| 382 |
+
|
| 383 |
+
---
|
| 384 |
+
""",
|
| 385 |
+
elem_id="header",
|
| 386 |
+
)
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
with gr.Row():
|
| 391 |
+
with gr.Column(elem_id="col-chatbox"):
|
| 392 |
+
gr.Markdown("### 💬 Review Progress")
|
| 393 |
+
|
| 394 |
+
player_chatbots = []
|
| 395 |
+
for i in range(MAX_NUM_PLAYERS):
|
| 396 |
+
player_name = f"Reviewer {i + 1}"
|
| 397 |
+
|
| 398 |
+
with gr.Tab(f"👨💼 {player_name}", visible=(i < DEFAULT_NUM_PLAYERS)):
|
| 399 |
+
player_chatbot = gr.Chatbot(
|
| 400 |
+
elem_id=f"chatbox-{i}",
|
| 401 |
+
visible=i < DEFAULT_NUM_PLAYERS,
|
| 402 |
+
label=player_name,
|
| 403 |
+
show_label=False,
|
| 404 |
+
height=600 # FIXME: this parameter is not working
|
| 405 |
+
)
|
| 406 |
+
player_chatbots.append(player_chatbot)
|
| 407 |
+
|
| 408 |
+
all_components += [*player_chatbots]
|
| 409 |
+
|
| 410 |
+
with gr.Column(elem_id="col-config"):
|
| 411 |
+
gr.Markdown("### ⚙️ Configuration Panel")
|
| 412 |
+
# gr.Markdown("Player Configuration")
|
| 413 |
+
|
| 414 |
+
# parallel_checkbox = gr.Checkbox(
|
| 415 |
+
# label="Parallel Actions", value=False, visible=True
|
| 416 |
+
# )
|
| 417 |
+
|
| 418 |
+
all_players_components, players_idx2comp = [], {}
|
| 419 |
+
with gr.Blocks():
|
| 420 |
+
for i in range(MAX_NUM_PLAYERS):
|
| 421 |
+
player_name = f"Reviewer {i + 1}"
|
| 422 |
+
|
| 423 |
+
with gr.Tab(
|
| 424 |
+
f"👨💼 {player_name}", visible=(i < DEFAULT_NUM_PLAYERS)
|
| 425 |
+
) as tab:
|
| 426 |
+
player_comps = get_player_components(
|
| 427 |
+
player_name, visible=(i < DEFAULT_NUM_PLAYERS)
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
players_idx2comp[i] = player_comps + [tab]
|
| 431 |
+
all_players_components += player_comps + [tab]
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
all_components += all_players_components
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
gr.Markdown("### 📄 Upload Your Paper")
|
| 438 |
+
upload_file_box = gr.File(
|
| 439 |
+
visible=True,
|
| 440 |
+
height=120,
|
| 441 |
+
label="Choose PDF file",
|
| 442 |
+
file_types=[".pdf"],
|
| 443 |
+
file_count="single"
|
| 444 |
+
)
|
| 445 |
+
|
| 446 |
+
# Add auto-detect button
|
| 447 |
+
with gr.Row():
|
| 448 |
+
auto_detect_btn = gr.Button("🔍 Auto-detect Paper Type", variant="secondary", size="sm")
|
| 449 |
+
paper_type_status = gr.Markdown("**Paper Type:** Technical Paper (default)")
|
| 450 |
+
|
| 451 |
+
with gr.Row():
|
| 452 |
+
btn_step = gr.Button("🚀 Start Review", variant="primary", size="lg")
|
| 453 |
+
btn_restart = gr.Button("🔄 Reset", variant="secondary", size="lg")
|
| 454 |
+
|
| 455 |
+
all_components += [upload_file_box, auto_detect_btn, paper_type_status, btn_step, btn_restart]
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def _convert_to_chatbot_output(all_messages, display_recv=False):
|
| 459 |
+
chatbot_output = []
|
| 460 |
+
try:
|
| 461 |
+
for i, message in enumerate(all_messages):
|
| 462 |
+
# Handle case where message might be None or invalid
|
| 463 |
+
if not hasattr(message, 'agent_name') or not hasattr(message, 'content'):
|
| 464 |
+
print(f"Warning: Invalid message at index {i}: {message}")
|
| 465 |
+
continue
|
| 466 |
+
|
| 467 |
+
agent_name, msg, recv = (
|
| 468 |
+
message.agent_name,
|
| 469 |
+
message.content,
|
| 470 |
+
str(message.visible_to),
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
# Handle empty or None content
|
| 474 |
+
if not msg or msg.strip() == "":
|
| 475 |
+
print(f"Warning: Empty message from {agent_name}")
|
| 476 |
+
continue
|
| 477 |
+
|
| 478 |
+
new_msg = re.sub(
|
| 479 |
+
r"\n+", "<br>", msg.strip()
|
| 480 |
+
) # Preprocess message for chatbot output
|
| 481 |
+
if display_recv:
|
| 482 |
+
new_msg = f"**{agent_name} (-> {recv})**: {new_msg}" # Add role to the message
|
| 483 |
+
else:
|
| 484 |
+
new_msg = f"**{agent_name}**: {new_msg}"
|
| 485 |
+
|
| 486 |
+
# Convert to Gradio Chatbot format: list of [user_message, bot_message] tuples
|
| 487 |
+
if agent_name == "Moderator":
|
| 488 |
+
chatbot_output.append([new_msg, None])
|
| 489 |
+
else:
|
| 490 |
+
chatbot_output.append([None, new_msg])
|
| 491 |
+
except Exception as e:
|
| 492 |
+
print(f"Error in _convert_to_chatbot_output: {e}")
|
| 493 |
+
print(f"all_messages type: {type(all_messages)}")
|
| 494 |
+
print(f"all_messages content: {all_messages}")
|
| 495 |
+
# Return empty list as fallback
|
| 496 |
+
return []
|
| 497 |
+
return chatbot_output
|
| 498 |
+
|
| 499 |
+
def _create_arena_config_from_components(all_comps: dict):
|
| 500 |
+
|
| 501 |
+
env_desc = const.GLOBAL_PROMPT
|
| 502 |
+
paper_pdf_path = all_comps[upload_file_box]
|
| 503 |
+
|
| 504 |
+
# Step 1: Initialize the players
|
| 505 |
+
num_players = MAX_NUM_PLAYERS
|
| 506 |
+
|
| 507 |
+
# You can ignore these fields for the demo
|
| 508 |
+
conference = "EMNLP2024"
|
| 509 |
+
paper_decision = "Accept"
|
| 510 |
+
data_dir = ''
|
| 511 |
+
paper_id = "12345"
|
| 512 |
+
|
| 513 |
+
args = Namespace(openai_client_type="openai",
|
| 514 |
+
experiment_name="test",
|
| 515 |
+
max_num_words=16384)
|
| 516 |
+
|
| 517 |
+
# Phase I: Only reviewers are active
|
| 518 |
+
players = []
|
| 519 |
+
|
| 520 |
+
# 不能直接获取role_desc,需要根据Intention_config, Knowledge_config, Responsibility_config生成一个配置
|
| 521 |
+
# self.environment.experiment_setting["players"]['Reviewer'][reviewer_index - 1]
|
| 522 |
+
|
| 523 |
+
experiment_setting = {
|
| 524 |
+
"paper_id": paper_id,
|
| 525 |
+
"paper_decision": paper_decision,
|
| 526 |
+
"players": {
|
| 527 |
+
|
| 528 |
+
# Paper Extractor is a special player that extracts a paper from the dataset.
|
| 529 |
+
# Its constructor does not take any arguments.
|
| 530 |
+
"Paper Extractor": [{}],
|
| 531 |
+
|
| 532 |
+
# Reviewer settings are generated based on reviewer types provided in the settings.
|
| 533 |
+
"Reviewer": [],
|
| 534 |
+
},
|
| 535 |
+
# "global_settings": setting['global_settings']
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
for i in range(num_players):
|
| 540 |
+
|
| 541 |
+
role_name = role_desc = temperature = max_tokens = None
|
| 542 |
+
|
| 543 |
+
# All players are reviewers in Phase I only
|
| 544 |
+
role_name, expertise_config, paper_type, temperature, max_tokens = (
|
| 545 |
+
all_comps[c]
|
| 546 |
+
for c in players_idx2comp[i]
|
| 547 |
+
if not isinstance(c, (gr.Accordion, gr.Tab))
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
# Use default backend
|
| 551 |
+
backend_type = DEFAULT_BACKEND
|
| 552 |
+
|
| 553 |
+
# Use default values for other attributes since we removed them from UI
|
| 554 |
+
experiment_setting["players"]['Reviewer'].append({"is_benign": None,
|
| 555 |
+
"is_knowledgeable": None,
|
| 556 |
+
"is_responsible": None,
|
| 557 |
+
"knows_authors": 'unfamous'})
|
| 558 |
+
|
| 559 |
+
role_desc = get_reviewer_description(expertise=expertise_config, paper_type=paper_type)
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
# common config for all players
|
| 564 |
+
player_config = {
|
| 565 |
+
"name": role_name,
|
| 566 |
+
"role_desc": role_desc,
|
| 567 |
+
"global_prompt": env_desc,
|
| 568 |
+
"backend": {
|
| 569 |
+
"backend_type": backend_type,
|
| 570 |
+
"temperature": temperature,
|
| 571 |
+
"max_tokens": max_tokens,
|
| 572 |
+
},
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
player_config = AgentConfig(**player_config)
|
| 576 |
+
|
| 577 |
+
# All players are reviewers in Phase I only
|
| 578 |
+
player = Reviewer(data_dir=data_dir, conference=conference, args=args, **player_config)
|
| 579 |
+
|
| 580 |
+
players.append(player)
|
| 581 |
+
|
| 582 |
+
# Phase I: Create paper extractor for reviewer assessment
|
| 583 |
+
|
| 584 |
+
# Add paper extractor
|
| 585 |
+
paper_extractor_config = get_paper_extractor_config(max_tokens=2048)
|
| 586 |
+
|
| 587 |
+
paper_extractor = PaperExtractorPlayer(paper_pdf_path=paper_pdf_path,
|
| 588 |
+
data_dir=data_dir, paper_id=paper_id,
|
| 589 |
+
paper_decision=paper_decision, args=args,
|
| 590 |
+
conference=conference, **paper_extractor_config)
|
| 591 |
+
players.append(paper_extractor)
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
player_names = [player.name for player in players]
|
| 595 |
+
|
| 596 |
+
# Step 2: Initialize the environment
|
| 597 |
+
env = PaperReview(player_names=player_names, paper_decision=paper_decision, paper_id=paper_id,
|
| 598 |
+
args=args, experiment_setting=experiment_setting)
|
| 599 |
+
|
| 600 |
+
# Step 3: Initialize the Arena
|
| 601 |
+
arena = PaperReviewArena(players=players, environment=env, args=args, global_prompt=env_desc)
|
| 602 |
+
|
| 603 |
+
return arena
|
| 604 |
+
|
| 605 |
+
def step_game(all_comps: dict):
|
| 606 |
+
global CURRENT_STEP_INDEX
|
| 607 |
+
|
| 608 |
+
yield {
|
| 609 |
+
btn_step: gr.update(value="Running...", interactive=False),
|
| 610 |
+
btn_restart: gr.update(interactive=False),
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
cur_state = all_comps[state]
|
| 614 |
+
|
| 615 |
+
# If arena is not yet created, create it
|
| 616 |
+
if cur_state["arena"] is None:
|
| 617 |
+
# Create the Arena
|
| 618 |
+
arena = _create_arena_config_from_components(all_comps)
|
| 619 |
+
cur_state["arena"] = arena
|
| 620 |
+
else:
|
| 621 |
+
arena = cur_state["arena"]
|
| 622 |
+
|
| 623 |
+
# TODO: 连续运行
|
| 624 |
+
|
| 625 |
+
timestep = arena.step()
|
| 626 |
+
|
| 627 |
+
CURRENT_STEP_INDEX = int(arena.environment.phase_index)
|
| 628 |
+
|
| 629 |
+
# 更新前端信息
|
| 630 |
+
if timestep:
|
| 631 |
+
try:
|
| 632 |
+
all_messages = timestep.observation
|
| 633 |
+
|
| 634 |
+
# Initialize update dictionary
|
| 635 |
+
update_dict = {
|
| 636 |
+
btn_step: gr.update(
|
| 637 |
+
value="Next Step", interactive=not timestep.terminal
|
| 638 |
+
),
|
| 639 |
+
btn_restart: gr.update(interactive=True),
|
| 640 |
+
state: cur_state,
|
| 641 |
+
}
|
| 642 |
+
except Exception as e:
|
| 643 |
+
print(f"Error updating main chatbot: {e}")
|
| 644 |
+
# Initialize update dictionary with empty chatbot output
|
| 645 |
+
update_dict = {
|
| 646 |
+
btn_step: gr.update(
|
| 647 |
+
value="Next Step", interactive=not timestep.terminal
|
| 648 |
+
),
|
| 649 |
+
btn_restart: gr.update(interactive=True),
|
| 650 |
+
state: cur_state,
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
# Define a mapping of player names to their respective chatbots
|
| 654 |
+
player_name_to_chatbot = {
|
| 655 |
+
"Reviewer 1": player_chatbots[0],
|
| 656 |
+
"Reviewer 2": player_chatbots[1],
|
| 657 |
+
"Reviewer 3": player_chatbots[2]
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
# Update each player's chatbot output
|
| 661 |
+
for player in arena.players:
|
| 662 |
+
player_name = player.name
|
| 663 |
+
if player_name in player_name_to_chatbot:
|
| 664 |
+
try:
|
| 665 |
+
player_messages = arena.environment.get_messages_from_player(player_name)
|
| 666 |
+
# player_messages[0].content = 'Paper content has been extracted.'
|
| 667 |
+
player_output = _convert_to_chatbot_output(player_messages)
|
| 668 |
+
update_dict[player_name_to_chatbot[player_name]] = player_output
|
| 669 |
+
except Exception as e:
|
| 670 |
+
print(f"Error updating player {player_name} chatbot: {e}")
|
| 671 |
+
# Set empty output as fallback
|
| 672 |
+
update_dict[player_name_to_chatbot[player_name]] = []
|
| 673 |
+
|
| 674 |
+
# # Reviewer 1, 2, 3 Area Chair, Paper Extractor, Author
|
| 675 |
+
# for i, player in enumerate(arena.players):
|
| 676 |
+
# player_name = player.name
|
| 677 |
+
# # Get the messages for the current player
|
| 678 |
+
# player_messages = arena.environment.get_observation(player_name)
|
| 679 |
+
# player_messages[0].content = 'Paper content has been extracted.'
|
| 680 |
+
#
|
| 681 |
+
# # Convert messages to chatbot output
|
| 682 |
+
# player_output = _convert_to_chatbot_output(player_messages)
|
| 683 |
+
|
| 684 |
+
|
| 685 |
+
"""
|
| 686 |
+
# Phase I only: All players are reviewers
|
| 687 |
+
if 'Reviewer' in player.name:
|
| 688 |
+
player_messages = arena.environment.get_observation(player.name)
|
| 689 |
+
# 不要显示第一条长段的信息,只显示 文章内容已被抽取
|
| 690 |
+
player_messages[0].content = 'Paper content has been extracted.'
|
| 691 |
+
player_output = _convert_to_chatbot_output(player_messages)
|
| 692 |
+
# Update the player's chatbot output
|
| 693 |
+
update_dict[player_chatbots[i]] = player_output
|
| 694 |
+
"""
|
| 695 |
+
# Ahren: Auto run
|
| 696 |
+
# if not timestep.terminal:
|
| 697 |
+
# yield from step_game(all_comps)
|
| 698 |
+
|
| 699 |
+
yield update_dict
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
def restart_game(all_comps: dict):
|
| 703 |
+
global CURRENT_STEP_INDEX
|
| 704 |
+
CURRENT_STEP_INDEX = 0
|
| 705 |
+
|
| 706 |
+
cur_state = all_comps[state]
|
| 707 |
+
cur_state["arena"] = None
|
| 708 |
+
yield {
|
| 709 |
+
btn_restart: gr.update(interactive=False),
|
| 710 |
+
btn_step: gr.update(interactive=False),
|
| 711 |
+
state: cur_state,
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
# arena_config = _create_arena_config_from_components(all_comps)
|
| 715 |
+
# arena = Arena.from_config(arena_config)
|
| 716 |
+
# log_arena(arena, database=DB)
|
| 717 |
+
# cur_state["arena"] = arena
|
| 718 |
+
|
| 719 |
+
yield {
|
| 720 |
+
btn_step: gr.update(value="Start", interactive=True),
|
| 721 |
+
btn_restart: gr.update(interactive=True),
|
| 722 |
+
upload_file_box: gr.update(value=None),
|
| 723 |
+
state: cur_state,
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
# Remove Accordion and Tab from the list of components
|
| 727 |
+
all_components = [
|
| 728 |
+
comp for comp in all_components if not isinstance(comp, (gr.Accordion, gr.Tab))
|
| 729 |
+
]
|
| 730 |
+
|
| 731 |
+
# update component
|
| 732 |
+
|
| 733 |
+
# If any of the Textbox, Slider, Checkbox, Dropdown, RadioButtons is changed, the Step button is disabled
|
| 734 |
+
for comp in all_components:
|
| 735 |
+
|
| 736 |
+
def _disable_step_button(state):
|
| 737 |
+
if state["arena"] is not None:
|
| 738 |
+
return gr.update(interactive=False)
|
| 739 |
+
else:
|
| 740 |
+
return gr.update()
|
| 741 |
+
|
| 742 |
+
if (
|
| 743 |
+
isinstance(
|
| 744 |
+
comp, (gr.Textbox, gr.Slider, gr.Checkbox, gr.Dropdown, gr.Radio)
|
| 745 |
+
)
|
| 746 |
+
and comp is not upload_file_box
|
| 747 |
+
):
|
| 748 |
+
comp.change(_disable_step_button, state, btn_step)
|
| 749 |
+
|
| 750 |
+
# Add paper type change event to update all reviewer descriptions
|
| 751 |
+
def update_all_reviewer_descriptions(paper_type, *reviewer_comps):
|
| 752 |
+
# This function will be called when paper type changes
|
| 753 |
+
# For now, we'll just disable the step button
|
| 754 |
+
return gr.update(interactive=False)
|
| 755 |
+
|
| 756 |
+
# paper_type_box.change(
|
| 757 |
+
# fn=update_all_reviewer_descriptions,
|
| 758 |
+
# inputs=[paper_type_box] + [comp for comp in all_components if "Expertise_config" in str(comp)],
|
| 759 |
+
# outputs=[btn_step]
|
| 760 |
+
# )
|
| 761 |
+
|
| 762 |
+
# Auto-detect paper type functionality
|
| 763 |
+
# Get all paper type dropdowns from all reviewers
|
| 764 |
+
all_paper_type_boxes = []
|
| 765 |
+
for i in range(MAX_NUM_PLAYERS):
|
| 766 |
+
if i < DEFAULT_NUM_PLAYERS:
|
| 767 |
+
# Get the paper_type_box from each reviewer's components
|
| 768 |
+
paper_type_box = players_idx2comp[i][2] # Index 2 is paper_type_box
|
| 769 |
+
all_paper_type_boxes.append(paper_type_box)
|
| 770 |
+
|
| 771 |
+
# Set up auto-detect button event
|
| 772 |
+
def auto_detect_and_update(pdf_file):
|
| 773 |
+
detected_type = auto_detect_paper_type(pdf_file)
|
| 774 |
+
status_text = update_paper_type_status(detected_type)
|
| 775 |
+
# Return individual values for each dropdown and the status
|
| 776 |
+
return [detected_type] * len(all_paper_type_boxes) + [status_text]
|
| 777 |
+
|
| 778 |
+
# Auto-detect when file is uploaded
|
| 779 |
+
upload_file_box.change(
|
| 780 |
+
fn=auto_detect_and_update,
|
| 781 |
+
inputs=[upload_file_box],
|
| 782 |
+
outputs=all_paper_type_boxes + [paper_type_status]
|
| 783 |
+
)
|
| 784 |
+
|
| 785 |
+
# Manual auto-detect button
|
| 786 |
+
auto_detect_btn.click(
|
| 787 |
+
fn=auto_detect_and_update,
|
| 788 |
+
inputs=[upload_file_box],
|
| 789 |
+
outputs=all_paper_type_boxes + [paper_type_status]
|
| 790 |
+
)
|
| 791 |
+
|
| 792 |
+
# Ahren: Auto run
|
| 793 |
+
btn_step.click(
|
| 794 |
+
step_game,
|
| 795 |
+
set(all_components + [state]),
|
| 796 |
+
[*player_chatbots, btn_step, btn_restart, state, upload_file_box],
|
| 797 |
+
)
|
| 798 |
+
|
| 799 |
+
btn_restart.click(
|
| 800 |
+
restart_game,
|
| 801 |
+
set(all_components + [state]),
|
| 802 |
+
[*player_chatbots, btn_step, btn_restart, state, upload_file_box],
|
| 803 |
+
)
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
demo.queue()
|
| 807 |
+
demo.launch()
|
autoreview/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
ROOT_DIR = (
|
| 4 |
+
os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) + os.path.sep
|
| 5 |
+
)
|
| 6 |
+
EXAMPLES_DIR = os.path.join(ROOT_DIR, "examples")
|
| 7 |
+
|
| 8 |
+
__version__ = "0.1.16"
|
autoreview/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (646 Bytes). View file
|
|
|
autoreview/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (675 Bytes). View file
|
|
|
autoreview/__pycache__/agent.cpython-311.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
autoreview/__pycache__/agent.cpython-312.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
autoreview/__pycache__/arena.cpython-311.pyc
ADDED
|
Binary file (9.7 kB). View file
|
|
|
autoreview/__pycache__/arena.cpython-312.pyc
ADDED
|
Binary file (8.53 kB). View file
|
|
|
autoreview/__pycache__/arguments.cpython-311.pyc
ADDED
|
Binary file (8.58 kB). View file
|
|
|
autoreview/__pycache__/arguments.cpython-312.pyc
ADDED
|
Binary file (8.14 kB). View file
|
|
|
autoreview/__pycache__/config.cpython-311.pyc
ADDED
|
Binary file (8.66 kB). View file
|
|
|
autoreview/__pycache__/config.cpython-312.pyc
ADDED
|
Binary file (6.94 kB). View file
|
|
|
autoreview/__pycache__/const.cpython-311.pyc
ADDED
|
Binary file (9.38 kB). View file
|
|
|
autoreview/__pycache__/const.cpython-312.pyc
ADDED
|
Binary file (9.16 kB). View file
|
|
|
autoreview/__pycache__/message.cpython-311.pyc
ADDED
|
Binary file (7.96 kB). View file
|
|
|
autoreview/__pycache__/message.cpython-312.pyc
ADDED
|
Binary file (7.24 kB). View file
|
|
|
autoreview/__pycache__/paper_review_arena.cpython-311.pyc
ADDED
|
Binary file (7.66 kB). View file
|
|
|
autoreview/__pycache__/paper_review_arena.cpython-312.pyc
ADDED
|
Binary file (6.97 kB). View file
|
|
|
autoreview/__pycache__/paper_review_message.cpython-311.pyc
ADDED
|
Binary file (5.23 kB). View file
|
|
|
autoreview/__pycache__/paper_review_message.cpython-312.pyc
ADDED
|
Binary file (4.07 kB). View file
|
|
|
autoreview/__pycache__/paper_review_player.cpython-311.pyc
ADDED
|
Binary file (6.61 kB). View file
|
|
|
autoreview/__pycache__/paper_review_player.cpython-312.pyc
ADDED
|
Binary file (6.53 kB). View file
|
|
|
autoreview/__pycache__/paper_type_classifier.cpython-311.pyc
ADDED
|
Binary file (5.91 kB). View file
|
|
|
autoreview/__pycache__/paper_type_classifier.cpython-312.pyc
ADDED
|
Binary file (5.39 kB). View file
|
|
|
autoreview/__pycache__/role_descriptions.cpython-311.pyc
ADDED
|
Binary file (23 kB). View file
|
|
|
autoreview/__pycache__/role_descriptions.cpython-312.pyc
ADDED
|
Binary file (19.9 kB). View file
|
|
|
autoreview/__pycache__/utils.cpython-311.pyc
ADDED
|
Binary file (5.17 kB). View file
|
|
|
autoreview/__pycache__/utils.cpython-312.pyc
ADDED
|
Binary file (4.72 kB). View file
|
|
|
autoreview/agent.py
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import re
|
| 3 |
+
import uuid
|
| 4 |
+
from abc import abstractmethod
|
| 5 |
+
from argparse import Namespace
|
| 6 |
+
from typing import List, Union
|
| 7 |
+
|
| 8 |
+
from tenacity import RetryError
|
| 9 |
+
|
| 10 |
+
from .backends import IntelligenceBackend, load_backend
|
| 11 |
+
from .config import AgentConfig, BackendConfig, Configurable
|
| 12 |
+
from .message import SYSTEM_NAME, Message
|
| 13 |
+
|
| 14 |
+
# A special signal sent by the player to indicate that it is not possible to continue the conversation, and it requests to end the conversation.
|
| 15 |
+
# It contains a random UUID string to avoid being exploited by any of the players.
|
| 16 |
+
SIGNAL_END_OF_CONVERSATION = f"<<<<<<END_OF_CONVERSATION>>>>>>{uuid.uuid4()}"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class Agent(Configurable):
|
| 20 |
+
"""An abstract base class for all the agents in the chatArena environment."""
|
| 21 |
+
|
| 22 |
+
@abstractmethod
|
| 23 |
+
def __init__(
|
| 24 |
+
self, name: str, role_desc: str, global_prompt: str = None, *args, **kwargs
|
| 25 |
+
):
|
| 26 |
+
"""
|
| 27 |
+
Initialize the agent.
|
| 28 |
+
|
| 29 |
+
Parameters:
|
| 30 |
+
name (str): The name of the agent.
|
| 31 |
+
role_desc (str): Description of the agent's role.
|
| 32 |
+
global_prompt (str): A universal prompt that applies to all agents. Defaults to None.
|
| 33 |
+
"""
|
| 34 |
+
super().__init__(
|
| 35 |
+
name=name, role_desc=role_desc, global_prompt=global_prompt, **kwargs
|
| 36 |
+
)
|
| 37 |
+
self.name = name
|
| 38 |
+
self.role_desc = role_desc
|
| 39 |
+
self.global_prompt = global_prompt
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Player(Agent):
|
| 43 |
+
"""
|
| 44 |
+
The Player class represents a player in the chatArena environment.
|
| 45 |
+
|
| 46 |
+
A player can observe the environment
|
| 47 |
+
and perform an action (generate a response) based on the observation.
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
def __init__(
|
| 51 |
+
self,
|
| 52 |
+
name: str,
|
| 53 |
+
role_desc: str,
|
| 54 |
+
backend: Union[BackendConfig, IntelligenceBackend],
|
| 55 |
+
global_prompt: str = None,
|
| 56 |
+
args: Namespace = None,
|
| 57 |
+
**kwargs,
|
| 58 |
+
):
|
| 59 |
+
"""
|
| 60 |
+
Initialize the player with a name, role description, backend, and a global prompt.
|
| 61 |
+
|
| 62 |
+
Parameters:
|
| 63 |
+
name (str): The name of the player.
|
| 64 |
+
role_desc (str): Description of the player's role.
|
| 65 |
+
backend (Union[BackendConfig, IntelligenceBackend]): The backend that will be used for decision making. It can be either a LLM backend or a Human backend.
|
| 66 |
+
global_prompt (str): A universal prompt that applies to all players. Defaults to None.
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
self.data_dir = kwargs.pop("data_dir", None)
|
| 70 |
+
self.args = args
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if isinstance(backend, BackendConfig):
|
| 74 |
+
backend_config = backend
|
| 75 |
+
backend_config['openai_client_type'] = args.openai_client_type
|
| 76 |
+
backend = load_backend(backend_config)
|
| 77 |
+
elif isinstance(backend, IntelligenceBackend):
|
| 78 |
+
backend_config = backend.to_config()
|
| 79 |
+
else:
|
| 80 |
+
raise ValueError(
|
| 81 |
+
f"backend must be a BackendConfig or an IntelligenceBackend, but got {type(backend)}"
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
assert (
|
| 85 |
+
name != SYSTEM_NAME
|
| 86 |
+
), f"Player name cannot be {SYSTEM_NAME}, which is reserved for the system."
|
| 87 |
+
|
| 88 |
+
# Register the fields in the _config
|
| 89 |
+
super().__init__(
|
| 90 |
+
name=name,
|
| 91 |
+
role_desc=role_desc,
|
| 92 |
+
backend=backend_config,
|
| 93 |
+
global_prompt=global_prompt,
|
| 94 |
+
**kwargs,
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
self.backend = backend
|
| 98 |
+
|
| 99 |
+
def to_config(self) -> AgentConfig:
|
| 100 |
+
return AgentConfig(
|
| 101 |
+
name=self.name,
|
| 102 |
+
role_desc=self.role_desc,
|
| 103 |
+
backend=self.backend.to_config(),
|
| 104 |
+
global_prompt=self.global_prompt,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
def act(self, observation: List[Message]) -> str:
|
| 108 |
+
"""
|
| 109 |
+
Take an action based on the observation (Generate a response), which can later be parsed to actual actions that affect the game dynamics.
|
| 110 |
+
|
| 111 |
+
Parameters:
|
| 112 |
+
observation (List[Message]): The messages that the player has observed from the environment.
|
| 113 |
+
|
| 114 |
+
Returns:
|
| 115 |
+
str: The action (response) of the player.
|
| 116 |
+
"""
|
| 117 |
+
try:
|
| 118 |
+
response = self.backend.query(
|
| 119 |
+
agent_name=self.name,
|
| 120 |
+
role_desc=self.role_desc,
|
| 121 |
+
history_messages=observation,
|
| 122 |
+
global_prompt=self.global_prompt,
|
| 123 |
+
request_msg=None,
|
| 124 |
+
)
|
| 125 |
+
except RetryError as e:
|
| 126 |
+
err_msg = f"Agent {self.name} failed to generate a response. Error: {e.last_attempt.exception()}. Sending signal to end the conversation."
|
| 127 |
+
logging.warning(err_msg)
|
| 128 |
+
response = SIGNAL_END_OF_CONVERSATION + err_msg
|
| 129 |
+
|
| 130 |
+
return response
|
| 131 |
+
|
| 132 |
+
def __call__(self, observation: List[Message]) -> str:
|
| 133 |
+
return self.act(observation)
|
| 134 |
+
|
| 135 |
+
async def async_act(self, observation: List[Message]) -> str:
|
| 136 |
+
"""
|
| 137 |
+
Async version of act().
|
| 138 |
+
|
| 139 |
+
This is used when you want to generate a response asynchronously.
|
| 140 |
+
|
| 141 |
+
Parameters:
|
| 142 |
+
observation (List[Message]): The messages that the player has observed from the environment.
|
| 143 |
+
|
| 144 |
+
Returns:
|
| 145 |
+
str: The action (response) of the player.
|
| 146 |
+
"""
|
| 147 |
+
try:
|
| 148 |
+
response = self.backend.async_query(
|
| 149 |
+
agent_name=self.name,
|
| 150 |
+
role_desc=self.role_desc,
|
| 151 |
+
history_messages=observation,
|
| 152 |
+
global_prompt=self.global_prompt,
|
| 153 |
+
request_msg=None,
|
| 154 |
+
)
|
| 155 |
+
except RetryError as e:
|
| 156 |
+
err_msg = f"Agent {self.name} failed to generate a response. Error: {e.last_attempt.exception()}. Sending signal to end the conversation."
|
| 157 |
+
logging.warning(err_msg)
|
| 158 |
+
response = SIGNAL_END_OF_CONVERSATION + err_msg
|
| 159 |
+
|
| 160 |
+
return response
|
| 161 |
+
|
| 162 |
+
def reset(self):
|
| 163 |
+
"""
|
| 164 |
+
Reset the player's backend in case they are not stateless.
|
| 165 |
+
|
| 166 |
+
This is usually called at the end of each episode.
|
| 167 |
+
"""
|
| 168 |
+
self.backend.reset()
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class Moderator(Player):
|
| 172 |
+
"""
|
| 173 |
+
The Moderator class represents a special type of player that moderates the conversation.
|
| 174 |
+
|
| 175 |
+
It is usually used as a component of the environment when the transition dynamics is conditioned on natural language that are not easy to parse programmatically.
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
def __init__(
|
| 179 |
+
self,
|
| 180 |
+
role_desc: str,
|
| 181 |
+
backend: Union[BackendConfig, IntelligenceBackend],
|
| 182 |
+
terminal_condition: str,
|
| 183 |
+
global_prompt: str = None,
|
| 184 |
+
**kwargs,
|
| 185 |
+
):
|
| 186 |
+
"""
|
| 187 |
+
Initialize the moderator with a role description, backend, terminal condition, and a global prompt.
|
| 188 |
+
|
| 189 |
+
Parameters:
|
| 190 |
+
role_desc (str): Description of the moderator's role.
|
| 191 |
+
backend (Union[BackendConfig, IntelligenceBackend]): The backend that will be used for decision making.
|
| 192 |
+
terminal_condition (str): The condition that signifies the end of the conversation.
|
| 193 |
+
global_prompt (str): A universal prompt that applies to the moderator. Defaults to None.
|
| 194 |
+
"""
|
| 195 |
+
name = "Moderator"
|
| 196 |
+
super().__init__(
|
| 197 |
+
name=name,
|
| 198 |
+
role_desc=role_desc,
|
| 199 |
+
backend=backend,
|
| 200 |
+
global_prompt=global_prompt,
|
| 201 |
+
**kwargs,
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
self.terminal_condition = terminal_condition
|
| 205 |
+
|
| 206 |
+
def to_config(self) -> AgentConfig:
|
| 207 |
+
return AgentConfig(
|
| 208 |
+
name=self.name,
|
| 209 |
+
role_desc=self.role_desc,
|
| 210 |
+
backend=self.backend.to_config(),
|
| 211 |
+
terminal_condition=self.terminal_condition,
|
| 212 |
+
global_prompt=self.global_prompt,
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
def is_terminal(self, history: List[Message], *args, **kwargs) -> bool:
|
| 216 |
+
"""
|
| 217 |
+
Check whether an episode is terminated based on the terminal condition.
|
| 218 |
+
|
| 219 |
+
Parameters:
|
| 220 |
+
history (List[Message]): The conversation history.
|
| 221 |
+
|
| 222 |
+
Returns:
|
| 223 |
+
bool: True if the conversation is over, otherwise False.
|
| 224 |
+
"""
|
| 225 |
+
# If the last message is the signal, then the conversation is over
|
| 226 |
+
if history[-1].content == SIGNAL_END_OF_CONVERSATION:
|
| 227 |
+
return True
|
| 228 |
+
|
| 229 |
+
try:
|
| 230 |
+
request_msg = Message(
|
| 231 |
+
agent_name=self.name, content=self.terminal_condition, turn=-1
|
| 232 |
+
)
|
| 233 |
+
response = self.backend.query(
|
| 234 |
+
agent_name=self.name,
|
| 235 |
+
role_desc=self.role_desc,
|
| 236 |
+
history_messages=history,
|
| 237 |
+
global_prompt=self.global_prompt,
|
| 238 |
+
request_msg=request_msg,
|
| 239 |
+
*args,
|
| 240 |
+
**kwargs,
|
| 241 |
+
)
|
| 242 |
+
except RetryError as e:
|
| 243 |
+
logging.warning(
|
| 244 |
+
f"Agent {self.name} failed to generate a response. "
|
| 245 |
+
f"Error: {e.last_attempt.exception()}."
|
| 246 |
+
)
|
| 247 |
+
return True
|
| 248 |
+
|
| 249 |
+
if re.match(
|
| 250 |
+
r"yes|y|yea|yeah|yep|yup|sure|ok|okay|alright", response, re.IGNORECASE
|
| 251 |
+
):
|
| 252 |
+
# print(f"Decision: {response}. Conversation is ended by moderator.")
|
| 253 |
+
return True
|
| 254 |
+
else:
|
| 255 |
+
return False
|
autoreview/arena.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import json
|
| 3 |
+
import logging
|
| 4 |
+
import uuid
|
| 5 |
+
from typing import Dict, List, Union
|
| 6 |
+
|
| 7 |
+
from .agent import Player
|
| 8 |
+
from .backends import Human
|
| 9 |
+
from .config import ArenaConfig
|
| 10 |
+
from .environments import Environment, TimeStep, load_environment
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TooManyInvalidActions(Exception):
|
| 14 |
+
pass
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class Arena:
|
| 18 |
+
"""Utility class that manages the game environment and players."""
|
| 19 |
+
|
| 20 |
+
def __init__(
|
| 21 |
+
self, players: List[Player], environment: Environment, args, global_prompt: str = None
|
| 22 |
+
):
|
| 23 |
+
# Create a container for the players and environment and reset the game
|
| 24 |
+
self.players = players
|
| 25 |
+
self.environment = environment
|
| 26 |
+
self.global_prompt = global_prompt
|
| 27 |
+
|
| 28 |
+
self.current_timestep = environment.reset()
|
| 29 |
+
self.uuid = uuid.uuid4() # Generate a unique id for the game
|
| 30 |
+
self.invalid_actions_retry = 5
|
| 31 |
+
self.args = args
|
| 32 |
+
|
| 33 |
+
@property
|
| 34 |
+
def num_players(self):
|
| 35 |
+
return self.environment.num_players
|
| 36 |
+
|
| 37 |
+
@property
|
| 38 |
+
def name_to_player(self) -> Dict[str, Player]:
|
| 39 |
+
return {player.name: player for player in self.players}
|
| 40 |
+
|
| 41 |
+
def reset(self) -> TimeStep:
|
| 42 |
+
# Reset the environment
|
| 43 |
+
self.current_timestep = self.environment.reset()
|
| 44 |
+
# Reset the players
|
| 45 |
+
for player in self.players:
|
| 46 |
+
player.reset()
|
| 47 |
+
# Reset the uuid
|
| 48 |
+
self.uuid = uuid.uuid4()
|
| 49 |
+
return self.current_timestep
|
| 50 |
+
|
| 51 |
+
def step(self) -> TimeStep:
|
| 52 |
+
"""Take a step in the game: one player takes an action and the environment updates."""
|
| 53 |
+
player_name = self.environment.get_next_player()
|
| 54 |
+
player = self.name_to_player[player_name] # get the player object
|
| 55 |
+
observation = self.environment.get_observation(
|
| 56 |
+
player_name
|
| 57 |
+
) # get the observation for the player
|
| 58 |
+
|
| 59 |
+
timestep = None
|
| 60 |
+
for i in range(
|
| 61 |
+
self.invalid_actions_retry
|
| 62 |
+
): # try to take an action for a few times
|
| 63 |
+
action = player(observation) # take an action
|
| 64 |
+
if self.environment.check_action(action, player_name): # action is valid
|
| 65 |
+
timestep = self.environment.step(
|
| 66 |
+
player_name, action
|
| 67 |
+
) # update the environment
|
| 68 |
+
break
|
| 69 |
+
else: # action is invalid
|
| 70 |
+
logging.warning(f"{player_name} made an invalid action {action}")
|
| 71 |
+
continue
|
| 72 |
+
|
| 73 |
+
if (
|
| 74 |
+
timestep is None
|
| 75 |
+
): # if the player made invalid actions for too many times, terminate the game
|
| 76 |
+
warning_msg = f"{player_name} has made invalid actions for {self.invalid_actions_retry} times. Terminating the game."
|
| 77 |
+
logging.warning(warning_msg)
|
| 78 |
+
raise TooManyInvalidActions(warning_msg)
|
| 79 |
+
|
| 80 |
+
return timestep
|
| 81 |
+
|
| 82 |
+
def next_is_human(self):
|
| 83 |
+
"""Check if the next player is human."""
|
| 84 |
+
player_name = self.environment.get_next_player()
|
| 85 |
+
player = self.name_to_player[player_name]
|
| 86 |
+
return isinstance(player.backend, Human)
|
| 87 |
+
|
| 88 |
+
def run(self, num_steps: int = 1):
|
| 89 |
+
"""Run the game for num_turns."""
|
| 90 |
+
for i in range(num_steps):
|
| 91 |
+
timestep = self.step()
|
| 92 |
+
if timestep.terminal:
|
| 93 |
+
break
|
| 94 |
+
|
| 95 |
+
@classmethod
|
| 96 |
+
def from_config(cls, config: Union[str, ArenaConfig]):
|
| 97 |
+
"""Create an arena from a config."""
|
| 98 |
+
# If config is a path, load the config
|
| 99 |
+
if isinstance(config, str):
|
| 100 |
+
config = ArenaConfig.load(config)
|
| 101 |
+
|
| 102 |
+
global_prompt = config.get("global_prompt", None)
|
| 103 |
+
|
| 104 |
+
# Create the players
|
| 105 |
+
players = []
|
| 106 |
+
for player_config in config.players:
|
| 107 |
+
# Add public_prompt to the player config
|
| 108 |
+
if global_prompt is not None:
|
| 109 |
+
player_config["global_prompt"] = global_prompt
|
| 110 |
+
|
| 111 |
+
player = Player.from_config(player_config)
|
| 112 |
+
players.append(player)
|
| 113 |
+
|
| 114 |
+
# Check that the player names are unique
|
| 115 |
+
player_names = [player.name for player in players]
|
| 116 |
+
assert len(player_names) == len(
|
| 117 |
+
set(player_names)
|
| 118 |
+
), "Player names must be unique"
|
| 119 |
+
|
| 120 |
+
# Create the environment
|
| 121 |
+
config.environment[
|
| 122 |
+
"player_names"
|
| 123 |
+
] = player_names # add the player names to the environment config
|
| 124 |
+
env = load_environment(config.environment)
|
| 125 |
+
|
| 126 |
+
return cls(players, env, global_prompt=global_prompt)
|
| 127 |
+
|
| 128 |
+
def to_config(self) -> ArenaConfig:
|
| 129 |
+
"""Convert the arena to a config."""
|
| 130 |
+
# return {
|
| 131 |
+
# "players": [player.to_config() for player in self.players],
|
| 132 |
+
# "environment": self.environment.to_config(),
|
| 133 |
+
# "global_prompt": self.global_prompt
|
| 134 |
+
# }
|
| 135 |
+
return ArenaConfig(
|
| 136 |
+
players=[player.to_config() for player in self.players],
|
| 137 |
+
environment=self.environment.to_config(),
|
| 138 |
+
global_prompt=self.global_prompt,
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
def launch_cli(self, max_steps: int = None, interactive: bool = True):
|
| 142 |
+
"""Launch the command line interface."""
|
| 143 |
+
from autoreview.ui.cli import ArenaCLI
|
| 144 |
+
|
| 145 |
+
cli = ArenaCLI(self)
|
| 146 |
+
cli.launch(max_steps=max_steps, interactive=interactive)
|
| 147 |
+
|
| 148 |
+
def save_config(self, path: str):
|
| 149 |
+
"""Save the config to a file."""
|
| 150 |
+
config = self.to_config()
|
| 151 |
+
config.save(path)
|
| 152 |
+
|
| 153 |
+
def save_history(self, path: str):
|
| 154 |
+
"""
|
| 155 |
+
Save the history of the game to a file.
|
| 156 |
+
|
| 157 |
+
Supports csv and json formats.
|
| 158 |
+
"""
|
| 159 |
+
messages = self.environment.get_observation()
|
| 160 |
+
message_rows = []
|
| 161 |
+
|
| 162 |
+
if path.endswith(".csv"):
|
| 163 |
+
header = [
|
| 164 |
+
"agent_name",
|
| 165 |
+
"content",
|
| 166 |
+
"turn",
|
| 167 |
+
"timestamp",
|
| 168 |
+
"visible_to",
|
| 169 |
+
"msg_type",
|
| 170 |
+
]
|
| 171 |
+
for message in messages:
|
| 172 |
+
message_row = [
|
| 173 |
+
message.agent_name,
|
| 174 |
+
message.content,
|
| 175 |
+
message.turn,
|
| 176 |
+
str(message.timestamp),
|
| 177 |
+
message.visible_to,
|
| 178 |
+
message.msg_type,
|
| 179 |
+
]
|
| 180 |
+
message_rows.append(message_row)
|
| 181 |
+
|
| 182 |
+
with open(path, "w") as f:
|
| 183 |
+
writer = csv.writer(f)
|
| 184 |
+
writer.writerow(header)
|
| 185 |
+
writer.writerows(message_rows)
|
| 186 |
+
elif path.endswith(".json"):
|
| 187 |
+
for message in messages:
|
| 188 |
+
message_row = {
|
| 189 |
+
"agent_name": message.agent_name,
|
| 190 |
+
"content": message.content,
|
| 191 |
+
"turn": message.turn,
|
| 192 |
+
"timestamp": str(message.timestamp),
|
| 193 |
+
"visible_to": message.visible_to,
|
| 194 |
+
"msg_type": message.msg_type,
|
| 195 |
+
}
|
| 196 |
+
message_rows.append(message_row)
|
| 197 |
+
|
| 198 |
+
with open(path, "w") as f:
|
| 199 |
+
json.dump(message_rows, f, indent=2)
|
| 200 |
+
else:
|
| 201 |
+
raise ValueError("Invalid file format")
|
autoreview/arguments.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
logger = logging.getLogger(__name__)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def parse_args():
|
| 9 |
+
parser = argparse.ArgumentParser(description="Argument parser for configuring OpenAI API and experiment settings")
|
| 10 |
+
|
| 11 |
+
# Authentication details for OpenAI API
|
| 12 |
+
parser.add_argument(
|
| 13 |
+
"--openai_key", type=str, default=None,
|
| 14 |
+
help="API key to authenticate with OpenAI. Can be set via this argument or through the OPENAI_API_KEY environment variable."
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
parser.add_argument(
|
| 18 |
+
"--deployment", type=str, default=None,
|
| 19 |
+
help="For Azure OpenAI: the deployment name to be used when calling the API."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
parser.add_argument(
|
| 23 |
+
"--openai_client_type", type=str, default="openai", choices=["openai", "azure_openai"],
|
| 24 |
+
help="Specify the OpenAI client type to use: 'openai' for standard OpenAI API or 'azure_openai' for Azure-hosted OpenAI services."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
parser.add_argument(
|
| 28 |
+
"--endpoint", type=str, default=None,
|
| 29 |
+
help="For Azure OpenAI: custom endpoint to access the API. Should be in the format 'https://<your-endpoint>.openai.azure.com'."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
parser.add_argument(
|
| 33 |
+
"--api_version", type=str, default="2023-05-15", help="API version to be used for making requests. Required "
|
| 34 |
+
"for Azure OpenAI clients."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Experiment configuration
|
| 38 |
+
parser.add_argument(
|
| 39 |
+
"--ac_scoring_method", type=str, default="ranking", choices=["recommendation", "ranking"],
|
| 40 |
+
help="Specifies the scoring method used by the Area Chair (AC) to evaluate papers: 'recommendation' or 'ranking'."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
parser.add_argument(
|
| 44 |
+
"--conference", type=str, default="ICLR2023",
|
| 45 |
+
help="Conference name where the papers are being evaluated, e.g., 'ICLR2023'."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
parser.add_argument(
|
| 49 |
+
"--num_reviewers_per_paper", type=int, default=3, help="The number of reviewers assigned to each paper."
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
parser.add_argument(
|
| 53 |
+
"--experiment_name",
|
| 54 |
+
type=str, default=None, required=False,
|
| 55 |
+
help="Specifies the name of the experiment to run. Choose from predefined experiment types based on the reviewer and AC behavior or experiment configuration."
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
parser.add_argument(
|
| 59 |
+
"--overwrite", action="store_true",
|
| 60 |
+
help="If set, existing results or output files will be overwritten without prompting."
|
| 61 |
+
)
|
| 62 |
+
parser.add_argument(
|
| 63 |
+
"--skip_logging", action="store_true", help="If set, we do not log the messages in the console."
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
parser.add_argument(
|
| 67 |
+
"--num_papers_per_area_chair", type=int, default=10,
|
| 68 |
+
help="The number of papers each area chair is assigned for evaluation."
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Model configuration
|
| 72 |
+
parser.add_argument(
|
| 73 |
+
"--model_name", type=str, default="gpt-4o", choices=["gpt-4", "gpt-4o", "gpt-35-turbo"],
|
| 74 |
+
help="Specifies which GPT model to use: 'gpt-4' for the standard GPT-4 model, 'gpt-35-turbo' for a "
|
| 75 |
+
"cost-effective alternative, or 'gpt-4o' for larger context support."
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
# Output directories
|
| 79 |
+
parser.add_argument(
|
| 80 |
+
"--output_dir", type=str, default="outputs", help="Directory where results, logs, and outputs will be stored."
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Output directories
|
| 84 |
+
parser.add_argument(
|
| 85 |
+
"--max_num_words", type=int, default=16384, help="Maximum number of words in the paper."
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
parser.add_argument(
|
| 89 |
+
"--visual_dir", type=str, default="outputs/visual",
|
| 90 |
+
help="Directory where visualization files (such as graphs and plots) will be stored."
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# System configuration
|
| 94 |
+
parser.add_argument(
|
| 95 |
+
"--device", type=str, default='cuda',
|
| 96 |
+
help="The device to be used for processing (e.g., 'cuda' for GPU acceleration or 'cpu' for standard processing)."
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
parser.add_argument(
|
| 100 |
+
"--data_dir", type=str, default='data', help="Directory where input data (e.g., papers) are stored."
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
parser.add_argument(
|
| 104 |
+
"--acceptance_rate", type=float, default=0.32,
|
| 105 |
+
help="Percentage of papers to accept. We use 0.32, the average acceptance rate for ICLR 2020 - 2023"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
args = parser.parse_args()
|
| 109 |
+
|
| 110 |
+
# Ensure necessary directories exist
|
| 111 |
+
os.makedirs(args.visual_dir, exist_ok=True)
|
| 112 |
+
os.makedirs(args.output_dir, exist_ok=True)
|
| 113 |
+
|
| 114 |
+
# Set 'player_to_test' based on experiment name
|
| 115 |
+
if args.experiment_name is None:
|
| 116 |
+
args.player_to_test = None
|
| 117 |
+
elif "Rx" in args.experiment_name:
|
| 118 |
+
args.player_to_test = "Reviewer"
|
| 119 |
+
elif "ACx" in args.experiment_name:
|
| 120 |
+
args.player_to_test = "Area Chair"
|
| 121 |
+
elif "no_rebuttal" in args.experiment_name or "no_overall_score" in args.experiment_name:
|
| 122 |
+
args.player_to_test = "Review Mechanism"
|
| 123 |
+
|
| 124 |
+
# Sanity checks for authentication
|
| 125 |
+
print("Running sanity checks for the arguments...")
|
| 126 |
+
|
| 127 |
+
if args.openai_client_type == "openai":
|
| 128 |
+
if os.environ.get('OPENAI_API_KEY') is None:
|
| 129 |
+
assert isinstance(args.openai_key, str), ("Please specify the `--openai_key` argument OR set the "
|
| 130 |
+
"OPENAI_API_KEY environment variable.")
|
| 131 |
+
raise ValueError("OpenAI key is missing.")
|
| 132 |
+
|
| 133 |
+
EXISTING_EXPERIMENT_SETTINGS = [
|
| 134 |
+
"BASELINE", "benign_Rx1", "malicious_Rx1", "malicious_Rx2", "malicious_Rx3", "unknowledgeable_Rx1",
|
| 135 |
+
"knowledgeable_Rx1", "responsible_Rx1", "irresponsible_Rx1", "irresponsible_Rx2", "irresponsible_Rx3",
|
| 136 |
+
"inclusive_ACx1", "authoritarian_ACx1", "conformist_ACx1", "no_numeric_ratings"]
|
| 137 |
+
|
| 138 |
+
if args.experiment_name not in EXISTING_EXPERIMENT_SETTINGS:
|
| 139 |
+
logger.warning(f"Experiment name '{args.experiment_name}' is not recognized. "
|
| 140 |
+
f"This can happen if you are customizing your own experiment settings. "
|
| 141 |
+
f"Otherwise, please choose from the following: "
|
| 142 |
+
f"{EXISTING_EXPERIMENT_SETTINGS}")
|
| 143 |
+
|
| 144 |
+
if args.openai_client_type == "azure_openai":
|
| 145 |
+
if os.environ.get('AZURE_OPENAI_KEY') is None:
|
| 146 |
+
assert isinstance(args.openai_key, str), ("Please specify the `--openai_key` argument OR set the "
|
| 147 |
+
"AZURE_OPENAI_KEY environment variable.")
|
| 148 |
+
os.environ['AZURE_OPENAI_KEY'] = args.openai_key
|
| 149 |
+
|
| 150 |
+
if os.environ.get('AZURE_DEPLOYMENT') is None:
|
| 151 |
+
assert isinstance(args.deployment, str), ("Please specify the `--deployment` argument OR set the "
|
| 152 |
+
"AZURE_DEPLOYMENT environment variable.")
|
| 153 |
+
os.environ['AZURE_DEPLOYMENT'] = args.deployment
|
| 154 |
+
|
| 155 |
+
if os.environ.get('AZURE_ENDPOINT') is None:
|
| 156 |
+
assert isinstance(args.endpoint, str), ("Please specify the `--endpoint` argument OR set the "
|
| 157 |
+
"AZURE_ENDPOINT environment variable.")
|
| 158 |
+
endpoint = args.endpoint
|
| 159 |
+
else:
|
| 160 |
+
endpoint = os.environ.get('AZURE_ENDPOINT')
|
| 161 |
+
|
| 162 |
+
if not endpoint.startswith("https://"):
|
| 163 |
+
endpoint = f"https://{endpoint}.openai.azure.com"
|
| 164 |
+
os.environ['AZURE_ENDPOINT'] = endpoint
|
| 165 |
+
|
| 166 |
+
if os.environ.get('OPENAI_API_VERSION') is None:
|
| 167 |
+
assert isinstance(args.api_version, str), ("Please specify the `--api_version` argument OR set the "
|
| 168 |
+
"OPENAI_API_VERSION environment variable.")
|
| 169 |
+
os.environ['OPENAI_API_VERSION'] = args.api_version
|
| 170 |
+
|
| 171 |
+
return args
|
autoreview/backends/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..config import BackendConfig
|
| 2 |
+
from .anthropic import Claude
|
| 3 |
+
from .base import IntelligenceBackend
|
| 4 |
+
from .cohere import CohereAIChat
|
| 5 |
+
from .hf_transformers import TransformersConversational
|
| 6 |
+
from .human import Human
|
| 7 |
+
from .openai import OpenAIChat
|
| 8 |
+
from .dummy import Dummy
|
| 9 |
+
|
| 10 |
+
ALL_BACKENDS = [
|
| 11 |
+
Human,
|
| 12 |
+
OpenAIChat,
|
| 13 |
+
CohereAIChat,
|
| 14 |
+
TransformersConversational,
|
| 15 |
+
Claude,
|
| 16 |
+
Dummy,
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
BACKEND_REGISTRY = {backend.type_name: backend for backend in ALL_BACKENDS}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# Load a backend from a config dictionary
|
| 23 |
+
def load_backend(config: BackendConfig):
|
| 24 |
+
try:
|
| 25 |
+
backend_cls = BACKEND_REGISTRY[config.backend_type]
|
| 26 |
+
except KeyError:
|
| 27 |
+
raise ValueError(f"Unknown backend type: {config.backend_type}")
|
| 28 |
+
|
| 29 |
+
backend = backend_cls.from_config(config)
|
| 30 |
+
return backend
|
autoreview/backends/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.47 kB). View file
|
|
|
autoreview/backends/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|
autoreview/backends/__pycache__/anthropic.cpython-311.pyc
ADDED
|
Binary file (5.02 kB). View file
|
|
|
autoreview/backends/__pycache__/anthropic.cpython-312.pyc
ADDED
|
Binary file (4.55 kB). View file
|
|
|
autoreview/backends/__pycache__/base.cpython-311.pyc
ADDED
|
Binary file (3.02 kB). View file
|
|
|
autoreview/backends/__pycache__/base.cpython-312.pyc
ADDED
|
Binary file (2.7 kB). View file
|
|
|
autoreview/backends/__pycache__/cohere.cpython-311.pyc
ADDED
|
Binary file (5 kB). View file
|
|
|
autoreview/backends/__pycache__/cohere.cpython-312.pyc
ADDED
|
Binary file (4.66 kB). View file
|
|
|
autoreview/backends/__pycache__/dummy.cpython-311.pyc
ADDED
|
Binary file (1.11 kB). View file
|
|
|
autoreview/backends/__pycache__/dummy.cpython-312.pyc
ADDED
|
Binary file (942 Bytes). View file
|
|
|
autoreview/backends/__pycache__/hf_transformers.cpython-311.pyc
ADDED
|
Binary file (6.14 kB). View file
|
|
|
autoreview/backends/__pycache__/hf_transformers.cpython-312.pyc
ADDED
|
Binary file (5.05 kB). View file
|
|
|