Text Generation
Transformers
Safetensors
MLX
English
Chinese
llama
llm
nanbeige
open4bits
conversational
text-generation-inference
4-bit precision
Instructions to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Open4bits/Nanbeige4.1-3B-mlx-4Bit") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Open4bits/Nanbeige4.1-3B-mlx-4Bit") model = AutoModelForCausalLM.from_pretrained("Open4bits/Nanbeige4.1-3B-mlx-4Bit", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - MLX
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("Open4bits/Nanbeige4.1-3B-mlx-4Bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- vLLM
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Open4bits/Nanbeige4.1-3B-mlx-4Bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Open4bits/Nanbeige4.1-3B-mlx-4Bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Open4bits/Nanbeige4.1-3B-mlx-4Bit
- SGLang
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit 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 "Open4bits/Nanbeige4.1-3B-mlx-4Bit" \ --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": "Open4bits/Nanbeige4.1-3B-mlx-4Bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Open4bits/Nanbeige4.1-3B-mlx-4Bit" \ --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": "Open4bits/Nanbeige4.1-3B-mlx-4Bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Pi
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Open4bits/Nanbeige4.1-3B-mlx-4Bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "Open4bits/Nanbeige4.1-3B-mlx-4Bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "Open4bits/Nanbeige4.1-3B-mlx-4Bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "Open4bits/Nanbeige4.1-3B-mlx-4Bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Open4bits/Nanbeige4.1-3B-mlx-4Bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Docker Model Runner
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with Docker Model Runner:
docker model run hf.co/Open4bits/Nanbeige4.1-3B-mlx-4Bit
- Hermes Agent
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Open4bits/Nanbeige4.1-3B-mlx-4Bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default Open4bits/Nanbeige4.1-3B-mlx-4Bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use Open4bits/Nanbeige4.1-3B-mlx-4Bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "Open4bits/Nanbeige4.1-3B-mlx-4Bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "Open4bits/Nanbeige4.1-3B-mlx-4Bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Upload chat_template.jinja with huggingface_hub
Browse files- chat_template.jinja +137 -0
chat_template.jinja
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
{%- if tools %}
|
| 3 |
+
{{- '<|im_start|>system
|
| 4 |
+
' }}
|
| 5 |
+
{%- if messages[0].role == 'system' %}
|
| 6 |
+
{{- messages[0].content + '
|
| 7 |
+
|
| 8 |
+
' }}
|
| 9 |
+
{%- else %}
|
| 10 |
+
{{- '你是一位工具函数调用专家,你会得到一个问题和一组可能的工具函数。根据问题,你需要进行一个或多个函数/工具调用以实现目的,请尽量尝试探索通过工具解决问题。
|
| 11 |
+
如果没有一个函数可以使用,请直接使用自然语言回复用户。
|
| 12 |
+
如果给定的问题缺少函数所需的参数,请使用自然语言进行提问,向用户询问必要信息。
|
| 13 |
+
如果调用结果已经足够回答用户问题,请对历史结果进行总结,使用自然语言回复用户。' }}
|
| 14 |
+
{%- endif %}
|
| 15 |
+
{{- "# Tools
|
| 16 |
+
|
| 17 |
+
You may call one or more functions to assist with the user query.
|
| 18 |
+
|
| 19 |
+
You are provided with function signatures within <tools></tools> XML tags:
|
| 20 |
+
<tools>" }}
|
| 21 |
+
{%- for tool in tools %}
|
| 22 |
+
{{- "
|
| 23 |
+
" }}
|
| 24 |
+
{{- tool | tojson }}
|
| 25 |
+
{%- endfor %}
|
| 26 |
+
{{- "
|
| 27 |
+
</tools>
|
| 28 |
+
|
| 29 |
+
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
|
| 30 |
+
<tool_call>
|
| 31 |
+
{\"name\": <function-name>, \"arguments\": <args-json-object>}
|
| 32 |
+
</tool_call><|im_end|>
|
| 33 |
+
" }}
|
| 34 |
+
{%- else %}
|
| 35 |
+
{%- if messages[0].role == 'system' %}
|
| 36 |
+
{{- '<|im_start|>system
|
| 37 |
+
' + messages[0].content + '<|im_end|>
|
| 38 |
+
' }}
|
| 39 |
+
{%- else %}
|
| 40 |
+
{{- '<|im_start|>system
|
| 41 |
+
你是南北阁,一款由BOSS直聘自主研发并训练的专业大语言模型。<|im_end|>
|
| 42 |
+
' }}
|
| 43 |
+
{%- endif %}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 46 |
+
{%- for message in messages[::-1] %}
|
| 47 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 48 |
+
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
|
| 49 |
+
{%- set ns.multi_step_tool = false %}
|
| 50 |
+
{%- set ns.last_query_index = index %}
|
| 51 |
+
{%- endif %}
|
| 52 |
+
{%- endfor %}
|
| 53 |
+
{%- for message in messages %}
|
| 54 |
+
{%- if message.content is string %}
|
| 55 |
+
{%- set content = message.content %}
|
| 56 |
+
{%- else %}
|
| 57 |
+
{%- set content = '' %}
|
| 58 |
+
{%- endif %}
|
| 59 |
+
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 60 |
+
{{- '<|im_start|>' + message.role + '
|
| 61 |
+
' + content + '<|im_end|>' + '
|
| 62 |
+
' }}
|
| 63 |
+
{%- elif message.role == "assistant" %}
|
| 64 |
+
{%- set reasoning_content = '' %}
|
| 65 |
+
{%- if message.reasoning_content is string %}
|
| 66 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 67 |
+
{%- else %}
|
| 68 |
+
{%- if '</think>' in content %}
|
| 69 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('
|
| 70 |
+
').split('<think>')[-1].lstrip('
|
| 71 |
+
') %}
|
| 72 |
+
{%- set content = content.split('</think>')[-1].lstrip('
|
| 73 |
+
') %}
|
| 74 |
+
{%- endif %}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- if loop.index0 > ns.last_query_index or keep_all_think or (extra_body is defined and extra_body.keep_all_think) %}
|
| 77 |
+
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 78 |
+
{{- '<|im_start|>' + message.role + '
|
| 79 |
+
<think>
|
| 80 |
+
' + reasoning_content.strip('
|
| 81 |
+
') + '
|
| 82 |
+
</think>
|
| 83 |
+
|
| 84 |
+
' + content.lstrip('
|
| 85 |
+
') }}
|
| 86 |
+
{%- else %}
|
| 87 |
+
{{- '<|im_start|>' + message.role + '
|
| 88 |
+
' + content }}
|
| 89 |
+
{%- endif %}
|
| 90 |
+
{%- else %}
|
| 91 |
+
{{- '<|im_start|>' + message.role + '
|
| 92 |
+
' + content }}
|
| 93 |
+
{%- endif %}
|
| 94 |
+
{%- if message.tool_calls %}
|
| 95 |
+
{%- for tool_call in message.tool_calls %}
|
| 96 |
+
{%- if (loop.first and content) or (not loop.first) %}
|
| 97 |
+
{{- '
|
| 98 |
+
' }}
|
| 99 |
+
{%- endif %}
|
| 100 |
+
{%- if tool_call.function %}
|
| 101 |
+
{%- set tool_call = tool_call.function %}
|
| 102 |
+
{%- endif %}
|
| 103 |
+
{{- '<tool_call>
|
| 104 |
+
{"name": "' }}
|
| 105 |
+
{{- tool_call.name }}
|
| 106 |
+
{{- '", "arguments": ' }}
|
| 107 |
+
{%- if tool_call.arguments is string %}
|
| 108 |
+
{{- tool_call.arguments }}
|
| 109 |
+
{%- else %}
|
| 110 |
+
{{- tool_call.arguments | tojson }}
|
| 111 |
+
{%- endif %}
|
| 112 |
+
{{- '}
|
| 113 |
+
</tool_call>' }}
|
| 114 |
+
{%- endfor %}
|
| 115 |
+
{%- endif %}
|
| 116 |
+
{{- '<|im_end|>
|
| 117 |
+
' }}
|
| 118 |
+
{%- elif message.role == "tool" %}
|
| 119 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 120 |
+
{{- '<|im_start|>user' }}
|
| 121 |
+
{%- endif %}
|
| 122 |
+
{{- '
|
| 123 |
+
<tool_response>
|
| 124 |
+
' }}
|
| 125 |
+
{{- content }}
|
| 126 |
+
{{- '
|
| 127 |
+
</tool_response>' }}
|
| 128 |
+
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 129 |
+
{{- '<|im_end|>
|
| 130 |
+
' }}
|
| 131 |
+
{%- endif %}
|
| 132 |
+
{%- endif %}
|
| 133 |
+
{%- endfor %}
|
| 134 |
+
{%- if add_generation_prompt %}
|
| 135 |
+
{{- '<|im_start|>assistant
|
| 136 |
+
' }}
|
| 137 |
+
{%- endif %}
|