commit b8ff906550fcec3824908650c1305e3ddbe397ba Author: ModelHub XC Date: Wed Jul 29 14:02:14 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4dd4054 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,37 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +*.gguf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/EXAONE-4.0-1.2B-BF16.gguf b/EXAONE-4.0-1.2B-BF16.gguf new file mode 100644 index 0000000..06314ed --- /dev/null +++ b/EXAONE-4.0-1.2B-BF16.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8fb80177b4d16ac77d3ceb8fd4831058358ad4aee6fadc800e24797eef78b88 +size 2563248416 diff --git a/EXAONE-4.0-1.2B-IQ4_XS.gguf b/EXAONE-4.0-1.2B-IQ4_XS.gguf new file mode 100644 index 0000000..66fb770 --- /dev/null +++ b/EXAONE-4.0-1.2B-IQ4_XS.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7abd23b5482b33458e9c87ee93e153e5cb1c49850c2d0599cfae7f4e80e4c189 +size 753799456 diff --git a/EXAONE-4.0-1.2B-Q4_K_M.gguf b/EXAONE-4.0-1.2B-Q4_K_M.gguf new file mode 100644 index 0000000..fdf5b89 --- /dev/null +++ b/EXAONE-4.0-1.2B-Q4_K_M.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b5e753540183ae4d56e6febd9b48cdd944de53386e6faa8f51c8f98cb2b47df +size 812437792 diff --git a/EXAONE-4.0-1.2B-Q5_K_M.gguf b/EXAONE-4.0-1.2B-Q5_K_M.gguf new file mode 100644 index 0000000..327d4c3 --- /dev/null +++ b/EXAONE-4.0-1.2B-Q5_K_M.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a7e39590e2686d990e6597f8dc95781aa084eb280c36ddd46d88dd759404972 +size 929616160 diff --git a/EXAONE-4.0-1.2B-Q6_K.gguf b/EXAONE-4.0-1.2B-Q6_K.gguf new file mode 100644 index 0000000..bb73ff8 --- /dev/null +++ b/EXAONE-4.0-1.2B-Q6_K.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:296e57a27bcb96a0aa4c7e37d9a90a59ec1c8465b6cce86533ee40a4816c405a +size 1054118176 diff --git a/EXAONE-4.0-1.2B-Q8_0.gguf b/EXAONE-4.0-1.2B-Q8_0.gguf new file mode 100644 index 0000000..0a8cd5c --- /dev/null +++ b/EXAONE-4.0-1.2B-Q8_0.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc0b2a3f447e134cafd2853104d06227122cc280f4c9fee8c90172066174ef04 +size 1363939616 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..047008b --- /dev/null +++ b/LICENSE @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c1762fb4bd94c8f17e114c5caa567e0948e1da7d02b79b55e99be9616e0f9e3 +size 13288 diff --git a/README.md b/README.md new file mode 100644 index 0000000..246cf3e --- /dev/null +++ b/README.md @@ -0,0 +1,1100 @@ +--- +base_model: LGAI-EXAONE/EXAONE-4.0-1.2B +base_model_relation: quantized +license: other +license_name: exaone +license_link: LICENSE +language: +- en +- ko +- es +tags: +- lg-ai +- exaone +- exaone-4.0 +pipeline_tag: text-generation +library_name: transformers +--- + +

+ +🎉 License Updated! We are pleased to announce our more flexible licensing terms 🤗 +
✈️ Try on FriendliAI (licensed under commercial purposes) +

