oybek
commited on
Commit
·
051f054
1
Parent(s):
61ff237
initial-commit
Browse files- .gitattributes +21 -0
- README.md +206 -0
- config.json +69 -0
- params +10 -0
- template +173 -0
.gitattributes
CHANGED
@@ -33,3 +33,24 @@ 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 |
+
gpt-oss-20b-Q2_only.gguf filter=lfs diff=lfs merge=lfs -text
|
37 |
+
gpt-oss-20b-MXFP4.gguf filter=lfs diff=lfs merge=lfs -text
|
38 |
+
gpt-oss-20b-BF16.gguf filter=lfs diff=lfs merge=lfs -text
|
39 |
+
MXFP4.gguf filter=lfs diff=lfs merge=lfs -text
|
40 |
+
gpt-oss-20b-F16.gguf filter=lfs diff=lfs merge=lfs -text
|
41 |
+
gpt-oss-20b-Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
|
42 |
+
gpt-oss-20b-Q3_K_M.gguf filter=lfs diff=lfs merge=lfs -text
|
43 |
+
gpt-oss-20b-UD-Q6_K_XL.gguf filter=lfs diff=lfs merge=lfs -text
|
44 |
+
gpt-oss-20b-Q4_0.gguf filter=lfs diff=lfs merge=lfs -text
|
45 |
+
gpt-oss-20b-Q4_1.gguf filter=lfs diff=lfs merge=lfs -text
|
46 |
+
gpt-oss-20b-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
|
47 |
+
gpt-oss-20b-UD-Q8_K_XL.gguf filter=lfs diff=lfs merge=lfs -text
|
48 |
+
gpt-oss-20b-F32.gguf filter=lfs diff=lfs merge=lfs -text
|
49 |
+
gpt-oss-20b-Q2_K.gguf filter=lfs diff=lfs merge=lfs -text
|
50 |
+
gpt-oss-20b-Q6_K.gguf filter=lfs diff=lfs merge=lfs -text
|
51 |
+
gpt-oss-20b-UD-Q4_K_XL.gguf filter=lfs diff=lfs merge=lfs -text
|
52 |
+
gpt-oss-20b-Q3_K_S.gguf filter=lfs diff=lfs merge=lfs -text
|
53 |
+
gpt-oss-20b-Q4_K_S.gguf filter=lfs diff=lfs merge=lfs -text
|
54 |
+
gpt-oss-20b-Q5_K_S.gguf filter=lfs diff=lfs merge=lfs -text
|
55 |
+
gpt-oss-20b-Q2_K_L.gguf filter=lfs diff=lfs merge=lfs -text
|
56 |
+
gpt-oss-20b-Q5_K_M.gguf filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model:
|
3 |
+
- openai/gpt-oss-20b
|
4 |
+
license: apache-2.0
|
5 |
+
pipeline_tag: text-generation
|
6 |
+
library_name: transformers
|
7 |
+
tags:
|
8 |
+
- openai
|
9 |
+
- unsloth
|
10 |
+
---
|
11 |
+
> [!NOTE]
|
12 |
+
> GGUF uploads with our fixes. More details and [Read our guide here.](https://docs.unsloth.ai/basics/gpt-oss)
|
13 |
+
>
|
14 |
+
<div>
|
15 |
+
<p style="margin-bottom: 0; margin-top: 0;">
|
16 |
+
<strong>See <a href="https://huggingface.co/collections/unsloth/gpt-oss-6892433695ce0dee42f31681">our collection</a> for all versions of gpt-oss including GGUF, 4-bit & 16-bit formats.</strong>
|
17 |
+
</p>
|
18 |
+
<p style="margin-bottom: 0;">
|
19 |
+
<em>Learn to run gpt-oss correctly - <a href="https://docs.unsloth.ai/basics/gpt-oss">Read our Guide</a>.</em>
|
20 |
+
</p>
|
21 |
+
<p style="margin-top: 0;margin-bottom: 0;">
|
22 |
+
<em>See <a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0 GGUFs</a> for our quantization benchmarks.</em>
|
23 |
+
</p>
|
24 |
+
<div style="display: flex; gap: 5px; align-items: center; ">
|
25 |
+
<a href="https://github.com/unslothai/unsloth/">
|
26 |
+
<img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
|
27 |
+
</a>
|
28 |
+
<a href="https://discord.gg/unsloth">
|
29 |
+
<img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
|
30 |
+
</a>
|
31 |
+
<a href="https://docs.unsloth.ai/basics/gpt-oss">
|
32 |
+
<img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
|
33 |
+
</a>
|
34 |
+
</div>
|
35 |
+
<h1 style="margin-top: 0rem;">✨ Read our gpt-oss Guide <a href="https://docs.unsloth.ai/basics/gpt-oss">here</a>!</h1>
|
36 |
+
</div>
|
37 |
+
|
38 |
+
- Fine-tune gpt-oss-20b for free using our [Google Colab notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/gpt-oss-(20B)-Fine-tuning.ipynb)
|
39 |
+
- Read our Blog about gpt-oss support: [unsloth.ai/blog/gpt-oss](https://unsloth.ai/blog/gpt-oss)
|
40 |
+
- View the rest of our notebooks in our [docs here](https://docs.unsloth.ai/get-started/unsloth-notebooks).
|
41 |
+
- Thank you to the [llama.cpp](https://github.com/ggml-org/llama.cpp) team for their work on supporting this model. We wouldn't be able to release quants without them!
|
42 |
+
|
43 |
+
The F32 quant is MXFP4 upcasted to BF16 for every single layer and is unquantized.
|
44 |
+
|
45 |
+
# gpt-oss-20b Details
|
46 |
+
|
47 |
+
<p align="center">
|
48 |
+
<img alt="gpt-oss-20b" src="https://raw.githubusercontent.com/openai/gpt-oss/main/docs/gpt-oss-20b.svg">
|
49 |
+
</p>
|
50 |
+
|
51 |
+
<p align="center">
|
52 |
+
<a href="https://gpt-oss.com"><strong>Try gpt-oss</strong></a> ·
|
53 |
+
<a href="https://cookbook.openai.com/topic/gpt-oss"><strong>Guides</strong></a> ·
|
54 |
+
<a href="https://openai.com/index/gpt-oss-model-card"><strong>System card</strong></a> ·
|
55 |
+
<a href="https://openai.com/index/introducing-gpt-oss/"><strong>OpenAI blog</strong></a>
|
56 |
+
</p>
|
57 |
+
|
58 |
+
<br>
|
59 |
+
|
60 |
+
Welcome to the gpt-oss series, [OpenAI’s open-weight models](https://openai.com/open-models) designed for powerful reasoning, agentic tasks, and versatile developer use cases.
|
61 |
+
|
62 |
+
We’re releasing two flavors of the open models:
|
63 |
+
- `gpt-oss-120b` — for production, general purpose, high reasoning use cases that fits into a single H100 GPU (117B parameters with 5.1B active parameters)
|
64 |
+
- `gpt-oss-20b` — for lower latency, and local or specialized use cases (21B parameters with 3.6B active parameters)
|
65 |
+
|
66 |
+
Both models were trained on our [harmony response format](https://github.com/openai/harmony) and should only be used with the harmony format as it will not work correctly otherwise.
|
67 |
+
|
68 |
+
|
69 |
+
> [!NOTE]
|
70 |
+
> This model card is dedicated to the smaller `gpt-oss-20b` model. Check out [`gpt-oss-120b`](https://huggingface.co/openai/gpt-oss-120b) for the larger model.
|
71 |
+
|
72 |
+
# Highlights
|
73 |
+
|
74 |
+
* **Permissive Apache 2.0 license:** Build freely without copyleft restrictions or patent risk—ideal for experimentation, customization, and commercial deployment.
|
75 |
+
* **Configurable reasoning effort:** Easily adjust the reasoning effort (low, medium, high) based on your specific use case and latency needs.
|
76 |
+
* **Full chain-of-thought:** Gain complete access to the model’s reasoning process, facilitating easier debugging and increased trust in outputs. It’s not intended to be shown to end users.
|
77 |
+
* **Fine-tunable:** Fully customize models to your specific use case through parameter fine-tuning.
|
78 |
+
* **Agentic capabilities:** Use the models’ native capabilities for function calling, [web browsing](https://github.com/openai/gpt-oss/tree/main?tab=readme-ov-file#browser), [Python code execution](https://github.com/openai/gpt-oss/tree/main?tab=readme-ov-file#python), and Structured Outputs.
|
79 |
+
* **Native MXFP4 quantization:** The models are trained with native MXFP4 precision for the MoE layer, making `gpt-oss-120b` run on a single H100 GPU and the `gpt-oss-20b` model run within 16GB of memory.
|
80 |
+
|
81 |
+
---
|
82 |
+
|
83 |
+
# Inference examples
|
84 |
+
|
85 |
+
## Transformers
|
86 |
+
|
87 |
+
You can use `gpt-oss-120b` and `gpt-oss-20b` with Transformers. If you use the Transformers chat template, it will automatically apply the [harmony response format](https://github.com/openai/harmony). If you use `model.generate` directly, you need to apply the harmony format manually using the chat template or use our [openai-harmony](https://github.com/openai/harmony) package.
|
88 |
+
|
89 |
+
To get started, install the necessary dependencies to setup your environment:
|
90 |
+
|
91 |
+
```
|
92 |
+
pip install -U transformers kernels torch
|
93 |
+
```
|
94 |
+
|
95 |
+
Once, setup you can proceed to run the model by running the snippet below:
|
96 |
+
|
97 |
+
```py
|
98 |
+
from transformers import pipeline
|
99 |
+
import torch
|
100 |
+
|
101 |
+
model_id = "openai/gpt-oss-20b"
|
102 |
+
|
103 |
+
pipe = pipeline(
|
104 |
+
"text-generation",
|
105 |
+
model=model_id,
|
106 |
+
torch_dtype="auto",
|
107 |
+
device_map="auto",
|
108 |
+
)
|
109 |
+
|
110 |
+
messages = [
|
111 |
+
{"role": "user", "content": "Explain quantum mechanics clearly and concisely."},
|
112 |
+
]
|
113 |
+
|
114 |
+
outputs = pipe(
|
115 |
+
messages,
|
116 |
+
max_new_tokens=256,
|
117 |
+
)
|
118 |
+
print(outputs[0]["generated_text"][-1])
|
119 |
+
```
|
120 |
+
|
121 |
+
Alternatively, you can run the model via [`Transformers Serve`](https://huggingface.co/docs/transformers/main/serving) to spin up a OpenAI-compatible webserver:
|
122 |
+
|
123 |
+
```
|
124 |
+
transformers serve
|
125 |
+
transformers chat localhost:8000 --model-name-or-path openai/gpt-oss-20b
|
126 |
+
```
|
127 |
+
|
128 |
+
[Learn more about how to use gpt-oss with Transformers.](https://cookbook.openai.com/articles/gpt-oss/run-transformers)
|
129 |
+
|
130 |
+
## vLLM
|
131 |
+
|
132 |
+
vLLM recommends using [uv](https://docs.astral.sh/uv/) for Python dependency management. You can use vLLM to spin up an OpenAI-compatible webserver. The following command will automatically download the model and start the server.
|
133 |
+
|
134 |
+
```bash
|
135 |
+
uv pip install --pre vllm==0.10.1+gptoss \
|
136 |
+
--extra-index-url https://wheels.vllm.ai/gpt-oss/ \
|
137 |
+
--extra-index-url https://download.pytorch.org/whl/nightly/cu128 \
|
138 |
+
--index-strategy unsafe-best-match
|
139 |
+
|
140 |
+
vllm serve openai/gpt-oss-20b
|
141 |
+
```
|
142 |
+
|
143 |
+
[Learn more about how to use gpt-oss with vLLM.](https://cookbook.openai.com/articles/gpt-oss/run-vllm)
|
144 |
+
|
145 |
+
## PyTorch / Triton
|
146 |
+
|
147 |
+
To learn about how to use this model with PyTorch and Triton, check out our [reference implementations in the gpt-oss repository](https://github.com/openai/gpt-oss?tab=readme-ov-file#reference-pytorch-implementation).
|
148 |
+
|
149 |
+
## Ollama
|
150 |
+
|
151 |
+
If you are trying to run gpt-oss on consumer hardware, you can use Ollama by running the following commands after [installing Ollama](https://ollama.com/download).
|
152 |
+
|
153 |
+
```bash
|
154 |
+
# gpt-oss-20b
|
155 |
+
ollama pull gpt-oss:20b
|
156 |
+
ollama run gpt-oss:20b
|
157 |
+
```
|
158 |
+
|
159 |
+
[Learn more about how to use gpt-oss with Ollama.](https://cookbook.openai.com/articles/gpt-oss/run-locally-ollama)
|
160 |
+
|
161 |
+
#### LM Studio
|
162 |
+
|
163 |
+
If you are using [LM Studio](https://lmstudio.ai/) you can use the following commands to download.
|
164 |
+
|
165 |
+
```bash
|
166 |
+
# gpt-oss-20b
|
167 |
+
lms get openai/gpt-oss-20b
|
168 |
+
```
|
169 |
+
|
170 |
+
Check out our [awesome list](https://github.com/openai/gpt-oss/blob/main/awesome-gpt-oss.md) for a broader collection of gpt-oss resources and inference partners.
|
171 |
+
|
172 |
+
---
|
173 |
+
|
174 |
+
# Download the model
|
175 |
+
|
176 |
+
You can download the model weights from the [Hugging Face Hub](https://huggingface.co/collections/openai/gpt-oss-68911959590a1634ba11c7a4) directly from Hugging Face CLI:
|
177 |
+
|
178 |
+
```shell
|
179 |
+
# gpt-oss-20b
|
180 |
+
huggingface-cli download openai/gpt-oss-20b --include "original/*" --local-dir gpt-oss-20b/
|
181 |
+
pip install gpt-oss
|
182 |
+
python -m gpt_oss.chat model/
|
183 |
+
```
|
184 |
+
|
185 |
+
# Reasoning levels
|
186 |
+
|
187 |
+
You can adjust the reasoning level that suits your task across three levels:
|
188 |
+
|
189 |
+
* **Low:** Fast responses for general dialogue.
|
190 |
+
* **Medium:** Balanced speed and detail.
|
191 |
+
* **High:** Deep and detailed analysis.
|
192 |
+
|
193 |
+
The reasoning level can be set in the system prompts, e.g., "Reasoning: high".
|
194 |
+
|
195 |
+
# Tool use
|
196 |
+
|
197 |
+
The gpt-oss models are excellent for:
|
198 |
+
* Web browsing (using built-in browsing tools)
|
199 |
+
* Function calling with defined schemas
|
200 |
+
* Agentic operations like browser tasks
|
201 |
+
|
202 |
+
# Fine-tuning
|
203 |
+
|
204 |
+
Both gpt-oss models can be fine-tuned for a variety of specialized use cases.
|
205 |
+
|
206 |
+
This smaller model `gpt-oss-20b` can be fine-tuned on consumer hardware, whereas the larger [`gpt-oss-120b`](https://huggingface.co/openai/gpt-oss-120b) can be fine-tuned on a single H100 node.
|
config.json
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"GptOssForCausalLM"
|
4 |
+
],
|
5 |
+
"attention_bias": true,
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"eos_token_id": 200002,
|
8 |
+
"experts_per_token": 4,
|
9 |
+
"head_dim": 64,
|
10 |
+
"hidden_act": "silu",
|
11 |
+
"hidden_size": 2880,
|
12 |
+
"initial_context_length": 4096,
|
13 |
+
"initializer_range": 0.02,
|
14 |
+
"intermediate_size": 2880,
|
15 |
+
"layer_types": [
|
16 |
+
"sliding_attention",
|
17 |
+
"full_attention",
|
18 |
+
"sliding_attention",
|
19 |
+
"full_attention",
|
20 |
+
"sliding_attention",
|
21 |
+
"full_attention",
|
22 |
+
"sliding_attention",
|
23 |
+
"full_attention",
|
24 |
+
"sliding_attention",
|
25 |
+
"full_attention",
|
26 |
+
"sliding_attention",
|
27 |
+
"full_attention",
|
28 |
+
"sliding_attention",
|
29 |
+
"full_attention",
|
30 |
+
"sliding_attention",
|
31 |
+
"full_attention",
|
32 |
+
"sliding_attention",
|
33 |
+
"full_attention",
|
34 |
+
"sliding_attention",
|
35 |
+
"full_attention",
|
36 |
+
"sliding_attention",
|
37 |
+
"full_attention",
|
38 |
+
"sliding_attention",
|
39 |
+
"full_attention"
|
40 |
+
],
|
41 |
+
"max_position_embeddings": 131072,
|
42 |
+
"model_type": "gpt_oss",
|
43 |
+
"num_attention_heads": 64,
|
44 |
+
"num_experts_per_tok": 4,
|
45 |
+
"num_hidden_layers": 24,
|
46 |
+
"num_key_value_heads": 8,
|
47 |
+
"num_local_experts": 32,
|
48 |
+
"output_router_logits": false,
|
49 |
+
"pad_token_id": 200017,
|
50 |
+
"rms_norm_eps": 1e-05,
|
51 |
+
"rope_scaling": {
|
52 |
+
"beta_fast": 32.0,
|
53 |
+
"beta_slow": 1.0,
|
54 |
+
"factor": 32.0,
|
55 |
+
"original_max_position_embeddings": 4096,
|
56 |
+
"rope_type": "yarn",
|
57 |
+
"truncate": false
|
58 |
+
},
|
59 |
+
"rope_theta": 150000,
|
60 |
+
"router_aux_loss_coef": 0.9,
|
61 |
+
"sliding_window": 128,
|
62 |
+
"swiglu_limit": 7.0,
|
63 |
+
"tie_word_embeddings": false,
|
64 |
+
"torch_dtype": "bfloat16",
|
65 |
+
"transformers_version": "4.55.0",
|
66 |
+
"unsloth_fixed": true,
|
67 |
+
"use_cache": true,
|
68 |
+
"vocab_size": 201088
|
69 |
+
}
|
params
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"stop": [
|
3 |
+
"<|endoftext|>",
|
4 |
+
"<|return|>"
|
5 |
+
],
|
6 |
+
"temperature": 1.0,
|
7 |
+
"min_p" : 0.00,
|
8 |
+
"top_k" : 0,
|
9 |
+
"top_p" : 1.0
|
10 |
+
}
|
template
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
|
2 |
+
Knowledge cutoff: 2024-06
|
3 |
+
Current date: {{ currentDate }}
|
4 |
+
{{- if and .IsThinkSet .Think (ne .ThinkLevel "") }}
|
5 |
+
|
6 |
+
Reasoning: {{ .ThinkLevel }}
|
7 |
+
{{- else if or (not .IsThinkSet) (and .IsThinkSet .Think) }}
|
8 |
+
|
9 |
+
Reasoning: medium
|
10 |
+
{{- end }}
|
11 |
+
|
12 |
+
{{- $hasNonBuiltinTools := false }}
|
13 |
+
{{- if .Tools -}}
|
14 |
+
{{- $hasBrowserSearch := false }}
|
15 |
+
{{- $hasBrowserOpen := false }}
|
16 |
+
{{- $hasBrowserFind := false }}
|
17 |
+
{{- $hasPython := false }}
|
18 |
+
{{- range .Tools }}
|
19 |
+
{{- if eq .Function.Name "browser.search" -}}{{- $hasBrowserSearch = true -}}
|
20 |
+
{{- else if eq .Function.Name "browser.open" -}}{{- $hasBrowserOpen = true -}}
|
21 |
+
{{- else if eq .Function.Name "browser.find" -}}{{- $hasBrowserFind = true -}}
|
22 |
+
{{- else if eq .Function.Name "python" -}}{{- $hasPython = true -}}
|
23 |
+
{{- else }}{{ $hasNonBuiltinTools = true -}}
|
24 |
+
{{- end }}
|
25 |
+
{{- end }}
|
26 |
+
{{- if or $hasBrowserSearch $hasBrowserOpen $hasBrowserFind $hasPython }}
|
27 |
+
|
28 |
+
# Tools
|
29 |
+
{{- if or $hasBrowserSearch $hasBrowserOpen $hasBrowserFind }}
|
30 |
+
|
31 |
+
## browser
|
32 |
+
|
33 |
+
// Tool for browsing.
|
34 |
+
// The `cursor` appears in brackets before each browsing display: `[{cursor}]`.
|
35 |
+
// Cite information from the tool using the following format:
|
36 |
+
// `【{cursor}†L{line_start}(-L{line_end})?】`, for example: `【6†L9-L11】` or `【8†L3】`.
|
37 |
+
// Do not quote more than 10 words directly from the tool output.
|
38 |
+
// sources=web (default: web)
|
39 |
+
namespace browser {
|
40 |
+
{{- if $hasBrowserSearch }}
|
41 |
+
|
42 |
+
// Searches for information related to `query` and displays `topn` results.
|
43 |
+
type search = (_: {
|
44 |
+
query: string,
|
45 |
+
topn?: number, // default: 10
|
46 |
+
source?: string,
|
47 |
+
}) => any;
|
48 |
+
{{- end }}
|
49 |
+
{{- if $hasBrowserOpen }}
|
50 |
+
|
51 |
+
// Opens the link `id` from the page indicated by `cursor` starting at line number `loc`, showing `num_lines` lines.
|
52 |
+
// Valid link ids are displayed with the formatting: `【{id}†.*】`.
|
53 |
+
// If `cursor` is not provided, the most recent page is implied.
|
54 |
+
// If `id` is a string, it is treated as a fully qualified URL associated with `source`.
|
55 |
+
// If `loc` is not provided, the viewport will be positioned at the beginning of the document or centered on the most relevant passage, if available.
|
56 |
+
// Use this function without `id` to scroll to a new location of an opened page.
|
57 |
+
type open = (_: {
|
58 |
+
id?: number | string, // default: -1
|
59 |
+
cursor?: number, // default: -1
|
60 |
+
loc?: number, // default: -1
|
61 |
+
num_lines?: number, // default: -1
|
62 |
+
view_source?: boolean, // default: false
|
63 |
+
source?: string,
|
64 |
+
}) => any;
|
65 |
+
{{- end }}
|
66 |
+
{{- if $hasBrowserFind }}
|
67 |
+
|
68 |
+
// Finds exact matches of `pattern` in the current page, or the page given by `cursor`.
|
69 |
+
type find = (_: {
|
70 |
+
pattern: string,
|
71 |
+
cursor?: number, // default: -1
|
72 |
+
}) => any;
|
73 |
+
{{- end }}
|
74 |
+
|
75 |
+
} // namespace browser
|
76 |
+
{{- end }}{{/* end if has browser tools */}}
|
77 |
+
{{- if $hasPython }}
|
78 |
+
|
79 |
+
## python
|
80 |
+
|
81 |
+
Use this tool to execute Python code in your chain of thought. The code will not be shown to the user. This tool should be used for internal reasoning, but not for code that is intended to be visible to the user (e.g. when creating plots, tables, or files).
|
82 |
+
|
83 |
+
When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 120.0 seconds. The drive at '/mnt/data' can be used to save and persist user files. Internet access for this session is UNKNOWN. Depends on the cluster.
|
84 |
+
{{- end }}{{/* end if hasPython */}}
|
85 |
+
{{- end }}{{/* end if has any built-in tools */}}
|
86 |
+
{{- end }}{{/* end if .Tools */}}
|
87 |
+
|
88 |
+
# Valid channels: analysis, commentary, final. Channel must be included for every message.{{ if $hasNonBuiltinTools }}
|
89 |
+
Calls to these tools must go to the commentary channel: 'functions'.
|
90 |
+
{{- end -}}<|end|>{{/* end of system */ -}}
|
91 |
+
{{- if or $hasNonBuiltinTools .System -}}
|
92 |
+
<|start|>developer<|message|>{{- if $hasNonBuiltinTools }}# Tools
|
93 |
+
|
94 |
+
## functions
|
95 |
+
|
96 |
+
namespace functions {
|
97 |
+
{{- range .Tools }}
|
98 |
+
{{- if not (or (eq .Function.Name "browser.search") (eq .Function.Name "browser.open") (eq .Function.Name "browser.find") (eq .Function.Name "python")) }}
|
99 |
+
{{if .Function.Description }}
|
100 |
+
// {{ .Function.Description }}
|
101 |
+
{{- end }}
|
102 |
+
{{- if and .Function.Parameters.Properties (gt (len .Function.Parameters.Properties) 0) }}
|
103 |
+
type {{ .Function.Name }} = (_: {
|
104 |
+
{{- range $name, $prop := .Function.Parameters.Properties }}
|
105 |
+
{{- if $prop.Description }}
|
106 |
+
// {{ $prop.Description }}
|
107 |
+
{{- end }}
|
108 |
+
{{ $name }}: {{ if gt (len $prop.Type) 1 }}{{ range $i, $t := $prop.Type }}{{ if $i }} | {{ end }}{{ $t }}{{ end }}{{ else }}{{ index $prop.Type 0 }}{{ end }},
|
109 |
+
{{- end }}
|
110 |
+
}) => any;
|
111 |
+
{{- else }}
|
112 |
+
type {{ .Function.Name }} = () => any;
|
113 |
+
{{- end }}
|
114 |
+
{{- end }}{{/* end if not browser tool */}}
|
115 |
+
{{- end }}{{/* end of range .Tools */}}
|
116 |
+
|
117 |
+
} // namespace functions
|
118 |
+
{{- end }}{{/* end if hasNonBuiltinTools */}}
|
119 |
+
{{- if .System}}
|
120 |
+
|
121 |
+
# Instructions
|
122 |
+
|
123 |
+
{{ .System }}
|
124 |
+
{{- end -}}
|
125 |
+
<|end|>
|
126 |
+
{{- end -}}
|
127 |
+
{{- /* Find the index of the last user message */ -}}
|
128 |
+
{{- $lastUserIdx := -1 }}
|
129 |
+
{{- $prefillingContent := false }}
|
130 |
+
{{- $prefillingThinkingOnly := false }}
|
131 |
+
{{- range $i, $msg := .Messages }}
|
132 |
+
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
|
133 |
+
{{- if eq $msg.Role "user" }}
|
134 |
+
{{- $lastUserIdx = $i }}
|
135 |
+
{{- end -}}
|
136 |
+
{{- if and $last (eq $msg.Role "assistant") (gt (len $msg.Content) 0) }}
|
137 |
+
{{- $prefillingContent = true }}
|
138 |
+
{{- else if and $last (eq $msg.Role "assistant") (gt (len $msg.Thinking) 0) }}
|
139 |
+
{{- $prefillingThinkingOnly = true }}
|
140 |
+
{{- end }}
|
141 |
+
{{- end -}}
|
142 |
+
{{- /* Now render messages */ -}}
|
143 |
+
{{- range $i, $msg := .Messages }}
|
144 |
+
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
|
145 |
+
{{- if (ne $msg.Role "system") -}}
|
146 |
+
{{- if eq $msg.Role "tool" -}}
|
147 |
+
{{- if or (eq $msg.ToolName "python") (eq $msg.ToolName "browser.search") (eq $msg.ToolName "browser.open") (eq $msg.ToolName "browser.find") -}}
|
148 |
+
<|start|>{{ $msg.ToolName }} to=assistant<|message|>{{ $msg.Content }}<|end|>
|
149 |
+
{{- else -}}
|
150 |
+
<|start|>functions.{{ $msg.ToolName }} to=assistant<|message|>{{ $msg.Content }}<|end|>
|
151 |
+
{{- end -}}
|
152 |
+
{{- else if eq $msg.Role "assistant" -}}
|
153 |
+
{{- if and $msg.Thinking (gt $i $lastUserIdx) -}}{{- /* Show thinking only after last user message */ -}}
|
154 |
+
<|start|>assistant<|channel|>analysis<|message|>{{ $msg.Thinking }}{{- if not $prefillingThinkingOnly -}}<|end|>{{- end -}}
|
155 |
+
{{- end -}}
|
156 |
+
{{- if gt (len $msg.Content) 0 -}}
|
157 |
+
<|start|>assistant<|channel|>final<|message|>{{ $msg.Content }}{{- if not $prefillingContent -}}<|end|>{{- end -}}
|
158 |
+
{{- end -}}
|
159 |
+
{{- if gt (len $msg.ToolCalls) 0 -}}
|
160 |
+
{{- range $j, $toolCall := $msg.ToolCalls -}}
|
161 |
+
{{- $isBuiltin := or (eq $toolCall.Function.Name "python") (eq $toolCall.Function.Name "browser.search") (eq $toolCall.Function.Name "browser.open") (eq $toolCall.Function.Name "browser.find") -}}
|
162 |
+
<|start|>assistant<|channel|>{{ if $isBuiltin }}analysis{{ else }}commentary{{ end }} to={{ if not $isBuiltin}}functions.{{end}}{{ $toolCall.Function.Name }} <|constrain|>json<|message|>{{ $toolCall.Function.Arguments }}<|call|>
|
163 |
+
{{- end -}}
|
164 |
+
{{- end -}}
|
165 |
+
{{- else if eq $msg.Role "user" -}}
|
166 |
+
<|start|>{{ $msg.Role }}<|message|>{{ $msg.Content }}<|end|>
|
167 |
+
{{- end }}
|
168 |
+
{{- else }}
|
169 |
+
{{- end }}
|
170 |
+
{{- end -}}
|
171 |
+
{{- if not (or $prefillingContent $prefillingThinkingOnly) -}}
|
172 |
+
<|start|>assistant
|
173 |
+
{{- end -}}
|