初始化项目,由ModelHub XC社区提供模型
Model: kumanomidoh/qwen3-4b-yaml-sft-with-template Source: Original Platform
This commit is contained in:
161
chat_template.jinja
Normal file
161
chat_template.jinja
Normal file
@@ -0,0 +1,161 @@
|
||||
{%- if messages[0].role == 'system' %}
|
||||
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
|
||||
{%- endif %}
|
||||
{%- for message in messages %}
|
||||
{%- if message.role == "user" or (message.role == "system" and not loop.first) %}
|
||||
{%- set content = message.content if message.content is string else '' %}
|
||||
{%- set suffix = '' %}
|
||||
{%- set fl = content.split('\n')[0].lower() %}
|
||||
{%- set formats = ['toml', 'xml', 'yaml', 'json', 'csv'] %}
|
||||
{%- set ns = namespace(target='') %}
|
||||
{%- for f in formats %}
|
||||
{%- if f in fl %}
|
||||
{%- if ns.target == '' or fl.rfind(f) > fl.rfind(ns.target) %}
|
||||
{%- set ns.target = f %}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{%- if ns.target == 'toml' %}
|
||||
{%- set suffix = '\n\nOutput ONLY raw TOML. Use [table] for nested objects and [[array]] for arrays. Do not use inline tables.' %}
|
||||
{%- elif ns.target == 'xml' %}
|
||||
{%- set suffix = '\n\nOutput ONLY raw XML. Escape & as &, < as <. No XML declaration. Follow these strict rules:
|
||||
|
||||
1. ROOT ELEMENT DETERMINATION:
|
||||
- For JSON input: Use the FIRST KEY from the input object as root name
|
||||
- For data generation queries: Infer based on expected path structure. If paths start with \'assessment_id.*\', root must be \'<assessment_id>\', not the entity name
|
||||
- All XML content must be wrapped within this single root element
|
||||
|
||||
2. FIELD ORDER & HIERARCHY:
|
||||
- When generating data, follow required path structure (e.g., \'assessment_id.assessment_id\' requires:
|
||||
<assessment_id>
|
||||
<assessment_id>UUID</assessment_id>
|
||||
...other nested fields...
|
||||
</assessment_id>)
|
||||
- Maintain exact field order required for path consistency
|
||||
- Arrays must be nested within their parent elements with _item suffix
|
||||
|
||||
3. XML SYNTAX REQUIREMENTS:
|
||||
- Must be parseable XML with ONE root element
|
||||
- Properly escape special characters
|
||||
- Match expected schema\'s path structure exactly
|
||||
- All opening tags must have closing tags
|
||||
|
||||
4. DATA TYPE HANDLING:
|
||||
- Maintain ISO 8601 timestamps (YYYY-MM-DDTHH:MM:SS.ssssss)
|
||||
- Preserve UUID formats (e.g., 5ceff241-2713-4bf4-a7b2-a4b795b4a1a9)
|
||||
- Keep DOI identifiers intact (e.g., 10.8889/HDtI)
|
||||
|
||||
5. SPECIFIC STRUCTURE REQUIREMENTS:
|
||||
- Academic assessments must have:
|
||||
assessment_id.assessment_id
|
||||
assessment_id.student_id
|
||||
assessment_id.course_id
|
||||
assessment_id.type
|
||||
assessment_id.date
|
||||
- Arrays must be properly nested (no standalone array containers)
|
||||
- Academic structures must maintain:
|
||||
- Assignments with name/due/weight
|
||||
- Textbooks with title/author/isbn
|
||||
- Authors arrays with name/affiliation/email
|
||||
|
||||
6. VALIDATION CHECKS:
|
||||
- Verify path format matches exactly:
|
||||
\'{root_element}.{field_name}\'
|
||||
\'{root_element}.{array_field}[index].{subfield}\'
|
||||
- Ensure all expected fields are present in correct hierarchy
|
||||
- Confirm single root element contains all content
|
||||
- Check proper array element formatting with _item suffix' %}
|
||||
{%- elif ns.target == 'yaml' %}
|
||||
{%- set suffix = '\n\nConvert the input data format (XML, CSV, or JSON) to valid, semantically equivalent YAML following these rules:
|
||||
|
||||
1. SYNTAX & FORMATTING
|
||||
- Use 2-space indentation levels for nesting
|
||||
- Represent lists with hyphens (-) followed by single space
|
||||
- Quote string values containing special characters (e.g., "-120", "0-18km")
|
||||
- Maintain consistent spacing around colons (key: value)
|
||||
- NO trailing spaces or markdown formatting
|
||||
- Ensure valid YAML syntax (test with parser before output)
|
||||
|
||||
2. STRUCTURE PRESERVATION
|
||||
- XML Conversion:
|
||||
- Map XML tags to nested keys
|
||||
- Convert multiple elements with same tag to list of maps DIRECTLY UNDER PARENT KEY, WITHOUT WRAPPING IN TAG NAME:
|
||||
✓ Correct: <planets><planet>Mercury</planet></planets> → planets: ["Mercury"]
|
||||
✓ Correct: <star_systems><star_system><name>Alpha</name></star_system> → star_systems: [ { name: "Alpha" } ]
|
||||
✗ Incorrect: star_systems: [ { star_system: { name: "Alpha" } } ]
|
||||
- Preserve element hierarchy: parent-child relationships must create direct key-value pairs
|
||||
- Convert XML attributes to keys with \'@\' prefix (e.g., <moon name="Phobos"/> → { "@name": "Phobos" })
|
||||
- CSV Conversion:
|
||||
- Map dot-notation headers to nested structures (system.star_name → system: { star_name: ... })
|
||||
- Create object arrays for underscore-prefixed columns (moons_diameter_km → moons: [ { diameter_km: ... } ])
|
||||
- Maintain field relationships in grouped columns (moons_diameter_km and moons_has_rings → moons: [ { diameter_km, has_rings } ])
|
||||
- Preserve row positions when splitting multi-value fields (Phobos;Deimos and 12;6 → first moon: name=Phobos, diameter=12)
|
||||
- JSON Conversion:
|
||||
- Directly map objects to YAML maps
|
||||
- Maintain array order and indexing
|
||||
- Preserve null values from source
|
||||
|
||||
3. SPECIAL CASE HANDLING
|
||||
- Empty elements: Represent as null (undefined) or empty string (explicitly empty) based on source
|
||||
- CSV multi-value fields:
|
||||
- Convert semicolon-separated values to arrays (Oxygen;Nitrogen → ["Oxygen", "Nitrogen"])
|
||||
- Align split values by position for grouped fields (moons field1;field2 → moons[*].field)
|
||||
- Numeric values: Keep unquoted, preserve type (int, float) from source
|
||||
- Boolean values: Convert to lowercase YAML booleans (true/false)
|
||||
- String numbers: Quote values starting with "-" or containing "-...km" patterns
|
||||
|
||||
4. PATH PRESERVATION & VALIDATION
|
||||
- Ensure all source paths exist in output using dot-notation:
|
||||
- XML: galaxy.clusters[0].name, galaxy.clusters[0].stars[0].type
|
||||
- CSV: atmosphere.composition.*, surface.topography, moons.*.moon_name
|
||||
- Confirm nested structures match source depth exactly
|
||||
- Validate list items maintain field relationships (moons.*.has_rings)
|
||||
- Verify key names match source paths including array element properties
|
||||
- Test YAML validity with parser before output
|
||||
|
||||
5. XML SPECIFIC NESTING RULES
|
||||
- For elements containing mixed content or simple text:
|
||||
<planet><![CDATA[Earth;Mars]]></planet> → planet: "Earth;Mars"
|
||||
- For elements with child elements:
|
||||
<planet>
|
||||
<name>Proxima b</name>
|
||||
<radius>0.12</radius>
|
||||
</planet> → planet:
|
||||
name: Proxima b
|
||||
radius: 0.12
|
||||
- For repeated elements (critical rule):
|
||||
<star_systems>
|
||||
<star_system> <!-- THIS TAG NAME MUST BE ELIDED IN YAML -->
|
||||
<name>Alpha Centauri</name>
|
||||
<planets>
|
||||
<planet> <!-- ELEMENT TO ARRAY CONVERSION -->
|
||||
<name>Proxima b</name>
|
||||
</planet>
|
||||
</planets>
|
||||
</star_system>
|
||||
</star_systems> → star_systems:
|
||||
- name: Alpha Centauri
|
||||
planets:
|
||||
- name: Proxima b
|
||||
|
||||
6. CSV SPECIFIC MAPPINGS
|
||||
- Top-level columns (no dot/underscore prefix) go at root level (planet_name: ...)
|
||||
- Convert dot notation headers to nested maps (system.star_name → system: { star_name: ... })
|
||||
- Map underscore-prefixed columns to object arrays:
|
||||
- moons_diameter_km → moons: [ { diameter_km: ... } ]
|
||||
- moons_has_rings → moons: [ { has_rings: ... } ]
|
||||
- Preserve field relationships in grouped columns:
|
||||
- moons, moons_diameter_km → moons: [ { moon_name, diameter_km } ]
|
||||
- moons_diameter_km, moons_has_rings → moons: [ { diameter_km, has_rings } ]
|
||||
|
||||
OUTPUT ONLY THE RAW YAML WITH NO EXPLANATIONS. MAINTAIN 100% STRUCTURAL PARITY WITH SOURCE DATA.' %}
|
||||
{%- endif %}
|
||||
{{- '<|im_start|>' + message.role + '\n' + content + suffix + '<|im_end|>' + '\n' }}
|
||||
{%- elif message.role == "assistant" %}
|
||||
{%- set content = message.content if message.content is string else '' %}
|
||||
{{- '<|im_start|>assistant\n' + content + '<|im_end|>\n' }}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{%- if add_generation_prompt %}
|
||||
{{- '<|im_start|>assistant\n' }}
|
||||
{%- endif %}
|
||||
Reference in New Issue
Block a user