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") 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 +15 -37
chat_template.jinja
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{%- if tools %}
|
| 2 |
-
{{- '||<|im_start|>system\n' }}
|
| 3 |
{%- if messages[0].role == 'system' %}
|
| 4 |
{{- messages[0].content + '\n\n' }}
|
| 5 |
{%- else %}
|
|
@@ -10,12 +10,12 @@
|
|
| 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>||<|eos|>\n" }}
|
| 14 |
{%- else %}
|
| 15 |
{%- if messages[0].role == 'system' %}
|
| 16 |
-
{{- '||<|im_start|>system\n' + messages[0].content + '||<|eos|>\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.||<|eos|>\n' }}
|
| 19 |
{%- endif %}
|
| 20 |
{%- endif %}
|
| 21 |
|
|
@@ -36,48 +36,27 @@
|
|
| 36 |
{%- endif %}
|
| 37 |
|
| 38 |
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 39 |
-
{{- '||<|im_start|>' + message.role + '\n' + content + '||<|eos|>\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 '||<|thinking_end|>' in content %}
|
| 47 |
-
{%- set reasoning_content = content.split('||<|thinking_end|>')[0].rstrip('\n').split('||<|thinking|>')[-1].lstrip('\n') %}
|
| 48 |
-
{%- set content = content.split('||<|thinking_end|>')[-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 |
-
{{- '### PASS 1 - First Implementation:\n' }}
|
| 57 |
-
{{- content.lstrip('\n') }}
|
| 58 |
-
|
| 59 |
-
{{- '\n\n||<|think_start|>\n' }}
|
| 60 |
-
{{- '### PASS 2 - Self-Review:\n' }}
|
| 61 |
-
{{- '- Syntax errors? Check correct bracketing, semicolons, imports\n' }}
|
| 62 |
-
{{- '- Edge cases? Empty inputs, null values, boundary cases\n' }}
|
| 63 |
-
{{- '- Performance? Time complexity, memory leaks, loops\n' }}
|
| 64 |
-
{{- '- Security? SQL injection, XSS, buffer overflow, input validation\n' }}
|
| 65 |
-
{{- '- Type safety? Type hints, generics, null safety\n' }}
|
| 66 |
-
{{- '||<|think_end|>\n' }}
|
| 67 |
-
|
| 68 |
-
{{- '\n||<|review_start|>\n' }}
|
| 69 |
-
{{- 'Review results: [Document found issues here]\n' }}
|
| 70 |
-
{{- '||<|review_end|>\n' }}
|
| 71 |
-
|
| 72 |
-
{{- '\n||<|final_start|>\n' }}
|
| 73 |
-
{{- '### PASS 3 - Final Version:\n' }}
|
| 74 |
-
{{- 'Based on review - identical functionality, optimized structure:\n\n' }}
|
| 75 |
-
|
| 76 |
{%- else %}
|
| 77 |
-
{{- '||<|im_start|>' + message.role + '\n' + content }}
|
| 78 |
{%- endif %}
|
| 79 |
{%- else %}
|
| 80 |
-
{{- '||<|im_start|>' + message.role + '\n' + content }}
|
| 81 |
{%- endif %}
|
| 82 |
|
| 83 |
{%- if message.tool_calls %}
|
|
@@ -99,22 +78,21 @@
|
|
| 99 |
{{- '}\n</tool_call>' }}
|
| 100 |
{%- endfor %}
|
| 101 |
{%- endif %}
|
| 102 |
-
{{- '||<|eos|>\n' }}
|
| 103 |
|
| 104 |
{%- elif message.role == "tool" %}
|
| 105 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 106 |
-
{{- '||<|im_start|>user' }}
|
| 107 |
{%- endif %}
|
| 108 |
{{- '\n<<tool_response>\n' }}
|
| 109 |
{{- content }}
|
| 110 |
{{- '\n</tool_response>' }}
|
| 111 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 112 |
-
{{- '||<|eos|>\n' }}
|
| 113 |
{%- endif %}
|
| 114 |
{%- endif %}
|
| 115 |
{%- endfor %}
|
| 116 |
|
| 117 |
{%- if add_generation_prompt %}
|
| 118 |
-
{{- '||<|im_start|>assistant\n' }}
|
| 119 |
-
{{- '### PASS 1 - First Implementation:\n' }}
|
| 120 |
{%- endif %}
|
|
|
|
| 1 |
{%- if tools %}
|
| 2 |
+
{{- '||<|<|im_start|>system\n' }}
|
| 3 |
{%- if messages[0].role == 'system' %}
|
| 4 |
{{- messages[0].content + '\n\n' }}
|
| 5 |
{%- else %}
|
|
|
|
| 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>||<|<|eos|>\n" }}
|
| 14 |
{%- else %}
|
| 15 |
{%- if messages[0].role == 'system' %}
|
| 16 |
+
{{- '||<|<|im_start|>system\n' + messages[0].content + '||<|<|eos|>\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.||<|<|eos|>\n' }}
|
| 19 |
{%- endif %}
|
| 20 |
{%- endif %}
|
| 21 |
|
|
|
|
| 36 |
{%- endif %}
|
| 37 |
|
| 38 |
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 39 |
+
{{- '||<|<|im_start|>' + message.role + '\n' + content + '||<|<|eos|>\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 '||<|<|thinking_end|>' in content %}
|
| 47 |
+
{%- set reasoning_content = content.split('||<|<|thinking_end|>')[0].rstrip('\n').split('||<|<|thinking|>')[-1].lstrip('\n') %}
|
| 48 |
+
{%- set content = content.split('||<|<|thinking_end|>')[-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' + content }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
{%- else %}
|
| 56 |
+
{{- '||<|<|im_start|>' + message.role + '\n' + content }}
|
| 57 |
{%- endif %}
|
| 58 |
{%- else %}
|
| 59 |
+
{{- '||<|<|im_start|>' + message.role + '\n' + content }}
|
| 60 |
{%- endif %}
|
| 61 |
|
| 62 |
{%- if message.tool_calls %}
|
|
|
|
| 78 |
{{- '}\n</tool_call>' }}
|
| 79 |
{%- endfor %}
|
| 80 |
{%- endif %}
|
| 81 |
+
{{- '||<|<|eos|>\n' }}
|
| 82 |
|
| 83 |
{%- elif message.role == "tool" %}
|
| 84 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 85 |
+
{{- '||<|<|im_start|>user' }}
|
| 86 |
{%- endif %}
|
| 87 |
{{- '\n<<tool_response>\n' }}
|
| 88 |
{{- content }}
|
| 89 |
{{- '\n</tool_response>' }}
|
| 90 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 91 |
+
{{- '||<|<|eos|>\n' }}
|
| 92 |
{%- endif %}
|
| 93 |
{%- endif %}
|
| 94 |
{%- endfor %}
|
| 95 |
|
| 96 |
{%- if add_generation_prompt %}
|
| 97 |
+
{{- '||<|<|im_start|>assistant\n' }}
|
|
|
|
| 98 |
{%- endif %}
|