{%- if tools %} {%- if messages[0]['role'] == 'system' %} {{-'<_system>'+messages[0]['content'] }} {%- else %} {{- '<_system>'+'你是中国电信星辰语义大模型,英文名是TeleChat,你是由中电信人工智能科技有限公司和中国电信人工智能研究院(TeleAI)研发的人工智能助手。' }} {%- endif %} {{- '\n\n# 可用工具\n你可以调用标签中包含的一个或多个工具来辅助你回答问题,以下是可用工具详情:\n\n' }} {%- for tool in tools %} {{- tool | tojson }} {{-'\n'}} {%- endfor %} {{- '\n\n# 调用方法\n你需要遵循工具的要求,使用json格式返回工具名称及参数,并用包含。下方是一个调用模板:\n\n{\"name\": , \"arguments\": }\n\n\n' }} {%- else %} {%- if messages[0]['role'] == 'system' %} {{- '<_system>' + messages[0]['content'] + '\n' }} {%- else %} {{- '<_system>'+'你是中国电信星辰语义大模型,英文名是TeleChat,你是由中电信人工智能科技有限公司和中国电信人工智能研究院(TeleAI)研发的人工智能助手。\n' }} {%- endif %} {%- endif %} {%- for message in messages %} {%- if (message.role == 'user') %} {{- '<_user>' + message.content }} {%- elif message.role == 'bot' or message.role == 'assistant' %} {{- '<_bot>' }} {%- if message.content %} {{- message.content }} {%- endif %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {%- if loop.index0 == 0 %} {{-''}} {%- else %} {{-'\n'}} {%- endif %} {{- '\n{"name": "' }}{{ tool_call.name }} {{- '", "arguments": ' }} {{- tool_call.arguments | tojson }} {{- '}\n' }} {%- endfor %} {{- '<_end>\n' }} {%- elif message.role == 'tool' %} {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != 'tool') %} {{- '<_user>'+'\n' }} {%- else %} {{- '\n\n' }} {%- endif %} {{- message.content }} {{- '\n' }} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<_bot>' }} {%- endif %}