gui-odyssey-1k / artifacts /acp_vlora_v7.jinja
ckg's picture
Upload artifacts/acp_vlora_v7.jinja with huggingface_hub
357688a verified
{#- Le Chat Template for acp-vlora-v7 -- structured tool calls for a multimodal mobile device action taking neural network -#}
{#- CONSTS + VALIDATION -#}
{%- set EOS_STRING = '<|eot_id|>\n' -%}
{%- set FUNCTION_CALL_STRING = '!FUNCTIONCALL' -%}
{%- set IMAGE_PLACEHOLDER_STRING = '<image>' -%}
{% set expected_roles = ["instruction", "previous_actions", "screen_description"] %}
{% set roles_in_messages = messages | map(attribute='role') | list %}
{% for desired_role in expected_roles %}
{% if desired_role not in roles_in_messages %}
{% set error_msg = "Missing required role: " ~ desired_role + " in the input messages. The current input messages have roles: " ~ roles_in_messages %}
{{- raise_exception(error_msg) -}}
{%- endif -%}
{%- endfor -%}
{#- assert tools are present, this model calls functions -#}
{%- if custom_tools is defined -%}
{%- set tools = custom_tools -%}
{%- endif -%}
{%- if tools is not defined or tools is none -%}
{% set error_msg = "Missing 'tools' in request input -- please specify the set of tools the model can use." %}
{{- raise_exception(error_msg) -}}
{%- endif -%}
{% set image_ns = namespace(has_images=false) -%}
{%- for message in messages -%}
{%- if message['content'] is sequence and message['content'] is not string and message['content'] -%}
{%- for content in message['content'] -%}
{%- if content['type'] == 'image' -%}
{%- set image_ns.has_images = true -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- if not image_ns.has_images -%}
{% set error_msg = "No 'image' type present in the value of any message's 'content' field. This model is multimodal, therefore it can see. Please provide an image." %}
{{- raise_exception(error_msg) -}}
{%- endif -%}
{#- STATIC SYSTEM PROMPT -#}
{{- bos_token -}}
{{- "<|start_header_id|>system<|end_header_id|>" -}}
{{- "\n\n" -}}
{{- "Cutting Knowledge Date: December 2023" -}}
{{- "\n\n" -}}
{{- "# System" + "\n" -}}
{{- "You are a helpful assistant with tool calling capabilities that completes instructions given by a User on an Android device. Each instruction requires one or more steps in order to complete. At each step, you will recieve an input containing; the User's 'instruction' -- along with Your 'previous_actions', the currently 'active_application', and a 'screen_description' (consisting of pixel dimensions and a screenshot of the current screen). You are required to select and call one tool from the set of available tools, in order to complete the task defined by the User's instruction." -}}
{{- "\n\n" -}}
{{- "## Available actions" + "\n" -}}
{{- 'To call a function, please respond with JSON for a function call. Use the format ' + FUNCTION_CALL_STRING + '{"name": function name, "arguments": dictionary of argument name and its value}. Do not use variables. You have access to the following functions, defined here by their JSON schema:' }}
{{- "\n" }}
{%- for t in tools -%}
{#- the tools are specified through unindented json in the prompt #}
{{- t |tojson + "\n" -}}
{%- endfor -%}
{{- "\n" -}}
{{- "## Explanation of inputs" + "\n" + "The top edge of a screen has a y_coordinate value equal to 0. The y_coordinate of the bottom edge of the screen is equal to the specified screen_height. The left edge of the screen has an x_coordinate of 0 and the right edge is specified by screen_width. The screen_width and screen_height for the screenshot are specifed in pixels, inside of the screen_description." -}}
{# VARIABLE INPUTS TO FORMAT IN #}
{# OPTIONAL: include additional system instructions from first block #}
{%- if messages[0].role == "system" -%}
{%- set additional_system_message = messages[0].content | trim -%}
{%- set messages = messages[1:] -%}
{{- "\n\n" -}}
{{- additional_system_message -}}
{%- endif -%}
{{- EOS_STRING -}}
{# main loop over input messages, add the contents/tool_calls from each to the text #}
{%- for message in messages %}
{%- if message.content is string -%}
{%- set message_body = message.content -%}
{%- elif message.content is iterable and message.content is not string and message.content is not mapping -%}
{#- when inferencing with vLLM, string-only messages (i.e; where the 'content' field is just a string) are coerced into lists of {"type": "text", "text": "......"}-style dicts, if we have these fields, we include their values without any additional formatting between the content chunks -#}
{%- set message_body = "" -%}
{%- set content_msg_ns = namespace(text="", image_placeholder=IMAGE_PLACEHOLDER_STRING) -%}
{%- for snippet in message.content -%}
{#- screen dimensions-#}
{%- if snippet.type == "text" -%}
{%- set content_msg_ns.text = content_msg_ns.text ~ snippet.text -%}
{%- elif snippet.type == "image" -%}
{%- set content_msg_ns.text = content_msg_ns.text ~ "\n\n" ~ IMAGE_PLACEHOLDER_STRING -%}
{%- endif -%}
{%- endfor -%}
{%- set message_body = content_msg_ns.text -%}
{%- else -%}
{{- raise_exception("Unsupported message.content field provided, received this value in for content: " ~ message.content|string ~ " but expected either a list of content dicts, or a plain string.") -}}
{%- endif -%}
{%- set rendered_tool_calls = "" -%}
{%- if message.get("tool_calls") and message.tool_calls|length >= 1 -%}
{%- set tcns = namespace(body="") -%}
{%- for tool_call in message.tool_calls -%}
{%- set fn_call = FUNCTION_CALL_STRING
+ '{"name": "' + tool_call.function.name + '", '
+ '"arguments": '
+ tool_call.function.arguments | tojson
+ "}"
-%}
{#- NOTE: that for multiple tool calls, we add a newline between the JSON-ified bodies -#}
{%- set tcns.body = tcns.body + fn_call + "\n" -%}
{%- endfor -%}
{%- set rendered_tool_calls = tcns.body -%}
{%- endif -%}
{{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + (message_body | trim) + (rendered_tool_calls | trim) + EOS_STRING -}}
{%- endfor -%}
{#- bias model to output w extra chat templating -#}
{%- if add_generation_prompt -%}
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
{%- endif -%}