📢 EXAONE 4.0 is officially supported by llama.cpp! Please check the guide below +
+ +# EXAONE-4.0-1.2B-GGUF + +## Introduction + +We introduce **EXAONE 4.0**, which integrates a **Non-reasoning mode** and **Reasoning mode** to achieve both the excellent usability of [EXAONE 3.5](https://github.com/LG-AI-EXAONE/EXAONE-3.5) and the advanced reasoning abilities of [EXAONE Deep](https://github.com/LG-AI-EXAONE/EXAONE-Deep). To pave the way for the agentic AI era, EXAONE 4.0 incorporates essential features such as agentic tool use, and its multilingual capabilities are extended +to support Spanish in addition to English and Korean. + +The EXAONE 4.0 model series consists of two sizes: a mid-size **32B** model optimized for high performance, and a small-size **1.2B** model designed for on-device applications. + +In the EXAONE 4.0 architecture, we apply new architectural changes compared to previous EXAONE models as below: + +1. **Hybrid Attention**: For the 32B model, we adopt hybrid attention scheme, which combines *Local attention (sliding window attention)* with *Global attention (full attention)* in a 3:1 ratio. We do not use RoPE (Rotary Positional Embedding) for global attention for better global context understanding. +2. **QK-Reorder-Norm**: We reorder the LayerNorm position from the traditional Pre-LN scheme by applying LayerNorm directly to the attention and MLP outputs, and we add RMS normalization right after the Q and K projection. It helps yield better performance on downstream tasks despite consuming more computation. + +For more details, please refer to our [technical report](https://arxiv.org/abs/2507.11407), [HuggingFace paper](https://huggingface.co/papers/2507.11407), [blog](https://www.lgresearch.ai/blog/view?seq=576), and [GitHub](https://github.com/LG-AI-EXAONE/EXAONE-4.0). + + +### Model Configuration + +- Number of Parameters (without embeddings): 1.07B +- Number of Layers: 30 +- Number of Attention Heads: GQA with 32-heads and 8-KV heads +- Vocab Size: 102,400 +- Context Length: 65,536 tokens +- Quantization: `Q8_0`, `Q6_K`, `Q5_K_M`, `Q4_K_M`, `IQ4_XS` in GGUF format (also includes `BF16` weights) + +## Quickstart + +### llama.cpp +You can run EXAONE models locally using llama.cpp by following these steps: + +1. Install the latest version of llama.cpp (version >= `b5932`). Please check the official [installation guide](https://github.com/ggml-org/llama.cpp?tab=readme-ov-file#quick-start) from llama.cpp. + +2. Download the EXAONE 4.0 model weights in GGUF format. + + ```bash + huggingface-cli download LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF \ + --include "EXAONE-4.0-1.2B-Q4_K_M.gguf" \ + --local-dir . + ``` + + +

