Text Generation
Transformers
Safetensors
PyTorch
English
llama
nvidia
unsloth
llama-3
conversational
text-generation-inference
File size: 2,372 Bytes
3456fa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{%- if tools %}
    {{- '<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n' -}}
    {%- if messages[0].role == 'system' -%}
        {{- messages[0].content + '\n\n' -}}
    {%- endif -%}
    {{- '<AVAILABLE_TOOLS>[' -}}
    {%- for tool in tools -%}
        {{- (tool.function if tool.function is defined else tool) | tojson -}}{{- ', ' if not loop.last else '' -}}
    {%- endfor -%}
    {{- ']</AVAILABLE_TOOLS>' -}}{{- '<|eot_id|>' -}}
{%- else %}
    {%- if messages[0].role == 'system' %}
        {{- '<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n' + messages[0].content + '<|eot_id|>' -}}
    {%- endif %}
{%- endif %}
{%- for message in messages -%}
    {%- if (message.role == 'user') -%}
        {{- '<|start_header_id|>user<|end_header_id|>\n\n' + message.content + '<|eot_id|>' -}}
    {%- elif message.role == 'assistant' -%}
        {%- set content = message.content -%}
        {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' + content -}}
        {%- if message.tool_calls -%}
            {{- '<TOOLCALL>[' -}}
            {%- for tool_call in message.tool_calls -%}
                {%- if tool_call.function -%}
                    {%- set tool_call = tool_call.function -%}
                {%- endif -%}
                {{- '{"name": "' }}{{- tool_call.name }}{{- '", "arguments": ' -}}
                {%- if tool_call.arguments is string -%}
                    {{- tool_call.arguments -}}
                {%- else -%}
                    {{- tool_call.arguments | tojson -}}
                {%- endif -%}
                {{- ', ' if not loop.last else '' -}}
            {%- endfor -%}
            {{- ']</TOOLCALL>' -}}
        {%- endif %}
        {{- '<|eot_id|>' -}}
    {%- elif message.role == 'tool' -%}
        {%- if loop.first or (messages[loop.index0 - 1].role != 'tool') -%}
            {{- '<|start_header_id|>user<|end_header_id|>\n\n' }}{{- '<TOOL_RESPONSE>[' -}}
        {%- endif -%}
        {{- message.content -}}{{- ', ' if not loop.last and (messages[loop.index0 + 1].role == 'tool') else '' -}}
        {%- if loop.last or (messages[loop.index0 + 1].role != 'tool') -%}
            {{- ']</TOOL_RESPONSE>' -}}{{- '<|eot_id|>' -}}
        {%- endif %}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
{%- endif %}