Text Generation
Transformers
Safetensors
English
qwen3
code
agent
Merge
uncensored
Rhea
multi-pass
reasoning
conversational
text-generation-inference
Instructions to use roskosmos19/Rhea-4B-Coding with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use roskosmos19/Rhea-4B-Coding with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="roskosmos19/Rhea-4B-Coding") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("roskosmos19/Rhea-4B-Coding") model = AutoModelForCausalLM.from_pretrained("roskosmos19/Rhea-4B-Coding", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use roskosmos19/Rhea-4B-Coding with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "roskosmos19/Rhea-4B-Coding" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "roskosmos19/Rhea-4B-Coding", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/roskosmos19/Rhea-4B-Coding
- SGLang
How to use roskosmos19/Rhea-4B-Coding 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 "roskosmos19/Rhea-4B-Coding" \ --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": "roskosmos19/Rhea-4B-Coding", "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 "roskosmos19/Rhea-4B-Coding" \ --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": "roskosmos19/Rhea-4B-Coding", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use roskosmos19/Rhea-4B-Coding with Docker Model Runner:
docker model run hf.co/roskosmos19/Rhea-4B-Coding
Update chat_template.jinja
Browse files- chat_template.jinja +51 -16
chat_template.jinja
CHANGED
|
@@ -1,19 +1,24 @@
|
|
| 1 |
{%- if tools %}
|
| 2 |
-
{{- '<|im_start|>system\n' }}
|
| 3 |
{%- if messages[0].role == 'system' %}
|
| 4 |
{{- messages[0].content + '\n\n' }}
|
|
|
|
|
|
|
| 5 |
{%- endif %}
|
| 6 |
-
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
| 7 |
{%- for tool in tools %}
|
| 8 |
{{- "\n" }}
|
| 9 |
{{- tool | tojson }}
|
| 10 |
{%- endfor %}
|
| 11 |
-
{{- "\n</tools>\n\nFor each function 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>
|
| 12 |
{%- else %}
|
| 13 |
{%- if messages[0].role == 'system' %}
|
| 14 |
-
{{- '<|im_start|>system\n' + messages[0].content + '
|
|
|
|
|
|
|
| 15 |
{%- endif %}
|
| 16 |
{%- endif %}
|
|
|
|
| 17 |
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
{%- for message in messages[::-1] %}
|
| 19 |
{%- set index = (messages|length - 1) - loop.index0 %}
|
|
@@ -22,33 +27,60 @@
|
|
| 22 |
{%- set ns.last_query_index = index %}
|
| 23 |
{%- endif %}
|
| 24 |
{%- endfor %}
|
|
|
|
| 25 |
{%- for message in messages %}
|
| 26 |
{%- if message.content is string %}
|
| 27 |
{%- set content = message.content %}
|
| 28 |
{%- else %}
|
| 29 |
{%- set content = '' %}
|
| 30 |
{%- endif %}
|
|
|
|
| 31 |
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 32 |
-
{{- '<|im_start|>' + message.role + '\n' + content + '
|
|
|
|
| 33 |
{%- elif message.role == "assistant" %}
|
| 34 |
{%- set reasoning_content = '' %}
|
| 35 |
{%- if message.reasoning_content is string %}
|
| 36 |
{%- set reasoning_content = message.reasoning_content %}
|
| 37 |
{%- else %}
|
| 38 |
-
{%- if '
|
| 39 |
-
{%- set reasoning_content = content.split('
|
| 40 |
-
{%- set content = content.split('
|
| 41 |
{%- endif %}
|
| 42 |
{%- endif %}
|
|
|
|
| 43 |
{%- if loop.index0 > ns.last_query_index %}
|
| 44 |
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 45 |
-
{{- '<|im_start|>' + message.role + '\n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
{%- else %}
|
| 47 |
-
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 48 |
{%- endif %}
|
| 49 |
{%- else %}
|
| 50 |
-
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 51 |
{%- endif %}
|
|
|
|
| 52 |
{%- if message.tool_calls %}
|
| 53 |
{%- for tool_call in message.tool_calls %}
|
| 54 |
{%- if (loop.first and content) or (not loop.first) %}
|
|
@@ -68,19 +100,22 @@
|
|
| 68 |
{{- '}\n</tool_call>' }}
|
| 69 |
{%- endfor %}
|
| 70 |
{%- endif %}
|
| 71 |
-
{{- '
|
|
|
|
| 72 |
{%- elif message.role == "tool" %}
|
| 73 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 74 |
-
{{- '<|im_start|>user' }}
|
| 75 |
{%- endif %}
|
| 76 |
-
{{- '\n<tool_response>\n' }}
|
| 77 |
{{- content }}
|
| 78 |
{{- '\n</tool_response>' }}
|
| 79 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 80 |
-
{{- '
|
| 81 |
{%- endif %}
|
| 82 |
{%- endif %}
|
| 83 |
{%- endfor %}
|
|
|
|
| 84 |
{%- if add_generation_prompt %}
|
| 85 |
-
{{- '<|im_start|>assistant\n
|
|
|
|
| 86 |
{%- endif %}
|
|
|
|
| 1 |
{%- if tools %}
|
| 2 |
+
{{- '||<|<|im_start|>system\n' }}
|
| 3 |
{%- if messages[0].role == 'system' %}
|
| 4 |
{{- messages[0].content + '\n\n' }}
|
| 5 |
+
{%- else %}
|
| 6 |
+
{{- 'You are Rhea-4B, a coding AI with multi-pass processing. Your process: 1) First implementation, 2) Self-review for bugs/edge cases/security/performance, 3) Final optimized version. Functionality remains identical, only structure and comments are improved.\n\n' }}
|
| 7 |
{%- endif %}
|
| 8 |
+
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<<tools>" }}
|
| 9 |
{%- for tool in tools %}
|
| 10 |
{{- "\n" }}
|
| 11 |
{{- tool | tojson }}
|
| 12 |
{%- endfor %}
|
| 13 |
+
{{- "\n</tools>\n\nFor each function 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> ζθη»ζ\n" }}
|
| 14 |
{%- else %}
|
| 15 |
{%- if messages[0].role == 'system' %}
|
| 16 |
+
{{- '||<|<|im_start|>system\n' + messages[0].content + ' ζθη»ζ\n' }}
|
| 17 |
+
{%- else %}
|
| 18 |
+
{{- '||<|<|im_start|>system\nYou are Rhea-4B, a coding AI with multi-pass processing. Your process: 1) First implementation, 2) Self-review for bugs/edge cases/security/performance, 3) Final optimized version. Functionality remains identical, only structure and comments are improved. ζθη»ζ\n' }}
|
| 19 |
{%- endif %}
|
| 20 |
{%- endif %}
|
| 21 |
+
|
| 22 |
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 23 |
{%- for message in messages[::-1] %}
|
| 24 |
{%- set index = (messages|length - 1) - loop.index0 %}
|
|
|
|
| 27 |
{%- set ns.last_query_index = index %}
|
| 28 |
{%- endif %}
|
| 29 |
{%- endfor %}
|
| 30 |
+
|
| 31 |
{%- for message in messages %}
|
| 32 |
{%- if message.content is string %}
|
| 33 |
{%- set content = message.content %}
|
| 34 |
{%- else %}
|
| 35 |
{%- set content = '' %}
|
| 36 |
{%- endif %}
|
| 37 |
+
|
| 38 |
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 39 |
+
{{- '||<|<|im_start|>' + message.role + '\n' + content + ' ζθη»ζ\n' }}
|
| 40 |
+
|
| 41 |
{%- elif message.role == "assistant" %}
|
| 42 |
{%- set reasoning_content = '' %}
|
| 43 |
{%- if message.reasoning_content is string %}
|
| 44 |
{%- set reasoning_content = message.reasoning_content %}
|
| 45 |
{%- else %}
|
| 46 |
+
{%- if 'ζθη»ζ' in content %}
|
| 47 |
+
{%- set reasoning_content = content.split('ζθη»ζ')[0].rstrip('\n').split('ζθ')[0].lstrip('\n') %}
|
| 48 |
+
{%- set content = content.split('ζθη»ζ')[-1].lstrip('\n') %}
|
| 49 |
{%- endif %}
|
| 50 |
{%- endif %}
|
| 51 |
+
|
| 52 |
{%- if loop.index0 > ns.last_query_index %}
|
| 53 |
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 54 |
+
{{- '||<|<|im_start|>' + message.role + '\n' }}
|
| 55 |
+
|
| 56 |
+
{# Multi-Pass Coding Structure #}
|
| 57 |
+
{{- '### PASS 1 - First Implementation:\n' }}
|
| 58 |
+
{{- content.lstrip('\n') }}
|
| 59 |
+
|
| 60 |
+
{{- '\n\n<<||<|<|think_start|>\n' }}
|
| 61 |
+
{{- '### PASS 2 - Self-Review:\n' }}
|
| 62 |
+
{{- '- Syntax errors? Check correct bracketing, semicolons, imports\n' }}
|
| 63 |
+
{{- '- Edge cases? Empty inputs, null values, boundary cases\n' }}
|
| 64 |
+
{{- '- Performance? Time complexity, memory leaks, loops\n' }}
|
| 65 |
+
{{- '- Security? SQL injection, XSS, buffer overflow, input validation\n' }}
|
| 66 |
+
{{- '- Type safety? Type hints, generics, null safety\n' }}
|
| 67 |
+
{{- '<||<|<|think_end|>\n' }}
|
| 68 |
+
|
| 69 |
+
{{- '\n<<||<|<|review_start|>\n' }}
|
| 70 |
+
{{- 'Review results: [Document found issues here]\n' }}
|
| 71 |
+
{{- '<||<|<|review_end|>\n' }}
|
| 72 |
+
|
| 73 |
+
{{- '\n<<||<|<|final_start|>\n' }}
|
| 74 |
+
{{- '### PASS 3 - Final Version:\n' }}
|
| 75 |
+
{{- 'Based on review - identical functionality, optimized structure:\n\n' }}
|
| 76 |
+
|
| 77 |
{%- else %}
|
| 78 |
+
{{- '||<|<|im_start|>' + message.role + '\n' + content }}
|
| 79 |
{%- endif %}
|
| 80 |
{%- else %}
|
| 81 |
+
{{- '||<|<|im_start|>' + message.role + '\n' + content }}
|
| 82 |
{%- endif %}
|
| 83 |
+
|
| 84 |
{%- if message.tool_calls %}
|
| 85 |
{%- for tool_call in message.tool_calls %}
|
| 86 |
{%- if (loop.first and content) or (not loop.first) %}
|
|
|
|
| 100 |
{{- '}\n</tool_call>' }}
|
| 101 |
{%- endfor %}
|
| 102 |
{%- endif %}
|
| 103 |
+
{{- ' ζθη»ζ\n' }}
|
| 104 |
+
|
| 105 |
{%- elif message.role == "tool" %}
|
| 106 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 107 |
+
{{- '||<|<|im_start|>user' }}
|
| 108 |
{%- endif %}
|
| 109 |
+
{{- '\n<<tool_response>\n' }}
|
| 110 |
{{- content }}
|
| 111 |
{{- '\n</tool_response>' }}
|
| 112 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 113 |
+
{{- ' ζθη»ζ\n' }}
|
| 114 |
{%- endif %}
|
| 115 |
{%- endif %}
|
| 116 |
{%- endfor %}
|
| 117 |
+
|
| 118 |
{%- if add_generation_prompt %}
|
| 119 |
+
{{- '||<|<|im_start|>assistant\n' }}
|
| 120 |
+
{{- '### PASS 1 - First Implementation:\n' }}
|
| 121 |
{%- endif %}
|