char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
6137c325a
char/aliceai-t5-moe
1{%- set tools_system_message_prefix = 'You are a helpful assistant with access to the following tools. You may call one or more tools to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>' %} 2{%- set tools_system_message_suffix = '\n</tools>\n\nFor each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\" name \ ": <function-name>, \" arguments \ ": <args-json-object>}\n</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.' %} 3{%- set documents_system_message_prefix = 'You are a helpful assistant with access to the following documents. You may use one or more documents to assist with the user query.\n\nYou are given a list of documents within <documents></documents> XML tags:\n<documents>' %} 4{%- set documents_system_message_suffix = '\n</documents>\n\nWrite the response to the user\' s input by strictly aligning with the facts in the provided documents . If the information needed to answer the question is not available in the documents , inform the user that the question cannot be answered based on the available data . ' %} 5{%- set g4_default_system_message = ' You are a helpful assistant . Please ensure responses are professional , accurate , and safe . ' %} 6{%- if available_tools is defined and available_tools %} 7{%- set tools = available_tools %} 8{%- endif %} 9{%- set ns = namespace(tools_system_message=tools_system_message_prefix, 10documents_system_message=documents_system_message_prefix, 11default_system_message=g4_default_system_message, 12system_message='' 13) %} 14{%- if tools %} 15{%- for tool in tools %} 16{%- set ns.tools_system_message = ns.tools_system_message + ' \ n ' + (tool | tojson) %} 17{%- endfor %} 18{%- set ns.tools_system_message = ns.tools_system_message + tools_system_message_suffix %} 19{%- else %} 20{%- set ns.tools_system_message = '' %} 21{%- endif %} 22{%- if documents %} 23{%- for document in documents %} 24{%- set ns.documents_system_message = ns.documents_system_message + ' \ n ' + (document | tojson) %} 25{%- endfor %} 26{%- set ns.documents_system_message = ns.documents_system_message + documents_system_message_suffix %} 27{%- else %} 28{%- set ns.documents_system_message = '' %} 29{%- endif %} 30{%- if messages[0].role == ' system ' %} 31{%- if messages[0].content is string %} 32{%- set ns.system_message = messages[0].content %} 33{%- elif messages[0].content is iterable %} 34{%- for entry in messages[0].content %} 35{%- if entry.type== ' text ' %} 36{%- if ns.system_message != '' %} 37{%- set ns.system_message = ns.system_message + ' \ n ' %} 38{%- endif %} 39{%- set ns.system_message = ns.system_message + entry.text %} 40{%- endif %} 41{%- endfor %} 42{%- endif %} 43{%- if tools and documents %} 44{%- set ns.system_message = ns.system_message + ' \ n \ n ' + ns.tools_system_message + ' \ n \ n ' + ns.documents_system_message %} 45{%- elif tools %} 46{%- set ns.system_message = ns.system_message + ' \ n \ n ' + ns.tools_system_message %} 47{%- elif documents %} 48{%- set ns.system_message = ns.system_message + ' \ n \ n ' + ns.documents_system_message %} 49{%- endif %} 50{%- else %} 51{%- if tools and documents %} 52{%- set ns.system_message = ns.tools_system_message + ' \ n \ n ' + ns.documents_system_message %} 53{%- elif tools %} 54{%- set ns.system_message = ns.tools_system_message %} 55{%- elif documents %} 56{%- set ns.system_message = ns.documents_system_message %} 57{%- endif %} 58{%- endif %} 59{%- if ns.system_message %} 60{{- ' <| start_of_role |> system <| end_of_role |> ' + ns.system_message + ' <| end_of_text |>\ n ' }} 61{%- else %} 62{{- ' <| start_of_role |> system <| end_of_role |> ' + ns.default_system_message + ' <| end_of_text |>\ n ' }} 63{%- endif %} 64{%- for message in messages %} 65{%- set content = namespace(val='') %} 66{%- if message.content is string %} 67{%- set content.val = message.content %} 68{%- else %} 69{%- if message.content is iterable %} 70{%- for entry in message.content %} 71{%- if entry.type== ' text ' %} 72{%- if content.val != '' %} 73{%- set content.val = content.val + ' \ n ' %} 74{%- endif %} 75{%- set content.val = content.val + entry.text %} 76{%- endif %} 77{%- endfor %} 78{%- endif %} 79{%- endif %} 80{%- if (message.role == ' user ') or (message.role == ' system ' and not loop.first) %} 81{{- ' <| start_of_role |> ' + message.role + ' <| end_of_role |> ' + content.val + ' <| end_of_text |>\ n ' }} 82{%- elif message.role == ' assistant ' %} 83{{- ' <| start_of_role |> ' + message.role + ' <| end_of_role |> ' + content.val }} 84{%- if message.tool_calls %} 85{%- for tool_call in message.tool_calls %} 86{%- if (loop.first and content.val) or (not loop.first) %} 87{{- ' \ n ' }} 88{%- endif %} 89{%- if tool_call.function %} 90{%- set tool_call = tool_call.function %} 91{%- endif %} 92{{- ' < tool_call >\ n{ "name" : "' }} 93{{ - tool_call . name }} 94{{ - '" , "arguments" : ' }} 95{%- if tool_call.arguments is string %} 96{{- tool_call.arguments }} 97{%- else %} 98{{- tool_call.arguments | tojson }} 99{%- endif %} 100{{- ' } \ n </ tool_call > ' }} 101{%- endfor %} 102{%- endif %} 103{{- ' <| end_of_text |>\ n ' }} 104{%- elif message.role == ' tool ' %} 105{%- if loop.first or (messages[loop.index0 - 1].role != ' tool ') %} 106{{- ' <| start_of_role |> user <| end_of_role |> ' }} 107{%- endif %} 108{{- ' \ n < tool_response >\ n ' }} 109{{- content.val }} 110{{- ' \ n </ tool_response > ' }} 111{%- if loop.last or (messages[loop.index0 + 1].role != ' tool ') %} 112{{- ' <| end_of_text |>\ n ' }} 113{%- endif %} 114{%- endif %} 115{%- endfor %} 116{%- if add_generation_prompt %} 117{{- ' <| start_of_role |> assistant <| end_of_role |> ' }} 118{% - endif %}