Image-Text-to-Text
Transformers
Safetensors
English
gemma4
text-generation-inference
unsloth
conversational
Instructions to use maxbsoft/small-tts-merged with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use maxbsoft/small-tts-merged with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="maxbsoft/small-tts-merged") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("maxbsoft/small-tts-merged") model = AutoModelForImageTextToText.from_pretrained("maxbsoft/small-tts-merged") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use maxbsoft/small-tts-merged with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "maxbsoft/small-tts-merged" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "maxbsoft/small-tts-merged", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/maxbsoft/small-tts-merged
- SGLang
How to use maxbsoft/small-tts-merged 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 "maxbsoft/small-tts-merged" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "maxbsoft/small-tts-merged", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "maxbsoft/small-tts-merged" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "maxbsoft/small-tts-merged", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Unsloth Studio new
How to use maxbsoft/small-tts-merged with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for maxbsoft/small-tts-merged to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for maxbsoft/small-tts-merged to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for maxbsoft/small-tts-merged to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="maxbsoft/small-tts-merged", max_seq_length=2048, ) - Docker Model Runner
How to use maxbsoft/small-tts-merged with Docker Model Runner:
docker model run hf.co/maxbsoft/small-tts-merged
| { | |
| "audio_token": "<|audio|>", | |
| "backend": "tokenizers", | |
| "boa_token": "<|audio>", | |
| "boi_token": "<|image>", | |
| "bos_token": "<bos>", | |
| "eoa_token": "<audio|>", | |
| "eoc_token": "<channel|>", | |
| "eoi_token": "<image|>", | |
| "eos_token": "<turn|>", | |
| "eot_token": "<turn|>", | |
| "escape_token": "<|\"|>", | |
| "etc_token": "<tool_call|>", | |
| "etd_token": "<tool|>", | |
| "etr_token": "<tool_response|>", | |
| "extra_special_tokens": [ | |
| "<unused0>", | |
| "<unused1>", | |
| "<unused2>", | |
| "<unused3>", | |
| "<unused4>", | |
| "<unused5>", | |
| "<unused6>", | |
| "<unused7>", | |
| "<unused8>", | |
| "<unused9>", | |
| "<unused10>", | |
| "<unused11>", | |
| "<unused12>", | |
| "<unused13>", | |
| "<unused14>", | |
| "<unused15>", | |
| "<unused16>", | |
| "<unused17>", | |
| "<unused18>", | |
| "<unused19>", | |
| "<unused20>", | |
| "<unused21>", | |
| "<unused22>", | |
| "<unused23>", | |
| "<unused24>", | |
| "<unused25>", | |
| "<unused26>", | |
| "<unused27>", | |
| "<unused28>", | |
| "<unused29>", | |
| "<unused30>", | |
| "<unused31>", | |
| "<unused32>", | |
| "<unused33>", | |
| "<unused34>", | |
| "<unused35>", | |
| "<unused36>", | |
| "<unused37>", | |
| "<unused38>", | |
| "<unused39>", | |
| "<unused40>", | |
| "<unused41>", | |
| "<unused42>", | |
| "<unused43>", | |
| "<unused44>", | |
| "<unused45>", | |
| "<unused46>", | |
| "<unused47>", | |
| "<unused48>", | |
| "<unused49>", | |
| "<unused50>", | |
| "<unused51>", | |
| "<unused52>", | |
| "<unused53>", | |
| "<unused54>", | |
| "<unused55>", | |
| "<unused56>", | |
| "<unused57>", | |
| "<unused58>", | |
| "<unused59>", | |
| "<unused60>", | |
| "<unused61>", | |
| "<unused62>", | |
| "<unused63>", | |
| "<unused64>", | |
| "<unused65>", | |
| "<unused66>", | |
| "<unused67>", | |
| "<unused68>", | |
| "<unused69>", | |
| "<unused70>", | |
| "<unused71>", | |
| "<unused72>", | |
| "<unused73>", | |
| "<unused74>", | |
| "<unused75>", | |
| "<unused76>", | |
| "<unused77>", | |
| "<unused78>", | |
| "<unused79>", | |
| "<unused80>", | |
| "<unused81>", | |
| "<unused82>", | |
| "<unused83>", | |
| "<unused84>", | |
| "<unused85>", | |
| "<unused86>", | |
| "<unused87>", | |
| "<unused88>", | |
| "<unused89>", | |
| "<unused90>", | |
| "<unused91>", | |
| "<unused92>", | |
| "<unused93>", | |
| "<unused94>", | |
| "<unused95>", | |
| "<unused96>", | |
| "<unused97>", | |
| "<unused98>", | |
| "<unused99>", | |
| "<unused100>", | |
| "<unused101>", | |
| "<unused102>", | |
| "<unused103>", | |
| "<unused104>", | |
| "<unused105>", | |
| "<unused106>", | |
| "<unused107>", | |
| "<unused108>", | |
| "<unused109>", | |
| "<unused110>", | |
| "<unused111>", | |
| "<unused112>", | |
| "<unused113>", | |
| "<unused114>", | |
| "<unused115>", | |
| "<unused116>", | |
| "<unused117>", | |
| "<unused118>", | |
| "<unused119>", | |
| "<unused120>", | |
| "<unused121>", | |
| "<unused122>", | |
| "<unused123>", | |
| "<unused124>", | |
| "<unused125>", | |
| "<unused126>", | |
| "<unused127>", | |
| "<unused128>", | |
| "<unused129>", | |
| "<unused130>", | |
| "<unused131>", | |
| "<unused132>", | |
| "<unused133>", | |
| "<unused134>", | |
| "<unused135>", | |
| "<unused136>", | |
| "<unused137>", | |
| "<unused138>", | |
| "<unused139>", | |
| "<unused140>", | |
| "<unused141>", | |
| "<unused142>", | |
| "<unused143>", | |
| "<unused144>", | |
| "<unused145>", | |
| "<unused146>", | |
| "<unused147>", | |
| "<unused148>", | |
| "<unused149>", | |
| "<unused150>", | |
| "<unused151>", | |
| "<unused152>", | |
| "<unused153>", | |
| "<unused154>", | |
| "<unused155>", | |
| "<unused156>", | |
| "<unused157>", | |
| "<unused158>", | |
| "<unused159>", | |
| "<unused160>", | |
| "<unused161>", | |
| "<unused162>", | |
| "<unused163>", | |
| "<unused164>", | |
| "<unused165>", | |
| "<unused166>", | |
| "<unused167>", | |
| "<unused168>", | |
| "<unused169>", | |
| "<unused170>", | |
| "<unused171>", | |
| "<unused172>", | |
| "<unused173>", | |
| "<unused174>", | |
| "<unused175>", | |
| "<unused176>", | |
| "<unused177>", | |
| "<unused178>", | |
| "<unused179>", | |
| "<unused180>", | |
| "<unused181>", | |
| "<unused182>", | |
| "<unused183>", | |
| "<unused184>", | |
| "<unused185>", | |
| "<unused186>", | |
| "<unused187>", | |
| "<unused188>", | |
| "<unused189>", | |
| "<unused190>", | |
| "<unused191>", | |
| "<unused192>", | |
| "<unused193>", | |
| "<unused194>", | |
| "<unused195>", | |
| "<unused196>", | |
| "<unused197>", | |
| "<unused198>", | |
| "<unused199>", | |
| "<unused200>", | |
| "<unused201>", | |
| "<unused202>", | |
| "<unused203>", | |
| "<unused204>", | |
| "<unused205>", | |
| "<unused206>", | |
| "<unused207>", | |
| "<unused208>", | |
| "<unused209>", | |
| "<unused210>", | |
| "<unused211>", | |
| "<unused212>", | |
| "<unused213>", | |
| "<unused214>", | |
| "<unused215>", | |
| "<unused216>", | |
| "<unused217>", | |
| "<unused218>", | |
| "<unused219>", | |
| "<unused220>", | |
| "<unused221>", | |
| "<unused222>", | |
| "<unused223>", | |
| "<unused224>", | |
| "<unused225>", | |
| "<unused226>", | |
| "<unused227>", | |
| "<unused228>", | |
| "<unused229>", | |
| "<unused230>", | |
| "<unused231>", | |
| "<unused232>", | |
| "<unused233>", | |
| "<unused234>", | |
| "<unused235>", | |
| "<unused236>", | |
| "<unused237>", | |
| "<unused238>", | |
| "<unused239>", | |
| "<unused240>", | |
| "<unused241>", | |
| "<unused242>", | |
| "<unused243>", | |
| "<unused244>", | |
| "<unused245>", | |
| "<unused246>", | |
| "<unused247>", | |
| "<unused248>", | |
| "<unused249>", | |
| "<unused250>", | |
| "<unused251>", | |
| "<unused252>", | |
| "<unused253>", | |
| "<unused254>", | |
| "<unused255>", | |
| "<unused256>", | |
| "<unused257>", | |
| "<unused258>", | |
| "<unused259>", | |
| "<unused260>", | |
| "<unused261>", | |
| "<unused262>", | |
| "<unused263>", | |
| "<unused264>", | |
| "<unused265>", | |
| "<unused266>", | |
| "<unused267>", | |
| "<unused268>", | |
| "<unused269>", | |
| "<unused270>", | |
| "<unused271>", | |
| "<unused272>", | |
| "<unused273>", | |
| "<unused274>", | |
| "<unused275>", | |
| "<unused276>", | |
| "<unused277>", | |
| "<unused278>", | |
| "<unused279>", | |
| "<unused280>", | |
| "<unused281>", | |
| "<unused282>", | |
| "<unused283>", | |
| "<unused284>", | |
| "<unused285>", | |
| "<unused286>", | |
| "<unused287>", | |
| "<unused288>", | |
| "<unused289>", | |
| "<unused290>", | |
| "<unused291>", | |
| "<unused292>", | |
| "<unused293>", | |
| "<unused294>", | |
| "<unused295>", | |
| "<unused296>", | |
| "<unused297>", | |
| "<unused298>", | |
| "<unused299>", | |
| "<unused300>", | |
| "<unused301>", | |
| "<unused302>", | |
| "<unused303>", | |
| "<unused304>", | |
| "<unused305>", | |
| "<unused306>", | |
| "<unused307>", | |
| "<unused308>", | |
| "<unused309>", | |
| "<unused310>", | |
| "<unused311>", | |
| "<unused312>", | |
| "<unused313>", | |
| "<unused314>", | |
| "<unused315>", | |
| "<unused316>", | |
| "<unused317>", | |
| "<unused318>", | |
| "<unused319>", | |
| "<unused320>", | |
| "<unused321>", | |
| "<unused322>", | |
| "<unused323>", | |
| "<unused324>", | |
| "<unused325>", | |
| "<unused326>", | |
| "<unused327>", | |
| "<unused328>", | |
| "<unused329>", | |
| "<unused330>", | |
| "<unused331>", | |
| "<unused332>", | |
| "<unused333>", | |
| "<unused334>", | |
| "<unused335>", | |
| "<unused336>", | |
| "<unused337>", | |
| "<unused338>", | |
| "<unused339>", | |
| "<unused340>", | |
| "<unused341>", | |
| "<unused342>", | |
| "<unused343>", | |
| "<unused344>", | |
| "<unused345>", | |
| "<unused346>", | |
| "<unused347>", | |
| "<unused348>", | |
| "<unused349>", | |
| "<unused350>", | |
| "<unused351>", | |
| "<unused352>", | |
| "<unused353>", | |
| "<unused354>", | |
| "<unused355>", | |
| "<unused356>", | |
| "<unused357>", | |
| "<unused358>", | |
| "<unused359>", | |
| "<unused360>", | |
| "<unused361>", | |
| "<unused362>", | |
| "<unused363>", | |
| "<unused364>", | |
| "<unused365>", | |
| "<unused366>", | |
| "<unused367>", | |
| "<unused368>", | |
| "<unused369>", | |
| "<unused370>", | |
| "<unused371>", | |
| "<unused372>", | |
| "<unused373>", | |
| "<unused374>", | |
| "<unused375>", | |
| "<unused376>", | |
| "<unused377>", | |
| "<unused378>", | |
| "<unused379>", | |
| "<unused380>", | |
| "<unused381>", | |
| "<unused382>", | |
| "<unused383>", | |
| "<unused384>", | |
| "<unused385>", | |
| "<unused386>", | |
| "<unused387>", | |
| "<unused388>", | |
| "<unused389>", | |
| "<unused390>", | |
| "<unused391>", | |
| "<unused392>", | |
| "<unused393>", | |
| "<unused394>", | |
| "<unused395>", | |
| "<unused396>", | |
| "<unused397>", | |
| "<unused398>", | |
| "<unused399>", | |
| "<unused400>", | |
| "<unused401>", | |
| "<unused402>", | |
| "<unused403>", | |
| "<unused404>", | |
| "<unused405>", | |
| "<unused406>", | |
| "<unused407>", | |
| "<unused408>", | |
| "<unused409>", | |
| "<unused410>", | |
| "<unused411>", | |
| "<unused412>", | |
| "<unused413>", | |
| "<unused414>", | |
| "<unused415>", | |
| "<unused416>", | |
| "<unused417>", | |
| "<unused418>", | |
| "<unused419>", | |
| "<unused420>", | |
| "<unused421>", | |
| "<unused422>", | |
| "<unused423>", | |
| "<unused424>", | |
| "<unused425>", | |
| "<unused426>", | |
| "<unused427>", | |
| "<unused428>", | |
| "<unused429>", | |
| "<unused430>", | |
| "<unused431>", | |
| "<unused432>", | |
| "<unused433>", | |
| "<unused434>", | |
| "<unused435>", | |
| "<unused436>", | |
| "<unused437>", | |
| "<unused438>", | |
| "<unused439>", | |
| "<unused440>", | |
| "<unused441>", | |
| "<unused442>", | |
| "<unused443>", | |
| "<unused444>", | |
| "<unused445>", | |
| "<unused446>", | |
| "<unused447>", | |
| "<unused448>", | |
| "<unused449>", | |
| "<unused450>", | |
| "<unused451>", | |
| "<unused452>", | |
| "<unused453>", | |
| "<unused454>", | |
| "<unused455>", | |
| "<unused456>", | |
| "<unused457>", | |
| "<unused458>", | |
| "<unused459>", | |
| "<unused460>", | |
| "<unused461>", | |
| "<unused462>", | |
| "<unused463>", | |
| "<unused464>", | |
| "<unused465>", | |
| "<unused466>", | |
| "<unused467>", | |
| "<unused468>", | |
| "<unused469>", | |
| "<unused470>", | |
| "<unused471>", | |
| "<unused472>", | |
| "<unused473>", | |
| "<unused474>", | |
| "<unused475>", | |
| "<unused476>", | |
| "<unused477>", | |
| "<unused478>", | |
| "<unused479>", | |
| "<unused480>", | |
| "<unused481>", | |
| "<unused482>", | |
| "<unused483>", | |
| "<unused484>", | |
| "<unused485>", | |
| "<unused486>", | |
| "<unused487>", | |
| "<unused488>", | |
| "<unused489>", | |
| "<unused490>", | |
| "<unused491>", | |
| "<unused492>", | |
| "<unused493>", | |
| "<unused494>", | |
| "<unused495>", | |
| "<unused496>", | |
| "<unused497>", | |
| "<unused498>", | |
| "<unused499>", | |
| "<unused500>", | |
| "<unused501>", | |
| "<unused502>", | |
| "<unused503>", | |
| "<unused504>", | |
| "<unused505>", | |
| "<unused506>", | |
| "<unused507>", | |
| "<unused508>", | |
| "<unused509>", | |
| "<unused510>", | |
| "<unused511>" | |
| ], | |
| "image_token": "<|image|>", | |
| "is_local": false, | |
| "mask_token": "<mask>", | |
| "model_max_length": 131072, | |
| "model_specific_special_tokens": { | |
| "audio_token": "<|audio|>", | |
| "boa_token": "<|audio>", | |
| "boi_token": "<|image>", | |
| "eoa_token": "<audio|>", | |
| "eoc_token": "<channel|>", | |
| "eoi_token": "<image|>", | |
| "eot_token": "<turn|>", | |
| "escape_token": "<|\"|>", | |
| "etc_token": "<tool_call|>", | |
| "etd_token": "<tool|>", | |
| "etr_token": "<tool_response|>", | |
| "image_token": "<|image|>", | |
| "soc_token": "<|channel>", | |
| "sot_token": "<|turn>", | |
| "stc_token": "<|tool_call>", | |
| "std_token": "<|tool>", | |
| "str_token": "<|tool_response>", | |
| "think_token": "<|think|>" | |
| }, | |
| "pad_token": "<pad>", | |
| "padding_side": "right", | |
| "processor_class": "Gemma4Processor", | |
| "response_schema": { | |
| "properties": { | |
| "content": { | |
| "type": "string" | |
| }, | |
| "role": { | |
| "const": "assistant" | |
| }, | |
| "thinking": { | |
| "type": "string" | |
| }, | |
| "tool_calls": { | |
| "items": { | |
| "properties": { | |
| "function": { | |
| "properties": { | |
| "arguments": { | |
| "additionalProperties": {}, | |
| "type": "object", | |
| "x-parser": "gemma4-tool-call" | |
| }, | |
| "name": { | |
| "type": "string" | |
| } | |
| }, | |
| "type": "object", | |
| "x-regex": "call\\:(?P<name>\\w+)(?P<arguments>\\{.*\\})" | |
| }, | |
| "type": { | |
| "const": "function" | |
| } | |
| }, | |
| "type": "object" | |
| }, | |
| "type": "array", | |
| "x-regex-iterator": "<\\|tool_call>(.*?)<tool_call\\|>" | |
| } | |
| }, | |
| "type": "object", | |
| "x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<content>(?:(?!\\<\\|tool_call\\>)(?!\\<turn\\|\\>).)+)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?:\\<turn\\|\\>)?" | |
| }, | |
| "soc_token": "<|channel>", | |
| "sot_token": "<|turn>", | |
| "stc_token": "<|tool_call>", | |
| "std_token": "<|tool>", | |
| "str_token": "<|tool_response>", | |
| "think_token": "<|think|>", | |
| "tokenizer_class": "GemmaTokenizer", | |
| "unk_token": "<unk>", | |
| "chat_template": "{%- macro format_parameters(properties, required) -%}\n {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}\n {%- set ns = namespace(found_first=false) -%}\n {%- for key, value in properties | dictsort -%}\n {%- set add_comma = false -%}\n {%- if key not in standard_keys -%}\n {%- if ns.found_first %},{% endif -%}\n {%- set ns.found_first = true -%}\n {{ key }}:{\n {%- if value['description'] -%}\n description:<|\"|>{{ value['description'] }}<|\"|>\n {%- set add_comma = true -%}\n {%- endif -%}\n {%- if value['nullable'] %}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n nullable:true\n {%- endif -%}\n {%- if value['type'] | upper == 'STRING' -%}\n {%- if value['enum'] -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n enum:{{ format_argument(value['enum']) }}\n {%- endif -%}\n {%- elif value['type'] | upper == 'OBJECT' -%}\n ,properties:{\n {%- if value['properties'] is defined and value['properties'] is mapping -%}\n {{- format_parameters(value['properties'], value['required'] | default([])) -}}\n {%- elif value is mapping -%}\n {{- format_parameters(value, value['required'] | default([])) -}}\n {%- endif -%}\n }\n {%- if value['required'] -%}\n ,required:[\n {%- for item in value['required'] | default([]) -%}\n <|\"|>{{- item -}}<|\"|>\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n ]\n {%- endif -%}\n {%- elif value['type'] | upper == 'ARRAY' -%}\n {%- if value['items'] is mapping and value['items'] -%}\n ,items:{\n {%- set ns_items = namespace(found_first=false) -%}\n {%- for item_key, item_value in value['items'] | dictsort -%}\n {%- if item_value is not none -%}\n {%- if ns_items.found_first %},{% endif -%}\n {%- set ns_items.found_first = true -%}\n {%- if item_key == 'properties' -%}\n properties:{\n {%- if item_value is mapping -%}\n {{- format_parameters(item_value, value['items']['required'] | default([])) -}}\n {%- endif -%}\n }\n {%- elif item_key == 'required' -%}\n required:[\n {%- for req_item in item_value -%}\n <|\"|>{{- req_item -}}<|\"|>\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n ]\n {%- elif item_key == 'type' -%}\n {%- if item_value is string -%}\n type:{{ format_argument(item_value | upper) }}\n {%- else -%}\n type:{{ format_argument(item_value | map('upper') | list) }}\n {%- endif -%}\n {%- else -%}\n {{ item_key }}:{{ format_argument(item_value) }}\n {%- endif -%}\n {%- endif -%}\n {%- endfor -%}\n }\n {%- endif -%}\n {%- endif -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n type:<|\"|>{{ value['type'] | upper }}<|\"|>}\n {%- endif -%}\n {%- endfor -%}\n{%- endmacro -%}\n{%- macro format_function_declaration(tool_data) -%}\n declaration:{{- tool_data['function']['name'] -}}{description:<|\"|>{{- tool_data['function']['description'] -}}<|\"|>\n {%- set params = tool_data['function']['parameters'] -%}\n {%- if params -%}\n ,parameters:{\n {%- if params['properties'] -%}\n properties:{ {{- format_parameters(params['properties'], params['required']) -}} },\n {%- endif -%}\n {%- if params['required'] -%}\n required:[\n {%- for item in params['required'] -%}\n <|\"|>{{- item -}}<|\"|>\n {{- ',' if not loop.last -}}\n {%- endfor -%}\n ],\n {%- endif -%}\n {%- if params['type'] -%}\n type:<|\"|>{{- params['type'] | upper -}}<|\"|>}\n {%- endif -%}\n {%- endif -%}\n {%- if 'response' in tool_data['function'] -%}\n {%- set response_declaration = tool_data['function']['response'] -%}\n ,response:{\n {%- if response_declaration['description'] -%}\n description:<|\"|>{{- response_declaration['description'] -}}<|\"|>,\n {%- endif -%}\n {%- if response_declaration['type'] | upper == 'OBJECT' -%}\n type:<|\"|>{{- response_declaration['type'] | upper -}}<|\"|>}\n {%- endif -%}\n {%- endif -%}\n }\n{%- endmacro -%}\n{%- macro format_argument(argument, escape_keys=True) -%}\n {%- if argument is string -%}\n {{- '<|\"|>' + argument + '<|\"|>' -}}\n {%- elif argument is boolean -%}\n {{- 'true' if argument else 'false' -}}\n {%- elif argument is mapping -%}\n {{- '{' -}}\n {%- set ns = namespace(found_first=false) -%}\n {%- for key, value in argument | dictsort -%}\n {%- if ns.found_first %},{% endif -%}\n {%- set ns.found_first = true -%}\n {%- if escape_keys -%}\n {{- '<|\"|>' + key + '<|\"|>' -}}\n {%- else -%}\n {{- key -}}\n {%- endif -%}\n :{{- format_argument(value, escape_keys=escape_keys) -}}\n {%- endfor -%}\n {{- '}' -}}\n {%- elif argument is sequence -%}\n {{- '[' -}}\n {%- for item in argument -%}\n {{- format_argument(item, escape_keys=escape_keys) -}}\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n {{- ']' -}}\n {%- else -%}\n {{- argument -}}\n {%- endif -%}\n{%- endmacro -%}\n{%- macro strip_thinking(text) -%}\n {%- set ns = namespace(result='') -%}\n {%- for part in text.split('<channel|>') -%}\n {%- if '<|channel>' in part -%}\n {%- set ns.result = ns.result + part.split('<|channel>')[0] -%}\n {%- else -%}\n {%- set ns.result = ns.result + part -%}\n {%- endif -%}\n {%- endfor -%}\n {{- ns.result | trim -}}\n{%- endmacro -%}\n\n{%- set ns = namespace(prev_message_type=None) -%}\n{%- set loop_messages = messages -%}\n{{ bos_token }}\n{#- Handle System/Tool Definitions Block -#}\n{%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}\n {{- '<|turn>system\\n' -}}\n\n {#- Inject Thinking token at the very top of the FIRST system turn -#}\n {%- if enable_thinking is defined and enable_thinking -%}\n {{- '<|think|>' -}}\n {%- set ns.prev_message_type = 'think' -%}\n {%- endif -%}\n\n {%- if messages[0]['role'] in ['system', 'developer'] -%}\n {{- messages[0]['content'] | trim -}}\n {%- set loop_messages = messages[1:] -%}\n {%- endif -%}\n\n {%- if tools -%}\n {%- for tool in tools %}\n {{- '<|tool>' -}}\n {{- format_function_declaration(tool) | trim -}}\n {{- '<tool|>' -}}\n {%- endfor %}\n {%- set ns.prev_message_type = 'tool' -%}\n {%- endif -%}\n\n {{- '<turn|>\\n' -}}\n{%- endif %}\n\n{#- Loop through messages -#}\n{%- for message in loop_messages -%}\n {%- set ns.prev_message_type = None -%}\n {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}\n {{- '<|turn>' + role + '\\n' }}\n\n {%- if message['tool_calls'] -%}\n {%- for tool_call in message['tool_calls'] -%}\n {%- set function = tool_call['function'] -%}\n {{- '<|tool_call>call:' + function['name'] + '{' -}}\n {%- if function['arguments'] is mapping -%}\n {%- set ns_args = namespace(found_first=false) -%}\n {%- for key, value in function['arguments'] | dictsort -%}\n {%- if ns_args.found_first %},{% endif -%}\n {%- set ns_args.found_first = true -%}\n {{- key -}}:{{- format_argument(value, escape_keys=False) -}}\n {%- endfor -%}\n {%- elif function['arguments'] is string -%}\n {{- function['arguments'] -}}\n {%- endif -%}\n {{- '}<tool_call|>' -}}\n {%- endfor -%}\n {%- set ns.prev_message_type = 'tool_call' -%}\n {%- endif -%}\n\n {%- if message['tool_responses'] -%}\n {#- Tool Response handling -#}\n {%- for tool_response in message['tool_responses'] -%}\n {{- '<|tool_response>' -}}\n {%- if tool_response['response'] is mapping -%}\n {{- 'response:' + tool_response['name'] | default('unknown') + '{' -}}\n {%- for key, value in tool_response['response'] | dictsort -%}\n {{- key -}}:{{- format_argument(value, escape_keys=False) -}}\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n {{- '}' -}}\n {%- else -%}\n {{- 'response:' + tool_response['name'] | default('unknown') + '{value:' + format_argument(tool_response['response'], escape_keys=False) + '}' -}}\n {%- endif -%}\n {{- '<tool_response|>' -}}\n {%- endfor -%}\n {%- set ns.prev_message_type = 'tool_response' -%}\n {%- endif -%}\n\n {%- if message['content'] is string -%}\n {%- if role == 'model' -%}\n {{- strip_thinking(message['content']) -}}\n {%- else -%}\n {{- message['content'] | trim -}}\n {%- endif -%}\n {%- elif message['content'] is sequence -%}\n {%- for item in message['content'] -%}\n {%- if item['type'] == 'text' -%}\n {%- if role == 'model' -%}\n {{- strip_thinking(item['text']) -}}\n {%- else -%}\n {{- item['text'] | trim -}}\n {%- endif -%}\n {%- elif item['type'] == 'image' -%}\n {{- '\\n\\n<|image|>\\n\\n' -}}\n {%- set ns.prev_message_type = 'image' -%}\n {%- elif item['type'] == 'audio' -%}\n {{- '<|audio|>' -}}\n {%- set ns.prev_message_type = 'audio' -%}\n {%- elif item['type'] == 'video' -%}\n {{- '\\n\\n<|video|>\\n\\n' -}}\n {%- set ns.prev_message_type = 'video' -%}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n\n {%- if not (message['tool_responses'] and not message['content']) -%}\n {{- '<turn|>\\n' -}}\n {%- endif -%}\n{%- endfor -%}\n\n{%- if add_generation_prompt -%}\n {%- if ns.prev_message_type != 'tool_response' -%}\n {{- '<|turn>model\\n' -}}\n {%- endif -%}\n{%- endif -%}" | |
| } |