Is there a way to create custom chat templates? #14321
Replies: 7 comments 12 replies
-
The best documentation is the official Then there is Hugging Face's Chat Template Writing Guide which will give you some very useful info on Chat Templates in particular. Also, I'd like to do a little self-plug and point out that the Chat Template Editor will make writing and testing Chat Templates much easier. :) Hopefully this will get you a long way, though beware that although this will enable you to fix the many, many crap cut-n-paste chat templates (it seems many model creators don't even bother testing them) out there, it most likely won't fix poor model instruction adherence (unless the problem is that the chat template is just plain wrong, and not what the model was trained on, which is not uncommon). Edit: Oh, and it's worth knowing that minja (what |
Beta Was this translation helpful? Give feedback.
-
Hi @CISC, just a question in between: maybe I didn't search carefully enough but I can't find an explanation what are the |
Beta Was this translation helpful? Give feedback.
-
They are just a way of separating the different parts of the conversation, they are arbitrarily chosen at training time, but it's really important that you use the same ones, and in the same pattern as at training. You can usually find them in the |
Beta Was this translation helpful? Give feedback.
-
Hi @CISC: now i need some real support :-) To mention in advance: I'm still using the "aya-expanse-8b" model (aya IMO the greatest LLM regarding e.g. the German language) {% if messages %}
{% for message in messages %}
{% if 'role' in message %}
{% set role=message['role'] %}
{% if 'tool_calls' in message %}
{{ FOO }}
{% endif %}
{% if 'content' in message %}
{% set content=message['content'] %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %} If you maybe could see I wanted to achieve to put out just 'FOO' if a tool_call was recognized. But it seems to be ignorred and I get the following instead (just two examples): a nonsense one: {'body': {'choices': [{'finish_reason': 'stop',
'index': 0,
'message': {'content': 'success,',
'role': 'assistant'}}],
'created': 1750608357,
'id': 'chatcmpl-FZi9OYRaqVDb30JyfcSyDw69JV7fJMrc',
'model': 'aya-expanse-8b-q8_0',
'object': 'chat.completion',
'system_fingerprint': 'b5736-af3373f1',
'timings': {'predicted_ms': 522.461,
'predicted_n': 16,
'predicted_per_second': 30.624295401953447,
'predicted_per_token_ms': 32.6538125,
'prompt_ms': 50.206,
'prompt_n': 1,
'prompt_per_second': 19.9179380950484,
'prompt_per_token_ms': 50.206},
'usage': {'completion_tokens': 16,
'prompt_tokens': 2,
'total_tokens': 18}},
'header': [{'Connection': 'close'},
{'Content-Type': 'application/json; charset=utf-8'},
{'Server': 'llama.cpp'},
{'Content-Length': '562'},
{'Access-Control-Allow-Origin': ''}]} a more nonsense (halucinating) one: {'body': {'choices': [{'finish_reason': 'stop',
'index': 0,
'message': {'content': '<h1>Google Maps Platform '
'Pricing</h1><p>Google Maps '
'Platform offers a range of APIs '
'and services for developers to '
'integrate maps, location, and '
'geospatial data into their '
'applications. The pricing '
'structure is based on usage, '
'with different tiers for '
'different levels of '
'usage.</p><h2>Pricing '
'Tiers</h2><ul><li><strong>Free '
'Tier:</strong> This is suitable '
'for developers and startups '
'with limited usage. It includes '
'a certain number of API calls, '
'data usage, and other '
'credits.</li><li><strong>Standard '
'Tier:</strong> For moderate '
'usage, this tier offers higher '
'limits than the free tier and '
'is suitable for growing '
'businesses.</li><li><strong>Premium '
'Tier:</strong> This is for '
'high-volume usage and large '
'enterprises, offering the '
'highest limits and priority '
'support.</li></ul><h2>API '
'Pricing</h2><p>The pricing for '
'individual APIs '
'varies:</p><ul><li><strong>Maps '
'JavaScript API:</strong> A '
'standard charge per API '
'call.</li><li><strong>Directions '
'API:</strong> Charged per '
'request based on the distance '
'and mode of '
'travel.</li><li><strong>Distance '
'Matrix API:</strong> Cost per '
'request, depending on the '
'number of origins and '
'destinations.</li><li><strong>Geocoding '
'API:</strong> Charged per '
'request, with higher rates for '
'batch '
'requests.</li><li><strong>Places '
'API:</strong> Pricing based on '
'the number of requests and the '
'level of detail '
'returned.</li></ul><h2>Data '
'Usage and Other '
'Charges</h2><p>There may be '
'additional charges for data '
'usage, such as for large data '
'sets or specific data types. '
'Google also offers credits and '
'discounts for specific use '
'cases and regions.</p><p>For '
'the most accurate and '
'up-to-date pricing information, '
'please visit the <a '
"href='https://cloud.google.com/maps-platform/pricing'>Google "
'Maps Platform Pricing '
'Page</a>.</p>',
'role': 'assistant'}}],
'created': 1750608595,
'id': 'chatcmpl-ooBhnGMBNY2QRuWVZt4JfnVlr3cLoNsV',
'model': 'aya-expanse-8b-q8_0',
'object': 'chat.completion',
'system_fingerprint': 'b5736-af3373f1',
'timings': {'predicted_ms': 8561.868,
'predicted_n': 414,
'predicted_per_second': 48.35393397795902,
'predicted_per_token_ms': 20.680840579710146,
'prompt_ms': 48.423,
'prompt_n': 1,
'prompt_per_second': 20.65134336988621,
'prompt_per_token_ms': 48.423},
'usage': {'completion_tokens': 414,
'prompt_tokens': 2,
'total_tokens': 416}},
'header': [{'Connection': 'close'},
{'Content-Type': 'application/json; charset=utf-8'},
{'Server': 'llama.cpp'},
{'Content-Length': '2326'},
{'Access-Control-Allow-Origin': ''}]} What am I doing wrong to drive the model to create anything else but giving me what I expect? |
Beta Was this translation helpful? Give feedback.
-
So, if you want to output a string you have to quote it, to output {{ 'FOO' }} Also, remember that all whitespace outside of |
Beta Was this translation helpful? Give feedback.
-
so this would be a tool call i sent out to trigger currently on model level to drop out "FOO" if it woul be recognized..... if this would work i would continue to fine tune the template for the real outrput.... that's at least what i'm expecting... |
Beta Was this translation helpful? Give feedback.
-
Since you mentioned |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi at all, as the subject already tells I'm asking myself if there's a way to create custom jinja templates for LLMs?
I've crawled the web for tutorials but didn't really find anything usable and assembling one by picking parts of existing templates leads me to an error telling me about the templates delivered by llama.cpp.
Why do i want to try to build an own template?
Because no matter if a system prompt is available telling to avoid it, I always get additional information at doing function calls e.g. the full json structure of the called function order, or some halucinating stuff next to the essential response. This sucks especially if I'm using "stream: True" because especially in this case it's difficult to get rid of the additional information....
Maybe someone will have an advice....(?)
Thanks in advance :-)
Beta Was this translation helpful? Give feedback.
All reactions