Instructions to use ServiceNow-AI/Apriel-1.5-15b-Thinker with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ServiceNow-AI/Apriel-1.5-15b-Thinker with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="ServiceNow-AI/Apriel-1.5-15b-Thinker") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("ServiceNow-AI/Apriel-1.5-15b-Thinker") model = AutoModelForImageTextToText.from_pretrained("ServiceNow-AI/Apriel-1.5-15b-Thinker") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ServiceNow-AI/Apriel-1.5-15b-Thinker with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ServiceNow-AI/Apriel-1.5-15b-Thinker" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ServiceNow-AI/Apriel-1.5-15b-Thinker", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/ServiceNow-AI/Apriel-1.5-15b-Thinker
- SGLang
How to use ServiceNow-AI/Apriel-1.5-15b-Thinker with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ServiceNow-AI/Apriel-1.5-15b-Thinker" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ServiceNow-AI/Apriel-1.5-15b-Thinker", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ServiceNow-AI/Apriel-1.5-15b-Thinker" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ServiceNow-AI/Apriel-1.5-15b-Thinker", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use ServiceNow-AI/Apriel-1.5-15b-Thinker with Docker Model Runner:
docker model run hf.co/ServiceNow-AI/Apriel-1.5-15b-Thinker
Update chat_template.json
Browse files- chat_template.json +1 -1
chat_template.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
{
|
| 2 |
-
"{%- set available_tools_string = '' -%}{%- set thought_instructions = '' -%}{%- set add_tool_id = true -%}{%- set tool_output_format = 'default' -%}\n\n{% if tools is not none and tools|length > 0 %}\n {% set available_tools_string %}\nYou are provided with function signatures within <available_tools></available_tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about the arguments. You should infer the argument values from previous user responses and the system message. Here are the available tools:\n<available_tools>\n{% for tool in tools %}\n{{ tool|string }}\n{% endfor %}\n</available_tools>\n{% endset %}\n{% endif %}\n{% if tool_output_format is none or tool_output_format == 'default' %}\n{% set tool_output_instructions %}\nReturn all function calls as a list of json objects within <tool_call></tool_call> XML tags. Each json object should contain a function name and arguments as follows:\n<tool_calls>[{\"name\": <function-name-1>, \"arguments\": <args-dict-1>}, {\"name\": <function-name-2>, \"arguments\": <args-dict-2>},...]</tool_calls>\n{% endset %}\n{% elif tool_output_format == 'yaml' %}\n{% set tool_output_instructions %}\nReturn all function calls as a list of yaml objects within <tool_call></tool_call> XML tags. Each yaml object should contain a function name and arguments as follows:\n<tool_calls>\n- name: <function-name-1>\n arguments: <args-dict-1>\n- name: <function-name-2>\n arguments: <args-dict-2>\n...\n</tool_calls>\n{% endset %}\n{% endif %}\n{% if add_thoughts %}\n{% set thought_instructions %}\nPrior to generating the function calls, you should generate the reasoning for why you're calling the function. Please generate these reasoning thoughts between <thinking> and </thinking> XML tags.\n{% endset %}\n{% endif %}\n{{- bos_token -}}\n{% set reasoning_prompt='You are a thoughtful and systematic AI assistant built by ServiceNow Language Models (SLAM) lab. Before providing an answer, analyze the problem carefully and present your reasoning step by step. After explaining your thought process, provide the final solution in the following format: [BEGIN FINAL RESPONSE] ... [END FINAL RESPONSE].' %}\n{% if messages[0]['role'] != 'system' and tools is not none and tools|length > 0 %}\n {{- '<|system|>\\n' + reasoning_prompt + available_tools_string + '\\n' + tool_output_instructions + '\\n<|end|>\\n' -}}\n{% endif %}\n{% if messages|selectattr('role', 'equalto', 'system')|list|length == 0 %}\n{{- '<|system|>\\n' + reasoning_prompt + '\\n<|end|>\\n' -}}\n{% endif %}\n{% for message in messages %}\n {% if message['role'] == 'user' %}\n {{- '<|user|>\\n' }}\n {% if message['content'] is not string %}\n {% for chunk in message['content'] %}\n {% if chunk['type'] == 'text' %}\n {{- chunk['text'] }}\n {% elif chunk['type'] == 'image' or chunk['type'] == 'image_url'%}\n {{- '[IMG]' }}\n {% else %}\n {{- raise_exception('Unrecognized content type!') }}\n {% endif %}\n {% endfor %}\n {% else %}\n {{- message['content'] }}\n {% endif %}\n {{- '\\n<|end|>\\n' }}\n {% elif message['role'] == 'content' %}\n {% if message['content'] is not string %}\n {{- '<|content|>\\n' + message['content'][0]['text'] + '\\n<|end|>\\n' -}}\n {% else %}\n {{- '<|content|>\\n' + message['content'] + '\\n<|end|>\\n' -}}\n {% endif %}\n {% elif message['role'] == 'system' %}\n {% if message['content'] is not none and message['content']|length > 0 %}\n {% if message['content'] is string %}\n {% set system_message = message['content'] %}\n {% else %}\n {% set system_message = message['content'][0]['text'] %}\n {% endif %}\n {% else %}\n {% set system_message = '' %}\n {% endif %}\n {% if tools is not none and tools|length > 0 %}\n {{- '<|system|>\\n' + reasoning_prompt + system_message + '\\n' + available_tools_string + '\\n<|end|>\\n' -}}\n {% else %}\n {{- '<|system|>\\n' + reasoning_prompt + system_message + '\\n<|end|>\\n' -}}\n {% endif %}\n {% elif message['role'] == 'assistant' %}\n {% if loop.last %}\n {% set add_tool_id = false %}\n {% endif %}\n {{- '<|assistant|>\\n' -}}\n {% if message['content'] is not none and message['content']|length > 0 %}\n {% if message['content'] is not string and message['content'][0]['text'] is not none %}\n {{- message['content'][0]['text'] }}\n {% else %}\n {{- message['content'] -}}\n {% endif %}\n {% elif message['chosen'] is not none and message['chosen']|length > 0 %}\n {{- message['chosen'][0] -}}\n {% endif %}\n {% if add_thoughts and 'thought' in message and message['thought'] is not none %}\n {{- '<thinking>' + message['thought'] + '</thinking>' -}}\n {% endif %}\n {% if message['tool_calls'] is not none and message['tool_calls']|length > 0 %}\n {{- '\\n<tool_calls>[' -}}\n {% for tool_call in message['tool_calls'] %}\n {{- '{\"name\": \"' + tool_call['function']['name'] + '\", \"arguments\": ' + tool_call['function']['arguments']|string -}}\n {% if add_tool_id == true %}\n {{- ', \"id\": \"' + tool_call['id'] + '\"' -}}\n {% endif %}\n {{- '}' -}}\n {% if not loop.last %}{{- ', ' -}}{% endif %}\n {% endfor %}\n {{- ']</tool_calls>' -}}\n {% endif %}\n {{- '\\n<|end|>\\n' + eos_token -}}\n {% elif message['role'] == 'tool' %}\n {% if message['content'] is string %}\n {% set tool_message = message['content'] %}\n {% else %}\n {% set tool_message = message['content'][0]['text'] %}\n {% endif %}\n {{- '<|tool_result|>\\n' + tool_message|string + '\\n<|end|>\\n' -}}\n {% endif %}\n {% if loop.last and add_generation_prompt and message['role'] != 'assistant' %}\n {{- '<|assistant|>\\n' -}}\n {% endif %}\n{% endfor %}"
|
| 3 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"chat_template": "{%- set available_tools_string = '' -%}{%- set thought_instructions = '' -%}{%- set add_tool_id = true -%}{%- set tool_output_format = 'default' -%}\n\n{% if tools is not none and tools|length > 0 %}\n {% set available_tools_string %}\nYou are provided with function signatures within <available_tools></available_tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about the arguments. You should infer the argument values from previous user responses and the system message. Here are the available tools:\n<available_tools>\n{% for tool in tools %}\n{{ tool|string }}\n{% endfor %}\n</available_tools>\n{% endset %}\n{% endif %}\n{% if tool_output_format is none or tool_output_format == 'default' %}\n{% set tool_output_instructions %}\nReturn all function calls as a list of json objects within <tool_call></tool_call> XML tags. Each json object should contain a function name and arguments as follows:\n<tool_calls>[{\"name\": <function-name-1>, \"arguments\": <args-dict-1>}, {\"name\": <function-name-2>, \"arguments\": <args-dict-2>},...]</tool_calls>\n{% endset %}\n{% elif tool_output_format == 'yaml' %}\n{% set tool_output_instructions %}\nReturn all function calls as a list of yaml objects within <tool_call></tool_call> XML tags. Each yaml object should contain a function name and arguments as follows:\n<tool_calls>\n- name: <function-name-1>\n arguments: <args-dict-1>\n- name: <function-name-2>\n arguments: <args-dict-2>\n...\n</tool_calls>\n{% endset %}\n{% endif %}\n{% if add_thoughts %}\n{% set thought_instructions %}\nPrior to generating the function calls, you should generate the reasoning for why you're calling the function. Please generate these reasoning thoughts between <thinking> and </thinking> XML tags.\n{% endset %}\n{% endif %}\n{{- bos_token -}}\n{% set reasoning_prompt='You are a thoughtful and systematic AI assistant built by ServiceNow Language Models (SLAM) lab. Before providing an answer, analyze the problem carefully and present your reasoning step by step. After explaining your thought process, provide the final solution in the following format: [BEGIN FINAL RESPONSE] ... [END FINAL RESPONSE].' %}\n{% if messages[0]['role'] != 'system' and tools is not none and tools|length > 0 %}\n {{- '<|system|>\\n' + reasoning_prompt + available_tools_string + '\\n' + tool_output_instructions + '\\n<|end|>\\n' -}}\n{% endif %}\n{% if messages|selectattr('role', 'equalto', 'system')|list|length == 0 %}\n{{- '<|system|>\\n' + reasoning_prompt + '\\n<|end|>\\n' -}}\n{% endif %}\n{% for message in messages %}\n {% if message['role'] == 'user' %}\n {{- '<|user|>\\n' }}\n {% if message['content'] is not string %}\n {% for chunk in message['content'] %}\n {% if chunk['type'] == 'text' %}\n {{- chunk['text'] }}\n {% elif chunk['type'] == 'image' or chunk['type'] == 'image_url'%}\n {{- '[IMG]' }}\n {% else %}\n {{- raise_exception('Unrecognized content type!') }}\n {% endif %}\n {% endfor %}\n {% else %}\n {{- message['content'] }}\n {% endif %}\n {{- '\\n<|end|>\\n' }}\n {% elif message['role'] == 'content' %}\n {% if message['content'] is not string %}\n {{- '<|content|>\\n' + message['content'][0]['text'] + '\\n<|end|>\\n' -}}\n {% else %}\n {{- '<|content|>\\n' + message['content'] + '\\n<|end|>\\n' -}}\n {% endif %}\n {% elif message['role'] == 'system' %}\n {% if message['content'] is not none and message['content']|length > 0 %}\n {% if message['content'] is string %}\n {% set system_message = message['content'] %}\n {% else %}\n {% set system_message = message['content'][0]['text'] %}\n {% endif %}\n {% else %}\n {% set system_message = '' %}\n {% endif %}\n {% if tools is not none and tools|length > 0 %}\n {{- '<|system|>\\n' + reasoning_prompt + system_message + '\\n' + available_tools_string + '\\n<|end|>\\n' -}}\n {% else %}\n {{- '<|system|>\\n' + reasoning_prompt + system_message + '\\n<|end|>\\n' -}}\n {% endif %}\n {% elif message['role'] == 'assistant' %}\n {% if loop.last %}\n {% set add_tool_id = false %}\n {% endif %}\n {{- '<|assistant|>\\n' -}}\n {% if message['content'] is not none and message['content']|length > 0 %}\n {% if message['content'] is not string and message['content'][0]['text'] is not none %}\n {{- message['content'][0]['text'] }}\n {% else %}\n {{- message['content'] -}}\n {% endif %}\n {% elif message['chosen'] is not none and message['chosen']|length > 0 %}\n {{- message['chosen'][0] -}}\n {% endif %}\n {% if add_thoughts and 'thought' in message and message['thought'] is not none %}\n {{- '<thinking>' + message['thought'] + '</thinking>' -}}\n {% endif %}\n {% if message['tool_calls'] is not none and message['tool_calls']|length > 0 %}\n {{- '\\n<tool_calls>[' -}}\n {% for tool_call in message['tool_calls'] %}\n {{- '{\"name\": \"' + tool_call['function']['name'] + '\", \"arguments\": ' + tool_call['function']['arguments']|string -}}\n {% if add_tool_id == true %}\n {{- ', \"id\": \"' + tool_call['id'] + '\"' -}}\n {% endif %}\n {{- '}' -}}\n {% if not loop.last %}{{- ', ' -}}{% endif %}\n {% endfor %}\n {{- ']</tool_calls>' -}}\n {% endif %}\n {{- '\\n<|end|>\\n' + eos_token -}}\n {% elif message['role'] == 'tool' %}\n {% if message['content'] is string %}\n {% set tool_message = message['content'] %}\n {% else %}\n {% set tool_message = message['content'][0]['text'] %}\n {% endif %}\n {{- '<|tool_result|>\\n' + tool_message|string + '\\n<|end|>\\n' -}}\n {% endif %}\n {% if loop.last and add_generation_prompt and message['role'] != 'assistant' %}\n {{- '<|assistant|>\\n' -}}\n {% endif %}\n{% endfor %}"
|
| 3 |
}
|