Image-Text-to-Text
Transformers
English
gamescaling
game-agent
embodied-agent
keyboard-mouse
continued-pretraining
qwen3_5
Instructions to use THUSI-Lab/GameScaling with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use THUSI-Lab/GameScaling with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="THUSI-Lab/GameScaling")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("THUSI-Lab/GameScaling", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use THUSI-Lab/GameScaling with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "THUSI-Lab/GameScaling" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "THUSI-Lab/GameScaling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/THUSI-Lab/GameScaling
- SGLang
How to use THUSI-Lab/GameScaling with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "THUSI-Lab/GameScaling" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "THUSI-Lab/GameScaling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "THUSI-Lab/GameScaling" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "THUSI-Lab/GameScaling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use THUSI-Lab/GameScaling with Docker Model Runner:
docker model run hf.co/THUSI-Lab/GameScaling
Add 0.8B and 2B (S1, S3) checkpoints, prompt skeleton
Browse files- README.md +54 -13
- models/0p8b_s1_1600h_gs6736/model.safetensors +3 -0
- models/0p8b_s3_1600h_gs6760/model.safetensors +3 -0
- models/2b_s1_1600h_gs6736/model.safetensors +3 -0
- models/2b_s3_1600h_gs6760/model.safetensors +3 -0
- prompts/example_doom_battle1.txt +28 -0
- prompts/system_prompt_template.txt +23 -0
- tests/test_core.py +11 -0
README.md
CHANGED
|
@@ -16,6 +16,9 @@ gamescaling/ 核心包,只依赖 requests + Pillow
|
|
| 16 |
policy.py 多轮客户端:历史窗口、图像编码、请求体
|
| 17 |
action.py 动作格式与反解(200 ms chunk -> 6 x 33 ms 键鼠)
|
| 18 |
keymaps.py 训练词表 <-> 浏览器/Playwright 键名
|
|
|
|
|
|
|
|
|
|
| 19 |
models/ 8 个 Qwen3.5 checkpoint,各自带 chat_template.jinja
|
| 20 |
scripts/serve_vllm.sh 起 OpenAI 兼容服务
|
| 21 |
tests/test_core.py 离线单测(不需要 GPU)
|
|
@@ -50,7 +53,45 @@ bash scripts/serve_vllm.sh /path/to/checkpoint 8000 # 单卡即可跑 0.8B-
|
|
| 50 |
`chat_template.jinja`(vLLM 默认就会用),**不要**换成原版 Qwen 模板:自带模板会把没有
|
| 51 |
思维链的历史轮渲染成 `<think>\n\n</think>\n\n<|action_start|>...`,与训练样本逐 token 一致。
|
| 52 |
|
| 53 |
-
## 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
```python
|
| 56 |
from PIL import Image
|
|
@@ -83,13 +124,13 @@ a.parsed # False = 无法解析,按 no-op 执行
|
|
| 83 |
`PolicyConfig.preset("omnigamearena" | "vizdoom" | "gameworld")`:前两档把画面缩到 854×480;
|
| 84 |
`gameworld` 不预填 `<think>`,提示词要用 `build_gameworld_system_prompt(..., reasoning=False)`。
|
| 85 |
|
| 86 |
-
##
|
| 87 |
|
| 88 |
所有 benchmark 用同一骨架,顺序固定(`gamescaling/prompt.py`):
|
| 89 |
|
| 90 |
1. **开场白**:游戏专家 + 游戏名 + "规划接下来 200ms、6 步、每步 33ms" 的契约;
|
| 91 |
2. `**Game Rules**`:游戏是什么、怎么计分;
|
| 92 |
-
3. **操作说明**:本游戏用到的键,**必须写成训练词表**(见 §
|
| 93 |
4. `**Task Instruction**`:仅 GameWorld(一个游戏有多个任务);
|
| 94 |
5. `**Output Format**`:模型据此决定输出格式;
|
| 95 |
6. `**Explanation**` + `**Key Naming Rules**`。
|
|
@@ -127,7 +168,7 @@ assistant "<think>"(仅 think_prefill 时,continue_final_message=True)
|
|
| 127 |
历史轮只放动作(`history_think=0`,论文口径)。解析失败的轮在历史里存成显式 no-op
|
| 128 |
`<|action_start|>0 0 0 ; ; ; ; ; ; <|action_end|>`,而不是模型的原始坏输出。
|
| 129 |
|
| 130 |
-
##
|
| 131 |
|
| 132 |
```
|
| 133 |
<|action_start|>X Y Z ; g1 ; g2 ; g3 ; g4 ; g5 ; g6<|action_end|>
|
|
@@ -158,12 +199,12 @@ assistant "<think>"(仅 think_prefill 时,continue_final_message=True)
|
|
| 158 |
不在词表里的 token 被丢弃(记在 `Action.dropped`)。`keymaps.TO_PLAYWRIGHT` 给出到浏览器
|
| 159 |
键名的映射。
|
| 160 |
|
| 161 |
-
##
|
| 162 |
|
| 163 |
三者都是**暂停时钟(pdq)**:模型思考时游戏冻结,只在执行 chunk 时前进。论文所有主表都是这个
|
| 164 |
口径;不同时钟之间的分数不可比。
|
| 165 |
|
| 166 |
-
###
|
| 167 |
|
| 168 |
```bash
|
| 169 |
pip install -r requirements.txt vizdoom==1.2.4
|
|
@@ -177,7 +218,7 @@ tic(35 tic/s),每个子步单独 `make_action(vec, 1)`。鼠标按 Doom
|
|
| 177 |
6 个 tic 上均分;HUD 开。计分:battle 图数击杀,defend 图击杀减死亡;`overall` 是四图均值的均值。
|
| 178 |
场景文件来源见 `integrations/vizdoom/scenarios/PROVENANCE.md`。
|
| 179 |
|
| 180 |
-
###
|
| 181 |
|
| 182 |
在 [OmniGameArena](https://github.com/mxlin043/OmniGameArena)(测于 `f3a4057`)里注册
|
| 183 |
agent kind `gamescaling`:
|
|
@@ -205,7 +246,7 @@ benchmark 分数;OVERALL 是七个游戏的均值。
|
|
| 205 |
- `solo_craft` 的后续 episode 请换一个新的 UE5 进程;复用实例时第 2、3 局会立即结束并复报
|
| 206 |
第 1 局分数。
|
| 207 |
|
| 208 |
-
###
|
| 209 |
|
| 210 |
在 [GameWorld](https://github.com/gameworld-project/gameworld)(测于 `e236a39`)里注册模型
|
| 211 |
id `gamescaling`:
|
|
@@ -233,17 +274,17 @@ python run_suite.py --suite <your_suite.yaml> # 批量:suite 里 mode
|
|
| 233 |
的 WASD 映射成方向键(模型主要在 PC 游戏上训练,习惯用 WASD 移动)。环境变量
|
| 234 |
`GAMESCALING_ENDPOINT` 可覆盖服务地址,`GAMESCALING_THINK=1` 可打开 think prefill(非论文口径)。
|
| 235 |
|
| 236 |
-
##
|
| 237 |
|
| 238 |
-
1. 用 `build_system_prompt` 写提示词:游戏名、规则、`key_bindings` 用训练词表;鼠标控视角
|
| 239 |
时加 `mouse_aim=True`;`reasoning` 与 `think_prefill` 一致。
|
| 240 |
2. 每 200 ms(或暂停时钟下每次决策)截一帧,调用 `policy.act(frame)`。
|
| 241 |
-
3. 按 §
|
| 242 |
4. 新游戏沿用默认客户端(原尺寸画面、预填 `<think>`、`build_system_prompt` 标准格式)。
|
| 243 |
要对齐论文某一张表时,再改用
|
| 244 |
`PolicyConfig.preset("omnigamearena" | "vizdoom" | "gameworld")`。
|
| 245 |
|
| 246 |
-
##
|
| 247 |
|
| 248 |
发布代码与论文内部评测代码逐项对拍过:三个 benchmark 的全部系统提示词逐字节相同
|
| 249 |
(ViZDoom 4 图、OmniGameArena 12 游戏 44 个 prompt、GameWorld 170 个任务),历史 trace
|
|
@@ -258,7 +299,7 @@ python run_suite.py --suite <your_suite.yaml> # 批量:suite 里 mode
|
|
| 258 |
- OmniGameArena 的 `map_wait` 用上游默认 3 s。内部评测等 60 s,但前 3 s 之后世界是冻结的,
|
| 259 |
所以两者进入第一步时的游戏时间一致。
|
| 260 |
|
| 261 |
-
##
|
| 262 |
|
| 263 |
```bash
|
| 264 |
python tests/test_core.py # 或 python -m pytest tests/;离线:提示词、请求体、动作反解,不需要 GPU / 服务
|
|
|
|
| 16 |
policy.py 多轮客户端:历史窗口、图像编码、请求体
|
| 17 |
action.py 动作格式与反解(200 ms chunk -> 6 x 33 ms 键鼠)
|
| 18 |
keymaps.py 训练词表 <-> 浏览器/Playwright 键名
|
| 19 |
+
prompts/
|
| 20 |
+
system_prompt_template.txt 标准系统提示词骨架,填三个占位符即可用于任意游戏
|
| 21 |
+
example_doom_battle1.txt 填好的示例
|
| 22 |
models/ 8 个 Qwen3.5 checkpoint,各自带 chat_template.jinja
|
| 23 |
scripts/serve_vllm.sh 起 OpenAI 兼容服务
|
| 24 |
tests/test_core.py 离线单测(不需要 GPU)
|
|
|
|
| 53 |
`chat_template.jinja`(vLLM 默认就会用),**不要**换成原版 Qwen 模板:自带模板会把没有
|
| 54 |
思维链的历史轮渲染成 `<think>\n\n</think>\n\n<|action_start|>...`,与训练样本逐 token 一致。
|
| 55 |
|
| 56 |
+
## 2. 系统提示词骨架
|
| 57 |
+
|
| 58 |
+
`prompts/system_prompt_template.txt` 是标准系统提示词,只有三处要按游戏填写,其余部分**原样保留**
|
| 59 |
+
(checkpoint 依赖 Output Format 那一段的精确文本来决定输出标签):
|
| 60 |
+
|
| 61 |
+
| 占位符 | 填什么 | 示例 |
|
| 62 |
+
|---|---|---|
|
| 63 |
+
| `{GAME_NAME}` | 游戏名,出现两次(开场白和键位标题) | `Doom Battle-1` |
|
| 64 |
+
| `{GAME_RULES}` | 游戏是什么、目标、怎么计分,一段英文 | `Kill as many monsters as possible; collect health and ammo.` |
|
| 65 |
+
| `{KEY_BINDINGS}` | 每行一个 `- <键> -> <作用>`,键名必须用训练词表(见 §5) | 见下 |
|
| 66 |
+
|
| 67 |
+
`{KEY_BINDINGS}` 的写法:
|
| 68 |
+
|
| 69 |
+
```text
|
| 70 |
+
- W -> Move forward
|
| 71 |
+
- S -> Move backward
|
| 72 |
+
- A -> Strafe left
|
| 73 |
+
- D -> Strafe right
|
| 74 |
+
- LB -> Fire
|
| 75 |
+
- Mouse X Y -> aim / rotate the camera (X>0 right, Y>0 down)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
最后一行只在鼠标控制视角的游戏里加,并且必须原样照抄。键名规则:字母大写(`W`),数字键写
|
| 79 |
+
`zero`..`nine`,F1-F12 写 `One`..`Twelve`,鼠标键写 `LB` / `RB` / `MB`,方向键写
|
| 80 |
+
`Up` / `Down` / `Left` / `Right`。填好的完整示例见 `prompts/example_doom_battle1.txt`。
|
| 81 |
+
|
| 82 |
+
直接用文本文件:
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
tpl = open("prompts/system_prompt_template.txt").read().rstrip("\n")
|
| 86 |
+
system = (tpl.replace("{GAME_NAME}", "Doom Battle-1")
|
| 87 |
+
.replace("{GAME_RULES}", "Kill as many monsters as possible; collect health and ammo.")
|
| 88 |
+
.replace("{KEY_BINDINGS}", "- W -> Move forward\n- LB -> Fire\n"
|
| 89 |
+
"- Mouse X Y -> aim / rotate the camera (X>0 right, Y>0 down)"))
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
和下面 `build_system_prompt(...)` 生成的结果逐字节相同(`tests/test_core.py` 会检查)。
|
| 93 |
+
|
| 94 |
+
## 3. 最小用法
|
| 95 |
|
| 96 |
```python
|
| 97 |
from PIL import Image
|
|
|
|
| 124 |
`PolicyConfig.preset("omnigamearena" | "vizdoom" | "gameworld")`:前两档把画面缩到 854×480;
|
| 125 |
`gameworld` 不预填 `<think>`,提示词要用 `build_gameworld_system_prompt(..., reasoning=False)`。
|
| 126 |
|
| 127 |
+
## 4. 系统提示词规范
|
| 128 |
|
| 129 |
所有 benchmark 用同一骨架,顺序固定(`gamescaling/prompt.py`):
|
| 130 |
|
| 131 |
1. **开场白**:游戏专家 + 游戏名 + "规划接下来 200ms、6 步、每步 33ms" 的契约;
|
| 132 |
2. `**Game Rules**`:游戏是什么、怎么计分;
|
| 133 |
+
3. **操作说明**:本游戏用到的键,**必须写成训练词表**(见 §5);
|
| 134 |
4. `**Task Instruction**`:仅 GameWorld(一个游戏有多个任务);
|
| 135 |
5. `**Output Format**`:模型据此决定输出格式;
|
| 136 |
6. `**Explanation**` + `**Key Naming Rules**`。
|
|
|
|
| 168 |
历史轮只放动作(`history_think=0`,论文口径)。解析失败的轮在历史里存成显式 no-op
|
| 169 |
`<|action_start|>0 0 0 ; ; ; ; ; ; <|action_end|>`,而不是模型的原始坏输出。
|
| 170 |
|
| 171 |
+
## 5. 动作格式与反解
|
| 172 |
|
| 173 |
```
|
| 174 |
<|action_start|>X Y Z ; g1 ; g2 ; g3 ; g4 ; g5 ; g6<|action_end|>
|
|
|
|
| 199 |
不在词表里的 token 被丢弃(记在 `Action.dropped`)。`keymaps.TO_PLAYWRIGHT` 给出到浏览器
|
| 200 |
键名的映射。
|
| 201 |
|
| 202 |
+
## 6. 三个 benchmark
|
| 203 |
|
| 204 |
三者都是**暂停时钟(pdq)**:模型思考时游戏冻结,只在执行 chunk 时前进。论文所有主表都是这个
|
| 205 |
口径;不同时钟之间的分数不可比。
|
| 206 |
|
| 207 |
+
### 6.1 ViZDoom(自包含)
|
| 208 |
|
| 209 |
```bash
|
| 210 |
pip install -r requirements.txt vizdoom==1.2.4
|
|
|
|
| 218 |
6 个 tic 上均分;HUD 开。计分:battle 图数击杀,defend 图击杀减死亡;`overall` 是四图均值的均值。
|
| 219 |
场景文件来源见 `integrations/vizdoom/scenarios/PROVENANCE.md`。
|
| 220 |
|
| 221 |
+
### 6.2 OmniGameArena
|
| 222 |
|
| 223 |
在 [OmniGameArena](https://github.com/mxlin043/OmniGameArena)(测于 `f3a4057`)里注册
|
| 224 |
agent kind `gamescaling`:
|
|
|
|
| 246 |
- `solo_craft` 的后续 episode 请换一个新的 UE5 进程;复用实例时第 2、3 局会立即结束并复报
|
| 247 |
第 1 局分数。
|
| 248 |
|
| 249 |
+
### 6.3 GameWorld
|
| 250 |
|
| 251 |
在 [GameWorld](https://github.com/gameworld-project/gameworld)(测于 `e236a39`)里注册模型
|
| 252 |
id `gamescaling`:
|
|
|
|
| 274 |
的 WASD 映射成方向键(模型主要在 PC 游戏上训练,习惯用 WASD 移动)。环境变量
|
| 275 |
`GAMESCALING_ENDPOINT` 可覆盖服务地址,`GAMESCALING_THINK=1` 可打开 think prefill(非论文口径)。
|
| 276 |
|
| 277 |
+
## 7. 接入新游戏
|
| 278 |
|
| 279 |
+
1. 填 `prompts/system_prompt_template.txt`(§2),或用 `build_system_prompt` 写提示词:游戏名、规则、`key_bindings` 用训练词表;鼠标控视角
|
| 280 |
时加 `mouse_aim=True`;`reasoning` 与 `think_prefill` 一致。
|
| 281 |
2. 每 200 ms(或暂停时钟下每次决策)截一帧,调用 `policy.act(frame)`。
|
| 282 |
+
3. 按 §5 执行 `Action`:6 个 33 ms 子步的按住键 + 鼠标位移 + 滚轮。
|
| 283 |
4. 新游戏沿用默认客户端(原尺寸画面、预填 `<think>`、`build_system_prompt` 标准格式)。
|
| 284 |
要对齐论文某一张表时,再改用
|
| 285 |
`PolicyConfig.preset("omnigamearena" | "vizdoom" | "gameworld")`。
|
| 286 |
|
| 287 |
+
## 8. 与论文评测代码的差异
|
| 288 |
|
| 289 |
发布代码与论文内部评测代码逐项对拍过:三个 benchmark 的全部系统提示词逐字节相同
|
| 290 |
(ViZDoom 4 图、OmniGameArena 12 游戏 44 个 prompt、GameWorld 170 个任务),历史 trace
|
|
|
|
| 299 |
- OmniGameArena 的 `map_wait` 用上游默认 3 s。内部评测等 60 s,但前 3 s 之后世界是冻结的,
|
| 300 |
所以两者进入第一步时的游戏时间一致。
|
| 301 |
|
| 302 |
+
## 9. 测试
|
| 303 |
|
| 304 |
```bash
|
| 305 |
python tests/test_core.py # 或 python -m pytest tests/;离线:提示词、请求体、动作反解,不需要 GPU / 服务
|
models/0p8b_s1_1600h_gs6736/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b2986b2a0deec5dd76c8c72946e7f65daf4b695c76c9b01c4f5fff9433dbeb67
|
| 3 |
+
size 2214590296
|
models/0p8b_s3_1600h_gs6760/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d553c0796833691e32277a937db649eaac39bae9a0028a63c964c12a261c2dfa
|
| 3 |
+
size 2214590296
|
models/2b_s1_1600h_gs6736/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:320dd2f7e1804faceae76fbfd6bfb83f17c9294a369bebf07cf1f3278dec3351
|
| 3 |
+
size 5443677680
|
models/2b_s3_1600h_gs6760/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:97018239265aed03c16afa0f2acb035a428a3e66195a20518cf3c14dcfe289e8
|
| 3 |
+
size 5443677680
|
prompts/example_doom_battle1.txt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a gaming expert, and you are currently playing Doom Battle-1. You are proficient in keyboard and mouse operations. You understand game mechanics and combat pacing, can quickly extract key information from the current screen, and can think and make precise decisions at critical moments. Based on the current screen, plan the next 200ms of actions, consisting of 6 steps spaced 33ms apart. Each step lasts 33ms, until the next step begins. If the current situation continues the previous strategy, output the action directly. Think only when the situation changes significantly, the previous analysis is no longer valid, or a new objective appears.
|
| 2 |
+
**Game Rules**
|
| 3 |
+
Kill as many monsters as possible; collect health and ammo.
|
| 4 |
+
**Common Keys in Doom Battle-1**
|
| 5 |
+
- W -> Move forward
|
| 6 |
+
- S -> Move backward
|
| 7 |
+
- A -> Strafe left
|
| 8 |
+
- D -> Strafe right
|
| 9 |
+
- LB -> Fire
|
| 10 |
+
- Mouse X Y -> aim / rotate the camera (X>0 right, Y>0 down)
|
| 11 |
+
**Output Format**
|
| 12 |
+
**Action only (usual)**
|
| 13 |
+
<think></think><|action_start|>X Y Z ; k1 k2 k3 ; k4 k5 ; k6 ; k7 ; k8 ; k9 k10<|action_end|>
|
| 14 |
+
**Thinking + action (when necessary)**
|
| 15 |
+
<think>reasoning</think><|action_start|>X Y Z ; k1 k2 k3 ; k4 k5 ; k6 ; k7 ; k8 ; k9 k10<|action_end|>
|
| 16 |
+
**Explanation**
|
| 17 |
+
1. **Mouse Movement**: First, specify the relative displacement X, Y (X>0 means move right, Y>0 means move down) and scroll amount Z (Z>0 means scroll up).
|
| 18 |
+
2. **Key Sequence**: Then list 6 groups of keys; within each group, keys are separated by spaces, and groups are separated by semicolons.
|
| 19 |
+
- Each group can contain up to 4 keys.
|
| 20 |
+
- If a group has no keys, leave it empty but keep the `;`.
|
| 21 |
+
3. Only output a plain string that conforms to the above format — no line breaks and no quotation marks.
|
| 22 |
+
**Key Naming Rules**
|
| 23 |
+
- Number keys `0-9`: use lowercase English words, e.g., `zero` for `0`, `one` for `1`, ... `nine` for `9`.
|
| 24 |
+
- Function keys `F1-F12`: use capitalized English words, e.g., `One` represents `F1`, `Two` represents `F2`, and so on.
|
| 25 |
+
- Mouse buttons: use `LB`, `RB`, `MB` for the left, right, and middle mouse button.
|
| 26 |
+
- Letters: use the uppercase letter, e.g., `A`, `D`, `W`, `S`.
|
| 27 |
+
- Arrow keys: use `Up`, `Down`, `Left`, `Right`.
|
| 28 |
+
- Modifier/special keys: `Shift`, `Ctrl`, `Alt`, `Tab`, `Caps`, `Esc`, `Space`, `Enter`, `Back` (backspace), `Delete`, `Insert`, `Home`, `End`, `Pause`.
|
prompts/system_prompt_template.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a gaming expert, and you are currently playing {GAME_NAME}. You are proficient in keyboard and mouse operations. You understand game mechanics and combat pacing, can quickly extract key information from the current screen, and can think and make precise decisions at critical moments. Based on the current screen, plan the next 200ms of actions, consisting of 6 steps spaced 33ms apart. Each step lasts 33ms, until the next step begins. If the current situation continues the previous strategy, output the action directly. Think only when the situation changes significantly, the previous analysis is no longer valid, or a new objective appears.
|
| 2 |
+
**Game Rules**
|
| 3 |
+
{GAME_RULES}
|
| 4 |
+
**Common Keys in {GAME_NAME}**
|
| 5 |
+
{KEY_BINDINGS}
|
| 6 |
+
**Output Format**
|
| 7 |
+
**Action only (usual)**
|
| 8 |
+
<think></think><|action_start|>X Y Z ; k1 k2 k3 ; k4 k5 ; k6 ; k7 ; k8 ; k9 k10<|action_end|>
|
| 9 |
+
**Thinking + action (when necessary)**
|
| 10 |
+
<think>reasoning</think><|action_start|>X Y Z ; k1 k2 k3 ; k4 k5 ; k6 ; k7 ; k8 ; k9 k10<|action_end|>
|
| 11 |
+
**Explanation**
|
| 12 |
+
1. **Mouse Movement**: First, specify the relative displacement X, Y (X>0 means move right, Y>0 means move down) and scroll amount Z (Z>0 means scroll up).
|
| 13 |
+
2. **Key Sequence**: Then list 6 groups of keys; within each group, keys are separated by spaces, and groups are separated by semicolons.
|
| 14 |
+
- Each group can contain up to 4 keys.
|
| 15 |
+
- If a group has no keys, leave it empty but keep the `;`.
|
| 16 |
+
3. Only output a plain string that conforms to the above format — no line breaks and no quotation marks.
|
| 17 |
+
**Key Naming Rules**
|
| 18 |
+
- Number keys `0-9`: use lowercase English words, e.g., `zero` for `0`, `one` for `1`, ... `nine` for `9`.
|
| 19 |
+
- Function keys `F1-F12`: use capitalized English words, e.g., `One` represents `F1`, `Two` represents `F2`, and so on.
|
| 20 |
+
- Mouse buttons: use `LB`, `RB`, `MB` for the left, right, and middle mouse button.
|
| 21 |
+
- Letters: use the uppercase letter, e.g., `A`, `D`, `W`, `S`.
|
| 22 |
+
- Arrow keys: use `Up`, `Down`, `Left`, `Right`.
|
| 23 |
+
- Modifier/special keys: `Shift`, `Ctrl`, `Alt`, `Tab`, `Caps`, `Esc`, `Space`, `Enter`, `Back` (backspace), `Delete`, `Insert`, `Home`, `End`, `Pause`.
|
tests/test_core.py
CHANGED
|
@@ -98,6 +98,17 @@ def test_prompt_sections_in_order():
|
|
| 98 |
assert "**Action only" not in gw
|
| 99 |
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def test_translate_controls():
|
| 102 |
text = "- ArrowLeft: move left\n- a/d: strafe\n- 1-9: pick item\nPress Escape to pause."
|
| 103 |
out = translate_controls(text)
|
|
|
|
| 98 |
assert "**Action only" not in gw
|
| 99 |
|
| 100 |
|
| 101 |
+
def test_prompt_template_file_matches_builder():
|
| 102 |
+
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 103 |
+
with open(os.path.join(root, "prompts", "system_prompt_template.txt")) as f:
|
| 104 |
+
tpl = f.read().rstrip("\n")
|
| 105 |
+
keys = {"W": "Move forward", "LB": "Fire"}
|
| 106 |
+
bindings = "- W -> Move forward\n- LB -> Fire\n- Mouse X Y -> aim / rotate the camera (X>0 right, Y>0 down)"
|
| 107 |
+
filled = (tpl.replace("{GAME_NAME}", "Doom").replace("{GAME_RULES}", "Kill monsters.")
|
| 108 |
+
.replace("{KEY_BINDINGS}", bindings))
|
| 109 |
+
assert filled == build_system_prompt("Doom", rules="Kill monsters.", key_bindings=keys)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
def test_translate_controls():
|
| 113 |
text = "- ArrowLeft: move left\n- a/d: strafe\n- 1-9: pick item\nPress Escape to pause."
|
| 114 |
out = translate_controls(text)
|