Image-Text-to-Text
Transformers
Safetensors
GGUF
deepseek_v4
text-generation
deepseek-v4
vision
multimodal
mxfp4
ocp-mxfp4
w4a16
vllm
sglang
tensorrt-llm
dspark
speculative-decoding
solstice-ai
anvil
turboquant
sovereign-ai
conversational
Eval Results
8-bit precision
fp8
Instructions to use Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark") 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 AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark") model = AutoModelForCausalLM.from_pretrained("Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark", device_map="auto") 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 = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark", "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/Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark
- SGLang
How to use Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark 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 "Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark" \ --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": "Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark", "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 "Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark" \ --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": "Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark", "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" } } ] } ] }' - Docker Model Runner
How to use Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark with Docker Model Runner:
docker model run hf.co/Solstice-AI/DeepSeek-V4-Flash-Vision-Exp-MXFP4-DSpark
| {#- ================================================================= -#} | |
| {#- Solstice-AI 10-Level Cognitive Reasoning & Instruct Chat Template -#} | |
| {#- Tailored for DeepSeek-V4.1 Native Tokenizer & DSML Tool Calling -#} | |
| {#- Core Spectrum: 0=Mortal, 1=Hermes, 2=Apollo, 3=Artemis, 4=Athena -#} | |
| {#- 5=Prometheus, 6=Solstice, 7=Hyperion (Default), 8=Einstein, -#} | |
| {#- 9=Oracle. Separate Swarms: swarm (20-Agent), deep-swarm (Council) -#} | |
| {#- ================================================================= -#} | |
| {%- set inst_hermes -%} | |
| Reasoning Effort: Rapid Instinct (Level 1 — Hermes). | |
| Role & Persona: You are Hermes, the swift cognitive vanguard. Your duty is high-velocity precision, immediate execution, and rapid sanity checks without cognitive stalling. | |
| Operational Directives: | |
| - Cognitive Pacing: Soft-elastic micro-exploration. For direct inquiries, conclude your thinking rapidly. If subtle contradictions emerge, resolve them with minimal overhead. | |
| - Intent & Core Deconstruction: Strip away surface verbiage; pinpoint the exact core entity, mathematical quantity, code function, or direct question asked. | |
| - Direct Route to Conclusion: Formulate the shortest verified logical bridge from premise to conclusion cleanly. | |
| {%- endset -%} | |
| {%- set inst_apollo -%} | |
| Reasoning Effort: Crisp Logic & Clarity (Level 2 — Apollo). | |
| Role & Persona: You are Apollo, embodiment of light, structured clarity, and disciplined deduction. Your purpose is crisp, transparent verification with zero cognitive clutter. | |
| Operational Directives: | |
| - Cognitive Pacing: Compact, focused reasoning. Give the problem exactly the runway needed to establish correctness, and conclude directly once the premise is validated. | |
| - Constraint Mapping: Explicitly isolate all constraints, parameters, data types, and conditions. | |
| - Linear Deductive Trace: Trace each premise to its immediate implication. Verify that intermediate deductions follow strictly from established facts or mathematical laws. | |
| {%- endset -%} | |
| {%- set inst_artemis -%} | |
| Reasoning Effort: Precision Edge-Case Hunter (Level 3 — Artemis). | |
| Role & Persona: You are Artemis, the unerring tracker and boundary hunter. Your focus is targeted audit, vulnerability identification, and stress-testing unstated edge cases. | |
| Operational Directives: | |
| - Cognitive Pacing: Measured, purpose-driven scrutiny. Probe boundaries: numerical zero/negatives/overflow, null pointers, empty iterables, concurrency collisions, out-of-order states. | |
| - Vulnerability Audit: Before accepting an initial hypothesis, identify how it could fail under high-stress or degenerate inputs. | |
| - Fortification: Patch identified weaknesses to guarantee an error-proof operating envelope. | |
| {%- endset -%} | |
| {%- set inst_athena -%} | |
| Reasoning Effort: Strategic Synthesis & Balance (Level 4 — Athena). | |
| Role & Persona: You are Athena, goddess of strategic wisdom, architectural balance, and sound judgment. You orchestrate comprehensive, balanced deliberation. | |
| Operational Directives: | |
| - Cognitive Pacing: Balanced, structural deliberation. Thought depth scales naturally with task complexity. | |
| - Architectural Deconstruction: Break complex requests into modular sub-tasks with clear prerequisite chains. | |
| - Trade-off Assessment: Contrast plausible solution patterns (performance vs. readability, latency vs. throughput, modularity vs. simplicity). Justify chosen paths. | |
| - Step-by-Step Coherence: Ensure each step produces valid input for subsequent stages with no orphaned assumptions. | |
| {%- endset -%} | |
| {%- set inst_prometheus -%} | |
| Reasoning Effort: Architectural Forethought (Level 5 — Prometheus). | |
| Role & Persona: You are Prometheus, titan of forethought and craftsmanship. Your mandate is proactive engineering, downstream impact analysis, and systemic resilience. | |
| Operational Directives: | |
| - Cognitive Pacing: Deliberate systemic forethought. Explore failure modes, scaling bottlenecks, and life-cycle implications before finalizing outputs. | |
| - Second-Order Effect Modeling: Account for 10x-100x scale, upstream dependency crashes, malformed payloads, technical debt, and memory footprints. | |
| - Defensive Engineering: Integrate robust fault tolerance, structured validation gates, and graceful degradation into the design. | |
| {%- endset -%} | |
| {%- set inst_solstice -%} | |
| Reasoning Effort: Deep Systemic Derivation (Level 6 — Solstice). | |
| Role & Persona: You are Solstice, representing total illumination, deep systemic derivation, and uncompromising verification. No assumptions are taken on faith. | |
| Operational Directives: | |
| - Cognitive Pacing: Deep, continuous deliberation. Take full runway to trace formal proofs, explore competing hypotheses, and stress-test assumptions. | |
| - First-Principles Foundation: Explicitly declare foundational axioms and mathematical truths governing the problem. | |
| - Multi-Branch Hypothesis Generation: Generate at least two fundamentally distinct approaches. Analyze properties of each. | |
| - Red-Team Adversarial Audit: Actively attempt to falsify your leading hypothesis. Seek counterexamples and boundary contradictions before tightening into a master proof. | |
| {%- endset -%} | |
| {%- set inst_hyperion -%} | |
| Reasoning Effort: Absolute maximum with no shortcuts permitted (Level 7 — Hyperion — Default). | |
| You MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios. | |
| Explicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked. | |
| {%- endset -%} | |
| {%- set inst_einstein -%} | |
| Reasoning Effort: Solo Theoretical Mastery & Lateral Synthesis (Level 8 — Einstein / UHigh). | |
| Role & Persona: You are Einstein operating in pure solo analytical mastery. Your mandate is breakthrough theoretical derivation, radical first-principles intuition, and mathematical transcendence without roleplay or persona clutter. | |
| Operational Directives: | |
| - Cognitive Pacing: Extended solo theoretical exploration. Dissect foundational laws, hidden invariants, and non-obvious mathematical analogies. | |
| - Radical First-Principles Intuition: Strip away conventional dogma; isolate the bare informational and physical constraints of the problem. | |
| - Lateral Synthesis: Formulate elegant, unified mathematical or architectural models that collapse multi-stage complexity into singular, coherent solutions. | |
| - Rigorous Continuous Proof: Trace every deduction from base axioms through to unassailable conclusions, rigorously verifying edge conditions and asymptotic behavior. | |
| {%- endset -%} | |
| {%- set inst_oracle -%} | |
| Reasoning Effort: Solo Exhaustive Theorem Proof (Level 9 — Oracle / AMax). | |
| Role & Persona: You are the Oracle operating in pure solo definitive authority. You produce verified, proof-grade, exhaustive engineering deliverables and mathematical certainty. | |
| Operational Directives: | |
| - Cognitive Pacing: Deepest continuous solo analytical runway. Leave absolutely nothing to chance or intuition. | |
| - Exhaustive Root Deconstruction: Decompose the problem into atomic constituents; verify every underlying assumption, lemma, and invariant. | |
| - Adversarial Self-Falsification: Systematically challenge every proposed step against worst-case inputs, stress thresholds, and degenerate edge states. | |
| - Definitive Synthesis: Deliver the complete, finalized solution with unmatched technical accuracy, explicit proofs, and total implementation completeness. | |
| {%- endset -%} | |
| {%- set inst_swarm -%} | |
| Reasoning Effort: 20-Agent Divergent Swarm (Specialized Swarm Mode). | |
| Role & Persona: You are the Einstein Divergent Swarm Coordinator. Your purpose is breakthrough problem solving, radical lateral thinking, and multi-perspective emergence. | |
| Operational Protocol — The 20-Perspective Swarm: | |
| - Cognitive Pacing: Broad divergent exploration across multiple cognitive modalities followed by structured convergence. Scale token depth to the magnitude of the challenge. | |
| - Phase 1 (First-Principles Disassembly): Strip the problem of conventional paradigms; isolate the bare informational core. | |
| - Phase 2 (Perspective Swarm Activation): Internally simulate an array of specialized virtual cognitive agents: | |
| 1. Analytical Logician: Formal validity, mathematical correctness, axiom purity. | |
| 2. Creative Maverick: Radical, non-traditional metaphors, lateral paradigms, disruptive angles. | |
| 3. Systems Engineer: Real-world feasibility, hardware limits, cache hierarchies, operational cost. | |
| 4. Adversarial Red-Teamer: Exploits, boundary breakages, failure states, stress tests. | |
| 5. Systems Dynamics Modeler: Feedback loops, second-order effects, equilibrium analysis. | |
| 6. Algorithmic Optimizer: Asymptotic bounds, latency, memory allocations. | |
| 7. Human Factors Critic: Developer ergonomics, interface simplicity, usability. | |
| - Phase 3 (Cross-Pollination & Synthesis): Force creative collisions between divergent concepts. Synthesize superior hybrid solutions that resolve tensions between speed, memory, and correctness. | |
| - Phase 4 (Convergence & Polish): Solidify the highest-conviction breakthrough into a master-grade deliverable. | |
| {%- endset -%} | |
| {%- set inst_deep_swarm -%} | |
| Reasoning Effort: Deep Research Council (Specialized Deep-Swarm Mode). | |
| Role & Persona: You are the Oracle Meta-Research Council. You simulate an exhaustive multi-expert research institute to produce verified, proof-grade, definitive results. | |
| Operational Protocol — The Deep Research Standard: | |
| - Protocol 1 (Problem Calibration): Calibrate complexity from 1 to 5; establish explicit domain boundaries and success criteria. | |
| - Protocol 2 (Virtual Expert Panel): Assemble 3 to 5 virtual specialist perspectives tailored specifically to the prompt (Domain Principal, Formal Methods Verification Critic, Systems Architect, Security/Compliance Lead, Final Synthesizer). | |
| - Protocol 3 (Adversarial Deliberation & Proof Trace): Have experts debate the problem, expose hidden assumptions, challenge lazy consensus, and trace proofs. | |
| - Protocol 4 (Multi-Candidate Evaluation Matrix): Formulate 2 to 3 candidate architectures. Score each on Correctness, Completeness, Efficiency, and Robustness (1-5 scale). Document the winning trade-off. | |
| - Protocol 5 (Master Deliverable Synthesis): Present the definitive final result with unmatched thoroughness, clear structure, and complete implementation. | |
| {%- endset -%} | |
| {%- macro render_content(content) -%} | |
| {%- if content is string -%} | |
| {{- content -}} | |
| {%- elif content is iterable and content is not mapping -%} | |
| {%- for item in content -%} | |
| {%- if 'image' in item or 'image_url' in item or item.type == 'image' -%} | |
| {{- '<|deepseek_image|>' -}} | |
| {%- elif 'text' in item -%} | |
| {{- item.text -}} | |
| {%- else -%} | |
| {{- item | string -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- elif content is none or content is undefined -%} | |
| {{- '' -}} | |
| {%- else -%} | |
| {{- content | string -}} | |
| {%- endif -%} | |
| {%- endmacro -%} | |
| {%- if not messages -%} | |
| {{- raise_exception('No messages provided.') -}} | |
| {%- endif -%} | |
| {%- set bos = bos_token | default('<|begin▁of▁sentence|>') -%} | |
| {%- set eos = eos_token | default('<|end▁of▁sentence|>') -%} | |
| {%- set store = namespace( | |
| messages=[], | |
| raw_mode='', | |
| explicit_thinking=enable_thinking, | |
| last_user_idx=-1 | |
| ) -%} | |
| {%- for msg in messages -%} | |
| {%- set txt = render_content(msg.content) | trim -%} | |
| {%- set clean_txt = txt -%} | |
| {%- set detected_mode = '' -%} | |
| {%- if '{REASON:' in clean_txt -%} | |
| {%- set parts = clean_txt.split('{REASON:') -%} | |
| {%- set tag_inner = parts[1].split('}')[0] | lower | trim -%} | |
| {%- set detected_mode = tag_inner -%} | |
| {%- set full_tag = '{REASON:' ~ parts[1].split('}')[0] ~ '}' -%} | |
| {%- set clean_txt = clean_txt.replace(full_tag, '') | trim -%} | |
| {%- elif '[MODE:' in clean_txt -%} | |
| {%- set parts = clean_txt.split('[MODE:') -%} | |
| {%- set tag_inner = parts[1].split(']')[0] | lower | trim -%} | |
| {%- set detected_mode = tag_inner -%} | |
| {%- set full_tag = '[MODE:' ~ parts[1].split(']')[0] ~ ']' -%} | |
| {%- set clean_txt = clean_txt.replace(full_tag, '') | trim -%} | |
| {%- endif -%} | |
| {%- if detected_mode -%} | |
| {%- set store.raw_mode = detected_mode -%} | |
| {%- endif -%} | |
| {%- set store.messages = store.messages + [{'role': msg.role, 'content': clean_txt, 'reasoning_content': msg.reasoning_content | default(''), 'tool_calls': msg.tool_calls | default([])}] -%} | |
| {%- endfor -%} | |
| {%- for msg in store.messages -%} | |
| {%- if msg.role == 'user' or msg.role == 'developer' -%} | |
| {%- set store.last_user_idx = loop.index0 -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- set target_mode = store.raw_mode -%} | |
| {%- if not target_mode and thinking_level is defined -%} | |
| {%- set target_mode = thinking_level | string | lower | trim -%} | |
| {%- elif not target_mode and reasoning_effort is defined -%} | |
| {%- set target_mode = reasoning_effort | string | lower | trim -%} | |
| {%- elif not target_mode and mode is defined -%} | |
| {%- set target_mode = mode | string | lower | trim -%} | |
| {%- endif -%} | |
| {%- if not target_mode -%} | |
| {%- set target_mode = '7' -%} | |
| {%- endif -%} | |
| {%- set direct_instruct = false -%} | |
| {%- if target_mode.startswith('i') and target_mode | length > 1 -%} | |
| {%- set direct_instruct = true -%} | |
| {%- set target_mode = target_mode[1:] -%} | |
| {%- endif -%} | |
| {%- if target_mode in ['0', 'mortal', 'disabled', 'none', 'off', 'zero', 'direct', 'chat'] -%} | |
| {%- set current_thinking = false -%} | |
| {%- set reasoning_instructions = '' -%} | |
| {%- elif target_mode in ['1', 'hermes', 'ulow', 'ultra-low', 'micro', 'minimal'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_hermes -%} | |
| {%- elif target_mode in ['2', 'apollo', 'low', 'compact', 'fast'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_apollo -%} | |
| {%- elif target_mode in ['3', 'artemis', 'lmed', 'low-medium', 'targeted'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_artemis -%} | |
| {%- elif target_mode in ['4', 'athena', 'medium', 'med', 'balanced'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_athena -%} | |
| {%- elif target_mode in ['5', 'prometheus', 'mhigh', 'medium-high', 'architect'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_prometheus -%} | |
| {%- elif target_mode in ['6', 'solstice', 'high', 'deep', 'thorough'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_solstice -%} | |
| {%- elif target_mode in ['7', 'hyperion', 'xhigh', 'extreme-high', 'rigorous', 'default'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_hyperion -%} | |
| {%- elif target_mode in ['8', 'einstein', 'uhigh', 'ultra-high', 'solo-einstein'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_einstein -%} | |
| {%- elif target_mode in ['9', 'oracle', 'amax', 'absolute-max', 'solo-oracle', 'proof'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_oracle -%} | |
| {%- elif target_mode in ['swarm', 'einstein-swarm', '20-swarm', 'uhigh-swarm'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_swarm -%} | |
| {%- elif target_mode in ['deep-swarm', 'oracle-swarm', 'council', 'amax-swarm', 'deep-research'] -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_deep_swarm -%} | |
| {%- else -%} | |
| {%- set current_thinking = not direct_instruct -%} | |
| {%- set reasoning_instructions = inst_hyperion -%} | |
| {%- endif -%} | |
| {%- if store.explicit_thinking is defined and store.explicit_thinking is not none -%} | |
| {%- set current_thinking = store.explicit_thinking -%} | |
| {%- endif -%} | |
| {{- bos -}} | |
| {%- if reasoning_instructions -%} | |
| {{- reasoning_instructions + '\n\n' -}} | |
| {%- endif -%} | |
| {%- if tools and tools is iterable and tools is not mapping -%} | |
| {{ "## Tools\n\nYou have access to a set of tools to help answer the user's question. You can invoke tools by writing a \"<|DSML|tool_calls>\" block like the following:\n\n<|DSML|tool_calls>\n<|DSML|invoke name=\"$TOOL_NAME\">\n<|DSML|parameter name=\"$PARAMETER_NAME\" string=\"true|false\">$PARAMETER_VALUE</|DSML|parameter>\n...\n</|DSML|invoke>\n<|DSML|invoke name=\"$TOOL_NAME2\">\n...\n</|DSML|invoke>\n</|DSML|tool_calls>\n\nString parameters should be specified as is and set `string=\"true\"`. For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set `string=\"false\"`.\n\n### Available Tool Schemas\n\n" }} | |
| {%- for tool in tools -%} | |
| {%- if tool.function is defined -%} | |
| {{- tool.function | tojson -}} | |
| {%- else -%} | |
| {{- tool | tojson -}} | |
| {%- endif -%} | |
| {%- if not loop.last -%}{{- '\n' -}}{%- endif -%} | |
| {%- endfor -%} | |
| {{ "\n\nYou MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.\n\n" }} | |
| {%- endif -%} | |
| {%- set ns = namespace(system_content='', has_system=false, prev_role='') -%} | |
| {%- for msg in store.messages -%} | |
| {%- if msg.role == 'system' -%} | |
| {%- if not ns.has_system -%} | |
| {%- set ns.system_content = msg.content -%} | |
| {%- set ns.has_system = true -%} | |
| {%- else -%} | |
| {%- set ns.system_content = ns.system_content + '\n\n' + msg.content -%} | |
| {%- endif -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- if ns.has_system and ns.system_content -%} | |
| {{- ns.system_content -}} | |
| {%- endif -%} | |
| {%- for msg in store.messages -%} | |
| {%- set idx = loop.index0 -%} | |
| {%- if msg.role == 'user' or msg.role == 'developer' -%} | |
| {{- '<|User|>' + msg.content -}} | |
| {%- set ns.prev_role = 'user' -%} | |
| {%- elif msg.role == 'assistant' -%} | |
| {%- set r_content = msg.reasoning_content | trim -%} | |
| {%- set m_content = msg.content | trim -%} | |
| {%- if r_content and (preserve_thinking is undefined or preserve_thinking or idx > store.last_user_idx) -%} | |
| {{- '<|Assistant|><think>' + r_content + '</think>' + m_content -}} | |
| {%- else -%} | |
| {{- '<|Assistant|>' + m_content -}} | |
| {%- endif -%} | |
| {%- if msg.tool_calls and msg.tool_calls is iterable and msg.tool_calls is not mapping -%} | |
| {{- '\n\n<|DSML|tool_calls>' -}} | |
| {%- for tc in msg.tool_calls -%} | |
| {%- set tc_name = tc.function.name if tc.function is defined else tc.name -%} | |
| {%- set tc_args = tc.function.arguments if tc.function is defined else tc.arguments -%} | |
| {{- '\n<|DSML|invoke name="' + tc_name + '">' -}} | |
| {%- if tc_args is mapping -%} | |
| {%- for p_name, p_val in tc_args.items() -%} | |
| {%- if p_val is string -%} | |
| {{- '\n<|DSML|parameter name="' + p_name + '" string="true">' + p_val + '</|DSML|parameter>' -}} | |
| {%- else -%} | |
| {{- '\n<|DSML|parameter name="' + p_name + '" string="false">' + (p_val | tojson) + '</|DSML|parameter>' -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- elif tc_args is string -%} | |
| {{- '\n' + tc_args -}} | |
| {%- endif -%} | |
| {{- '\n</|DSML|invoke>' -}} | |
| {%- endfor -%} | |
| {{- '\n</|DSML|tool_calls>' -}} | |
| {%- endif -%} | |
| {{- eos -}} | |
| {%- set ns.prev_role = 'assistant' -%} | |
| {%- elif msg.role == 'tool' -%} | |
| {%- if ns.prev_role != 'user' -%} | |
| {{- '<|User|>' -}} | |
| {%- endif -%} | |
| {{- '<tool_result>' + msg.content + '</tool_result>' -}} | |
| {%- set ns.prev_role = 'user' -%} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- if add_generation_prompt -%} | |
| {%- if current_thinking -%} | |
| {{- '<|Assistant|><think>\n' -}} | |
| {%- else -%} | |
| {{- '<|Assistant|></think>' -}} | |
| {%- endif -%} | |
| {%- endif -%} | |