+Generation with `llama-cli` + +3. Apply chat template using transformers. + + > This process is necessary to avoid issues with current EXAONE modeling code in `llama.cpp`. This is work in progress at our [PR](https://github.com/ggml-org/llama.cpp/pull/14630). We will update this once these issues are solved. + + ```python + from transformers import AutoModelForCausalLM, AutoTokenizer + + model_name = "LGAI-EXAONE/EXAONE-4.0-1.2B" + tokenizer = AutoTokenizer.from_pretrained(model_name) + + messages = [ + {"role": "user", "content": "Let's work together on local system!"} + ] + input_text = tokenizer.apply_chat_template( + messages, + tokenize=False, + add_generation_prompt=True, + ) + + print(repr(input_text)) + with open("inputs.txt", "w") as f: + f.write(input_text) + ``` + +4. Generate result with greedy decoding. + ```bash + llama-cli -m EXAONE-4.0-1.2B-Q4_K_M.gguf \ + -fa -ngl 31 \ + --temp 0.0 --top-k 1 \ + -f inputs.txt -no-cnv + ``` + +
+ +
+OpenAI compatible server with `llama-server` + +3. Run llama-server with EXAONE 4.0 Jinja template. You can find the [chat template file](https://huggingface.co/LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF/blob/main/chat_template.jinja) in this repository. + ```bash + llama-server -m EXAONE-4.0-1.2B-Q4_K_M.gguf \ + -c 131072 -fa -ngl 31 \ + --temp 0.6 --top-p 0.95 \ + --jinja --chat-template-file chat_template.jinja \ + --host 0.0.0.0 --port 8820 \ + -a EXAONE-4.0-1.2B-Q4_K_M + ``` + +4. Use OpenAI chat completion to test the GGUF model. + ```bash + curl -X POST http://localhost:8820/v1/chat/completions \ + -H "Content-Type: application/json" \ + -d '{ + "model": "EXAONE-4.0-1.2B-Q4_K_M", + "messages": [ + {"role": "user", "content": "Let'\''s work together on server!"} + ], + "max_tokens": 1024, + "temperature": 0.6, + "top_p": 0.95, + "chat_template_kwargs": {"enable_thinking": false} + }' + ``` + +
+ + +## Performance + +The following tables show the evaluation results of each model, with reasoning and non-reasoning mode. The evaluation details can be found in the [technical report](https://arxiv.org/abs/2507.11407). + +- ✅ denotes the model has a hybrid reasoning capability, evaluated by selecting reasoning / non-reasoning on the purpose. +- To assess Korean **practical** and **professional** knowledge, we adopt both the [KMMLU-Redux](https://huggingface.co/datasets/LGAI-EXAONE/KMMLU-Redux) and [KMMLU-Pro](https://huggingface.co/datasets/LGAI-EXAONE/KMMLU-Pro) benchmarks. Both datasets are publicly released! +- The evaluation results are based on the original model, not quantized model. + + +### 32B Reasoning Mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EXAONE 4.0 32B Phi 4 reasoning-plusMagistral Small-2506Qwen 3 32B Qwen 3 235B DeepSeek R1-0528
Model Size32.0B14.7B23.6B32.8B235B671B
Hybrid Reasoning
World Knowledge
MMLU-Redux92.390.886.890.992.793.4
MMLU-Pro81.876.073.480.083.085.0
GPQA-Diamond75.468.968.268.471.181.0
Math/Coding
AIME 202585.378.062.872.981.587.5
HMMT Feb 202572.953.643.550.462.579.4
LiveCodeBench v572.651.755.865.770.775.2
LiveCodeBench v666.747.147.460.158.970.3
Instruction Following
IFEval83.784.937.985.083.480.8
Multi-IF (EN)73.556.127.473.473.472.0
Agentic Tool Use
BFCL-v363.9N/A40.470.370.864.7
Tau-Bench (Airline)51.5N/A38.534.537.553.5
Tau-Bench (Retail)62.8N/A10.255.258.363.9
Multilinguality
KMMLU-Pro67.755.851.561.468.171.7
KMMLU-Redux72.762.754.667.574.577.0
KSM87.679.871.982.886.286.7
MMMLU (ES)85.684.368.982.886.788.2
MATH500 (ES)95.894.283.594.395.196.0
+ +### 32B Non-Reasoning Mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EXAONE 4.0 32B Phi 4Mistral-Small-2506Gemma3 27BQwen3 32B Qwen3 235B Llama-4-MaverickDeepSeek V3-0324
Model Size32.0B14.7B24.0B27.4B32.8B235B402B671B
Hybrid Reasoning
World Knowledge
MMLU-Redux89.888.385.985.085.789.292.392.3
MMLU-Pro77.670.469.167.574.477.480.581.2
GPQA-Diamond63.756.146.142.454.662.969.868.4
Math/Coding
AIME 202535.917.830.223.820.224.718.050.0
HMMT Feb 202521.84.016.910.39.811.97.329.2
LiveCodeBench v543.324.625.827.531.335.343.446.7
LiveCodeBench v643.127.426.929.728.031.432.744.0
Instruction Following
IFEval84.863.077.882.683.283.285.481.2
Multi-IF (EN)71.647.763.272.171.972.577.968.3
Long Context
HELMET58.3N/A61.958.354.563.313.7N/A
RULER88.2N/A71.866.085.690.62.9N/A
LongBench v148.1N/A51.551.544.245.334.7N/A
Agentic Tool Use
BFCL-v365.2N/A57.7N/A63.068.052.963.8
Tau-Bench (Airline)25.5N/A36.1N/A16.027.038.040.5
Tau-Bench (Retail)55.9N/A35.5N/A47.656.56.568.5
Multilinguality
KMMLU-Pro60.044.851.050.758.364.468.867.3
KMMLU-Redux64.850.153.653.364.471.776.972.2
KSM59.829.135.536.141.346.640.663.5
Ko-LongBench76.9N/A55.472.073.974.665.6N/A
MMMLU (ES)80.681.278.478.782.183.786.986.7
MATH500 (ES)87.378.283.486.884.787.278.789.2
WMT24++ (ES)90.789.392.293.191.492.992.794.3
+ +### 1.2B Reasoning Mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EXAONE 4.0 1.2B EXAONE Deep 2.4BQwen 3 0.6B Qwen 3 1.7B SmolLM 3 3B
Model Size1.28B2.41B596M1.72B3.08B
Hybrid Reasoning
World Knowledge
MMLU-Redux71.568.955.673.974.8
MMLU-Pro59.356.438.357.757.8
GPQA-Diamond52.054.327.940.141.7
Math/Coding
AIME 202545.247.915.136.836.7
HMMT Feb 202534.027.37.021.826.0
LiveCodeBench v544.647.212.333.227.6
LiveCodeBench v645.343.116.429.929.1
Instruction Following
IFEval67.871.059.272.571.2
Multi-IF (EN)53.954.537.553.547.5
Agentic Tool Use
BFCL-v352.9N/A46.456.637.1
Tau-Bench (Airline)20.5N/A22.031.037.0
Tau-Bench (Retail)28.1N/A3.36.55.4
Multilinguality
KMMLU-Pro42.724.621.638.330.5
KMMLU-Redux46.925.024.538.033.7
KSM60.660.922.852.949.7
MMMLU (ES)62.451.448.864.564.7
MATH500 (ES)88.884.570.687.987.5
+ +### 1.2B Non-Reasoning Mode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EXAONE 4.0 1.2B Qwen 3 0.6B Gemma 3 1BQwen 3 1.7B SmolLM 3 3B
Model Size1.28B596M1.00B1.72B3.08B
Hybrid Reasoning
World Knowledge
MMLU-Redux66.944.640.963.465.0
MMLU-Pro52.026.614.743.743.6
GPQA-Diamond40.122.919.228.635.7
Math/Coding
AIME 202523.52.62.19.89.3
HMMT Feb 202513.01.01.55.14.7
LiveCodeBench v526.43.61.811.611.4
LiveCodeBench v630.16.92.316.620.6
Instruction Following
IFEval74.754.580.268.276.7
Multi-IF (EN)62.137.532.551.051.9
Long Context
HELMET41.221.1N/A33.838.6
RULER77.455.1N/A65.966.3
LongBench v136.932.4N/A41.939.9
Agentic Tool Use
BFCL-v355.744.1N/A52.247.3
Tau-Bench (Airline)10.031.5N/A13.538.0
Tau-Bench (Retail)21.75.7N/A4.66.7
Multilinguality
KMMLU-Pro37.524.69.729.527.6
KMMLU-Redux40.422.819.429.826.4
KSM26.30.122.816.316.1
Ko-LongBench69.816.4N/A57.115.7
MMMLU (ES)54.639.535.954.355.1
MATH500 (ES)71.238.541.266.062.4
WMT24++ (ES)65.958.276.976.784.0
+ + + +## Usage Guideline + +> [!IMPORTANT] +> To achieve the expected performance, we recommend using the following configurations: +> +> - For non-reasoning mode, we recommend using a lower temperature value such as `temperature<0.6` for better performance. +> - For reasoning mode (using `` block), we recommend using `temperature=0.6` and `top_p=0.95`. +> - If you suffer from the model degeneration, we recommend using `presence_penalty=1.5`. +> - For Korean general conversation with 1.2B model, we suggest to use `temperature=0.1` to avoid code switching. + + +## Limitation + +The EXAONE language model has certain limitations and may occasionally generate inappropriate responses. The language model generates responses based on the output probability of tokens, and it is determined during learning from training data. While we have made every effort to exclude personal, harmful, and biased information from the training data, some problematic content may still be included, potentially leading to undesirable responses. Please note that the text generated by EXAONE language model does not reflect the views of LG AI Research. + +- Inappropriate answers may be generated, which contain personal, harmful or other inappropriate information. +- Biased responses may be generated, which are associated with age, gender, race, and so on. +- The generated responses rely heavily on statistics from the training data, which can result in the generation of +semantically or syntactically incorrect sentences. +- Since the model does not reflect the latest information, the responses may be false or contradictory. + +LG AI Research strives to reduce potential risks that may arise from EXAONE language models. Users are not allowed +to engage in any malicious activities (e.g., keying in illegal information) that may induce the creation of inappropriate +outputs violating LG AI's ethical principles when using EXAONE language models. + + +## License + +The model is licensed under [EXAONE AI Model License Agreement 1.2 - NC](./LICENSE) + +> [!NOTE] +> The main difference from the older version is as below: +> - We removed **the claim of model output ownership** from the license. +> - We restrict the model use **against the development of models that compete with EXAONE**. +> - We allow the model to be used for **educational purposes**, not just research. + + +## Citation + +``` +@article{exaone-4.0, + title={EXAONE 4.0: Unified Large Language Models Integrating Non-reasoning and Reasoning Modes}, + author={{LG AI Research}}, + journal={arXiv preprint arXiv:2507.11407}, + year={2025} +} +``` + + +## Contact + +LG AI Research Technical Support: contact_us@lgresearch.ai diff --git a/assets/EXAONE_Symbol+BI_3d.png b/assets/EXAONE_Symbol+BI_3d.png new file mode 100644 index 0000000..65dd84c --- /dev/null +++ b/assets/EXAONE_Symbol+BI_3d.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c473c63768e9303c02a4f968fd2e7d41df3f669fedc6a7b51c4398cfcd7f23e4 +size 249084 diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..3cc13f6 --- /dev/null +++ b/chat_template.jinja @@ -0,0 +1,146 @@ +{%- if not skip_think is defined %} + {%- set skip_think = true %} +{%- endif %} + +{%- set role_indicators = { + 'user': '[|user|]\n', + 'assistant': '[|assistant|]\n', + 'system': '[|system|]\n', + 'tool': '[|tool|]\n' +} %} +{%- set end_of_turn = '[|endofturn|]\n' %} + + +{%- macro available_tools(tools) %} + {{- "# Available Tools" }} + {{- "\nYou can use none, one, or multiple of the following tools by calling them as functions to help with the user’s query." }} + {{- "\nHere are the tools available to you in JSON format within and tags:\n" }} + {%- for tool in tools %} + {{- "" }} + {{- tool | tojson | safe }} + {{- "\n" }} + {%- endfor %} + + {{- "\nFor each function call you want to make, return a JSON object with function name and arguments within and tags, like:" }} + {{- "\n{\"name\": function_1_name, \"arguments\": {argument_1_name: argument_1_value, argument_2_name: argument_2_value}}" }} + {{- "\n{\"name\": function_2_name, \"arguments\": {...}}\n..." }} + {{- "\nNote that if no argument name is specified for a tool, you can just print the argument value directly, without the argument name or JSON formatting." }} +{%- endmacro %} + + +{%- set ns = namespace(last_query_index = messages|length - 1) %} +{%- for message in messages %} + {%- if message.role == "user" and message.content is string %} + {%- set ns.last_query_index = loop.index0 -%} + {%- endif %} +{%- endfor %} + +{%- for i in range(messages | length) %} + {%- set msg = messages[i] %} + {%- set role = msg.role %} + {% if role is not none and role.class is not none and not role in role_indicators %} + {{- raise_exception('Unknown role: ' ~ role) }} + {%- endif %} + + {%- if i == 0 %} + {%- if role == 'system' %} + {{- role_indicators['system'] }} + {{- msg.content }} + {%- if tools is defined and tools %} + {{- "\n\n" }}{{- available_tools(tools) }} + {%- endif %} + {{- end_of_turn -}} + {%- continue %} + {%- elif tools is defined and tools %} + {{- role_indicators['system'] }} + {{- available_tools(tools) }} + {{- end_of_turn -}} + {%- endif %} + {%- endif %} + + {%- if role == 'assistant' %} + {{- role_indicators['assistant'] }} + + {%- if msg.content %} + {%- if "" in msg.content %} + {%- set content = msg.content.split('')[-1].strip() %} + {%- set reasoning_content = msg.content.split('')[0].strip() %} + {%- if reasoning_content.startswith("") %} + {%- set reasoning_content = reasoning_content[9:].strip() %} + {%- endif %} + {%- else %} + {%- set content = msg.content %} + {%- endif %} + + {%- if msg.reasoning_content %} + {%- set reasoning_content = msg.reasoning_content %} + {%- endif %} + + {%- if (not skip_think and loop.last) and reasoning_content is defined %} + {{- "\n" }} + {{- reasoning_content}} + {{- "\n\n\n" }} + {%- else %} + {{- "\n\n\n\n" }} + {%- endif %} + {{- content }} + {%- endif %} + + {%- if msg.tool_calls %} + {%- if msg.content %} + {{- "\n" }} + {%- else %} + {{- "\n\n\n\n" }} + {%- endif %} + {%- for tool_call in msg.tool_calls %} + {%- if tool_call.function is defined %} + {%- set tool_call = tool_call.function %} + {%- endif %} + + {%- if tool_call.arguments is defined %} + {%- set arguments = tool_call.arguments %} + {%- elif tool_call.parameters is defined %} + {%- set arguments = tool_call.parameters %} + {%- else %} + {{- raise_exception('arguments or parameters are mandatory: ' ~ tool_call) }} + {%- endif %} + + {{- "" }}{"name": "{{- tool_call.name }}", "arguments": {{ arguments | tojson | safe }}}{{- "" }} + + {%- if not loop.last %} + {{- "\n" }} + {%- endif %} + + {%- endfor %} + {%- endif %} + {{- end_of_turn -}} + + {%- elif role == "tool" %} + {%- if i == 0 or messages[i - 1].role != "tool" %} + {{- role_indicators['tool'] }} + {%- endif %} + {%- if msg.content is defined %} + {{- "" }}{"result": {{ msg.content | tojson | safe }}}{{- "" }} + {%- endif %} + {%- if loop.last or messages[i + 1].role != "tool" %} + {{- end_of_turn -}} + {%- else %} + {{- "\n" }} + {%- endif %} + + {%- else %} + {{- role_indicators[role] }} + {{- msg.content }} + {{- end_of_turn -}} + {%- endif %} +{% endfor %} + + +{%- if add_generation_prompt %} + {{- role_indicators['assistant'] }} + {%- if enable_thinking is defined and enable_thinking is true %} + {{- "\n" }} + {%- else %} + {{- "\n\n\n\n" }} + {%- endif %} +{%- endif %} \ No newline at end of file diff --git a/configuration.json b/configuration.json new file mode 100644 index 0000000..bbeeda1 --- /dev/null +++ b/configuration.json @@ -0,0 +1 @@ +{"framework": "pytorch", "task": "text-generation", "allow_remote": true} \ No newline at end of file