Update README.md
Browse files
README.md
CHANGED
|
@@ -6,167 +6,332 @@ tags:
|
|
| 6 |
- coding-agent
|
| 7 |
- instruction-tuned
|
| 8 |
- hermit-code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
pipeline_tag: text-generation
|
| 10 |
---
|
| 11 |
|
| 12 |
-
<
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
<img src="https://img.shields.io/badge/
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
<
|
| 21 |
-
<p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
<p
|
| 24 |
-
<a href="#-quick-start">
|
| 25 |
-
<a href="#-capabilities">
|
| 26 |
-
<a href="#-
|
| 27 |
-
<a href="#-
|
| 28 |
-
<a href="#-examples">Examples</a> β’
|
| 29 |
-
<a href="#-acknowledgments">Acknowledgments</a>
|
| 30 |
</p>
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
---
|
| 33 |
|
| 34 |
-
## Quick Start
|
|
|
|
|
|
|
| 35 |
|
| 36 |
```python
|
| 37 |
from transformers import pipeline
|
| 38 |
|
|
|
|
| 39 |
pipe = pipeline("text-generation", model="Soloman2002/hermit-code-7b")
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
]
|
| 43 |
-
pipe(chat, max_new_tokens=512)
|
|
|
|
|
|
|
| 44 |
```
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
|
| 49 |
-
|---|---|
|
| 50 |
-
| **
|
| 51 |
-
| **
|
| 52 |
-
| **
|
| 53 |
-
| **
|
| 54 |
-
| **
|
| 55 |
-
| **Context** |
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|---|---|
|
| 61 |
-
| **Base Model** | [Qwen/Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct) |
|
| 62 |
-
| **Architecture** | Qwen2.5 Dense Transformer |
|
| 63 |
-
| **Parameters** | 7.61B (6.53B non-embedding) |
|
| 64 |
-
| **Layers** | 28 |
|
| 65 |
-
| **Attention** | GQA (28 Q heads, 4 KV heads) |
|
| 66 |
-
| **Context Length** | 131,072 tokens |
|
| 67 |
-
| **License** | Apache 2.0 |
|
| 68 |
-
| **Format** | Safetensors (BF16) |
|
| 69 |
|
| 70 |
-
## Usage
|
| 71 |
|
| 72 |
### Transformers
|
| 73 |
|
|
|
|
|
|
|
| 74 |
```python
|
| 75 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 76 |
|
|
|
|
|
|
|
| 77 |
model = AutoModelForCausalLM.from_pretrained(
|
| 78 |
-
|
| 79 |
-
torch_dtype=
|
| 80 |
device_map="auto"
|
| 81 |
)
|
| 82 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 83 |
|
|
|
|
| 84 |
messages = [
|
| 85 |
-
{"role": "system", "content": "You are Hermit Code,
|
| 86 |
{"role": "user", "content": "Write a Rust function that checks if a string is a palindrome."}
|
| 87 |
]
|
|
|
|
|
|
|
| 88 |
text = tokenizer.apply_chat_template(
|
| 89 |
-
messages,
|
|
|
|
|
|
|
| 90 |
)
|
|
|
|
|
|
|
| 91 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 92 |
-
outputs = model.generate(
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
print(response)
|
| 95 |
```
|
| 96 |
|
|
|
|
|
|
|
| 97 |
### vLLM (Recommended for Production)
|
| 98 |
|
|
|
|
|
|
|
|
|
|
| 99 |
```bash
|
| 100 |
pip install vllm
|
| 101 |
-
vllm serve "Soloman2002/hermit-code-7b"
|
| 102 |
```
|
| 103 |
|
|
|
|
| 104 |
```bash
|
| 105 |
curl -X POST "http://localhost:8000/v1/chat/completions" \
|
| 106 |
-H "Content-Type: application/json" \
|
| 107 |
-d '{
|
| 108 |
"model": "Soloman2002/hermit-code-7b",
|
| 109 |
"messages": [
|
| 110 |
-
{"role": "
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
}'
|
| 113 |
```
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
### Inference API
|
| 116 |
|
|
|
|
|
|
|
| 117 |
```python
|
| 118 |
from huggingface_hub import InferenceClient
|
| 119 |
|
| 120 |
client = InferenceClient(token="hf_YOUR_TOKEN")
|
| 121 |
-
|
|
|
|
| 122 |
model="Soloman2002/hermit-code-7b",
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
| 126 |
)
|
|
|
|
|
|
|
| 127 |
```
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
<details>
|
| 132 |
-
<summary><b>Python</b> β Quick Sort</summary>
|
| 133 |
|
| 134 |
```python
|
| 135 |
-
def quick_sort(arr):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
if len(arr) <= 1:
|
| 137 |
return arr
|
|
|
|
| 138 |
pivot = arr[len(arr) // 2]
|
| 139 |
left = [x for x in arr if x < pivot]
|
| 140 |
middle = [x for x in arr if x == pivot]
|
| 141 |
right = [x for x in arr if x > pivot]
|
|
|
|
| 142 |
return quick_sort(left) + middle + quick_sort(right)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
</details>
|
| 145 |
|
| 146 |
<details>
|
| 147 |
-
<summary><b>Rust</b> β Palindrome
|
| 148 |
|
| 149 |
```rust
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
fn is_palindrome(s: &str) -> bool {
|
| 151 |
-
let chars: Vec<char> = s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
let len = chars.len();
|
| 153 |
for i in 0..len / 2 {
|
| 154 |
-
if chars[i]
|
| 155 |
return false;
|
| 156 |
}
|
| 157 |
}
|
| 158 |
true
|
| 159 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
</details>
|
| 162 |
|
| 163 |
<details>
|
| 164 |
-
<summary><b>Go</b> β Merge Sorted Arrays</summary>
|
| 165 |
|
| 166 |
```go
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
func mergeSorted(a, b []int) []int {
|
| 168 |
result := make([]int, 0, len(a)+len(b))
|
| 169 |
i, j := 0, 0
|
|
|
|
|
|
|
| 170 |
for i < len(a) && j < len(b) {
|
| 171 |
if a[i] < b[j] {
|
| 172 |
result = append(result, a[i])
|
|
@@ -176,30 +341,125 @@ func mergeSorted(a, b []int) []int {
|
|
| 176 |
j++
|
| 177 |
}
|
| 178 |
}
|
|
|
|
|
|
|
| 179 |
result = append(result, a[i:]...)
|
| 180 |
result = append(result, b[j:]...)
|
|
|
|
| 181 |
return result
|
| 182 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
</details>
|
| 185 |
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|---|---|
|
| 190 |
-
| HumanEval (Python) | TBD |
|
| 191 |
-
| HumanEval (Multi-Lang) | TBD |
|
| 192 |
-
| MBPP | TBD |
|
| 193 |
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
-
|
| 197 |
|
| 198 |
-
|
| 199 |
-
- **Hermit AI Agent** β Built by the [Hermit Team](https://github.com/Soloman2002)
|
| 200 |
|
| 201 |
---
|
| 202 |
|
| 203 |
-
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- coding-agent
|
| 7 |
- instruction-tuned
|
| 8 |
- hermit-code
|
| 9 |
+
- qwen2.5-coder
|
| 10 |
+
- text-generation
|
| 11 |
+
- python
|
| 12 |
+
- javascript
|
| 13 |
+
- rust
|
| 14 |
+
- go
|
| 15 |
pipeline_tag: text-generation
|
| 16 |
---
|
| 17 |
|
| 18 |
+
<div align="center">
|
| 19 |
+
|
| 20 |
+
<!-- Hero Banner -->
|
| 21 |
+
<h1>
|
| 22 |
+
<img src="https://img.shields.io/badge/π-Hermit%20Code%207B-2ea44f?style=for-the-badge&logoColor=white" alt="Hermit Code 7B"/>
|
| 23 |
+
</h1>
|
| 24 |
+
|
| 25 |
+
<p><em>The official coding model for the <strong>Hermit AI Agent</strong></em></p>
|
| 26 |
|
| 27 |
+
<!-- Animated-style Status Badges -->
|
| 28 |
+
<p>
|
| 29 |
+
<img src="https://img.shields.io/badge/β‘-7.6B%20Parameters-3b82f6?style=flat-square" alt="Parameters"/>
|
| 30 |
+
<img src="https://img.shields.io/badge/π-128K%20Context-10b981?style=flat-square" alt="Context"/>
|
| 31 |
+
<img src="https://img.shields.io/badge/π-Apache%202.0-f59e0b?style=flat-square" alt="License"/>
|
| 32 |
+
<img src="https://img.shields.io/badge/πΎ-Safetensors%20BF16-f97316?style=flat-square" alt="Format"/>
|
| 33 |
+
<img src="https://img.shields.io/badge/π-Python%203.10%2B-3776ab?style=flat-square" alt="Python"/>
|
| 34 |
+
</p>
|
| 35 |
|
| 36 |
+
<p>
|
| 37 |
+
<a href="#-quick-start"><img src="https://img.shields.io/badge/π%20Quick%20Start-5865F2?style=for-the-badge&logoColor=white" height="28"/></a>
|
| 38 |
+
<a href="#-capabilities"><img src="https://img.shields.io/badge/π―%20Capabilities-5865F2?style=for-the-badge&logoColor=white" height="28"/></a>
|
| 39 |
+
<a href="#-usage"><img src="https://img.shields.io/badge/π»%20Usage-5865F2?style=for-the-badge&logoColor=white" height="28"/></a>
|
| 40 |
+
<a href="#-benchmarks"><img src="https://img.shields.io/badge/π%20Benchmarks-5865F2?style=for-the-badge&logoColor=white" height="28"/></a>
|
|
|
|
|
|
|
| 41 |
</p>
|
| 42 |
|
| 43 |
+
</div>
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## π Table of Contents
|
| 48 |
+
|
| 49 |
+
- [Quick Start](#-quick-start)
|
| 50 |
+
- [Capabilities](#-capabilities)
|
| 51 |
+
- [Model Details](#-model-details)
|
| 52 |
+
- [Usage](#-usage)
|
| 53 |
+
- [Transformers](#transformers)
|
| 54 |
+
- [vLLM (Production)](#vllm-recommended-for-production)
|
| 55 |
+
- [Inference API](#inference-api)
|
| 56 |
+
- [Interactive Examples](#-interactive-examples)
|
| 57 |
+
- [Benchmarks](#-benchmarks)
|
| 58 |
+
- [Acknowledgments](#-acknowledgments)
|
| 59 |
+
|
| 60 |
---
|
| 61 |
|
| 62 |
+
## π Quick Start
|
| 63 |
+
|
| 64 |
+
Get up and running in **3 lines of code**:
|
| 65 |
|
| 66 |
```python
|
| 67 |
from transformers import pipeline
|
| 68 |
|
| 69 |
+
# Initialize the model
|
| 70 |
pipe = pipeline("text-generation", model="Soloman2002/hermit-code-7b")
|
| 71 |
+
|
| 72 |
+
# Start coding
|
| 73 |
+
chat = [{"role": "user", "content": "Write a Python function to reverse a linked list"}]
|
| 74 |
+
response = pipe(chat, max_new_tokens=512)
|
| 75 |
+
|
| 76 |
+
print(response[0]["generated_text"][-1]["content"])
|
| 77 |
```
|
| 78 |
|
| 79 |
+
> π‘ **Tip:** For best results, use `temperature=0.2` and `top_p=0.95` for deterministic code generation.
|
| 80 |
+
|
| 81 |
+
---
|
| 82 |
+
|
| 83 |
+
## π― Capabilities
|
| 84 |
+
|
| 85 |
+
<div align="center">
|
| 86 |
+
|
| 87 |
+
| π» **Languages** | ποΈ **Code Gen** | π **Explain** | π **Debug** | β‘ **Refactor** | π§ **Context** |
|
| 88 |
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
| 89 |
+
| Python | Functions | Breakdowns | Bug Finding | Performance | 128K Tokens |
|
| 90 |
+
| JavaScript / TypeScript | Classes | Documentation | Fixing | Cleanup | Multi-file |
|
| 91 |
+
| Go | Scripts | Architecture | Optimization | Restructuring | Projects |
|
| 92 |
+
| Rust | Full Projects | Best Practices | Analysis | Modernization | Understanding |
|
| 93 |
+
| C++ | | | | | |
|
| 94 |
+
| Java | | | | | |
|
| 95 |
+
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
### β¨ What Makes Hermit Code Special?
|
| 99 |
+
|
| 100 |
+
- **π Multi-Language Mastery** β Native fluency in 6+ programming languages
|
| 101 |
+
- **π¦ Project-Scale Context** β Understand entire codebases with 128K token context
|
| 102 |
+
- **π Debugging Expert** β Identifies bugs, explains why they happen, and fixes them
|
| 103 |
+
- **π Educational** β Explains complex concepts with clear, step-by-step reasoning
|
| 104 |
+
- **βοΈ Production-Ready** β Optimized for both research and deployment via vLLM
|
| 105 |
+
|
| 106 |
+
---
|
| 107 |
+
|
| 108 |
+
## π§ Model Details
|
| 109 |
+
|
| 110 |
+
<div align="center">
|
| 111 |
|
| 112 |
+
| Property | Specification | Notes |
|
| 113 |
+
|:---|:---|:---|
|
| 114 |
+
| **Base Model** | [Qwen/Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct) | State-of-the-art code foundation |
|
| 115 |
+
| **Architecture** | Qwen2.5 Dense Transformer | Optimized for code understanding |
|
| 116 |
+
| **Parameters** | 7.61B (6.53B non-embedding) | Efficient size-to-performance ratio |
|
| 117 |
+
| **Layers** | 28 | Deep representation learning |
|
| 118 |
+
| **Attention** | GQA β 28 Q heads, 4 KV heads | Fast inference with grouped queries |
|
| 119 |
+
| **Context Length** | 131,072 tokens | ~100K+ lines of code context |
|
| 120 |
+
| **License** | Apache 2.0 | Commercial use permitted |
|
| 121 |
+
| **Format** | Safetensors (BF16) | Safe, efficient serialization |
|
| 122 |
|
| 123 |
+
</div>
|
| 124 |
|
| 125 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
## π» Usage
|
| 128 |
|
| 129 |
### Transformers
|
| 130 |
|
| 131 |
+
Perfect for **prototyping** and **local development**:
|
| 132 |
+
|
| 133 |
```python
|
| 134 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 135 |
+
import torch
|
| 136 |
|
| 137 |
+
# Load model and tokenizer
|
| 138 |
+
model_id = "Soloman2002/hermit-code-7b"
|
| 139 |
model = AutoModelForCausalLM.from_pretrained(
|
| 140 |
+
model_id,
|
| 141 |
+
torch_dtype=torch.bfloat16,
|
| 142 |
device_map="auto"
|
| 143 |
)
|
| 144 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 145 |
|
| 146 |
+
# Prepare chat messages
|
| 147 |
messages = [
|
| 148 |
+
{"role": "system", "content": "You are Hermit Code, an expert coding assistant."},
|
| 149 |
{"role": "user", "content": "Write a Rust function that checks if a string is a palindrome."}
|
| 150 |
]
|
| 151 |
+
|
| 152 |
+
# Apply chat template
|
| 153 |
text = tokenizer.apply_chat_template(
|
| 154 |
+
messages,
|
| 155 |
+
tokenize=False,
|
| 156 |
+
add_generation_prompt=True
|
| 157 |
)
|
| 158 |
+
|
| 159 |
+
# Generate
|
| 160 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 161 |
+
outputs = model.generate(
|
| 162 |
+
**inputs,
|
| 163 |
+
max_new_tokens=512,
|
| 164 |
+
temperature=0.2,
|
| 165 |
+
do_sample=True
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
# Decode response
|
| 169 |
+
response = tokenizer.decode(
|
| 170 |
+
outputs[0][inputs.input_ids.shape[1]:],
|
| 171 |
+
skip_special_tokens=True
|
| 172 |
+
)
|
| 173 |
print(response)
|
| 174 |
```
|
| 175 |
|
| 176 |
+
---
|
| 177 |
+
|
| 178 |
### vLLM (Recommended for Production)
|
| 179 |
|
| 180 |
+
For **high-throughput** serving and API deployment:
|
| 181 |
+
|
| 182 |
+
**1. Install & Launch:**
|
| 183 |
```bash
|
| 184 |
pip install vllm
|
| 185 |
+
vllm serve "Soloman2002/hermit-code-7b" --dtype bfloat16
|
| 186 |
```
|
| 187 |
|
| 188 |
+
**2. Query via API:**
|
| 189 |
```bash
|
| 190 |
curl -X POST "http://localhost:8000/v1/chat/completions" \
|
| 191 |
-H "Content-Type: application/json" \
|
| 192 |
-d '{
|
| 193 |
"model": "Soloman2002/hermit-code-7b",
|
| 194 |
"messages": [
|
| 195 |
+
{"role": "system", "content": "You are Hermit Code, a coding assistant."},
|
| 196 |
+
{"role": "user", "content": "Explain closures in JavaScript with examples."}
|
| 197 |
+
],
|
| 198 |
+
"temperature": 0.2,
|
| 199 |
+
"max_tokens": 512
|
| 200 |
}'
|
| 201 |
```
|
| 202 |
|
| 203 |
+
> π **vLLM Benefits:** Continuous batching, PagedAttention, and 10-20x throughput improvement over standard Transformers.
|
| 204 |
+
|
| 205 |
+
---
|
| 206 |
+
|
| 207 |
### Inference API
|
| 208 |
|
| 209 |
+
Use **Hugging Face's hosted infrastructure** for instant access:
|
| 210 |
+
|
| 211 |
```python
|
| 212 |
from huggingface_hub import InferenceClient
|
| 213 |
|
| 214 |
client = InferenceClient(token="hf_YOUR_TOKEN")
|
| 215 |
+
|
| 216 |
+
response = client.chat_completion(
|
| 217 |
model="Soloman2002/hermit-code-7b",
|
| 218 |
+
messages=[
|
| 219 |
+
{"role": "user", "content": "Write a Go function to merge two sorted arrays"}
|
| 220 |
+
],
|
| 221 |
+
max_tokens=512,
|
| 222 |
+
temperature=0.2,
|
| 223 |
+
stream=False
|
| 224 |
)
|
| 225 |
+
|
| 226 |
+
print(response.choices[0].message.content)
|
| 227 |
```
|
| 228 |
|
| 229 |
+
---
|
| 230 |
+
|
| 231 |
+
## π¨ Interactive Examples
|
| 232 |
+
|
| 233 |
+
Click any language below to expand and see Hermit Code in action:
|
| 234 |
|
| 235 |
<details>
|
| 236 |
+
<summary><b>π Python</b> β Quick Sort Implementation</summary>
|
| 237 |
|
| 238 |
```python
|
| 239 |
+
def quick_sort(arr: list[int]) -> list[int]:
|
| 240 |
+
"""
|
| 241 |
+
Sorts an array using the quicksort algorithm.
|
| 242 |
+
Time Complexity: O(n log n) average, O(nΒ²) worst case
|
| 243 |
+
Space Complexity: O(log n) due to recursion
|
| 244 |
+
"""
|
| 245 |
if len(arr) <= 1:
|
| 246 |
return arr
|
| 247 |
+
|
| 248 |
pivot = arr[len(arr) // 2]
|
| 249 |
left = [x for x in arr if x < pivot]
|
| 250 |
middle = [x for x in arr if x == pivot]
|
| 251 |
right = [x for x in arr if x > pivot]
|
| 252 |
+
|
| 253 |
return quick_sort(left) + middle + quick_sort(right)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
# Example usage
|
| 257 |
+
if __name__ == "__main__":
|
| 258 |
+
data = [3, 6, 8, 10, 1, 2, 1]
|
| 259 |
+
print(f"Original: {data}")
|
| 260 |
+
print(f"Sorted: {quick_sort(data)}")
|
| 261 |
```
|
| 262 |
+
|
| 263 |
+
**Key Features Demonstrated:**
|
| 264 |
+
- β
Type hints for better code clarity
|
| 265 |
+
- β
Docstrings with complexity analysis
|
| 266 |
+
- β
Recursive divide-and-conquer approach
|
| 267 |
+
- β
Idiomatic Python list comprehensions
|
| 268 |
+
|
| 269 |
</details>
|
| 270 |
|
| 271 |
<details>
|
| 272 |
+
<summary><b>π¦ Rust</b> β Palindrome Checker</summary>
|
| 273 |
|
| 274 |
```rust
|
| 275 |
+
/// Checks if a string is a palindrome, ignoring non-alphanumeric characters
|
| 276 |
+
/// and case differences.
|
| 277 |
+
///
|
| 278 |
+
/// # Examples
|
| 279 |
+
/// ```
|
| 280 |
+
/// assert!(is_palindrome("A man, a plan, a canal: Panama"));
|
| 281 |
+
/// assert!(!is_palindrome("Hello, World!"));
|
| 282 |
+
/// ```
|
| 283 |
fn is_palindrome(s: &str) -> bool {
|
| 284 |
+
let chars: Vec<char> = s
|
| 285 |
+
.chars()
|
| 286 |
+
.filter(|c| c.is_alphanumeric())
|
| 287 |
+
.map(|c| c.to_ascii_lowercase())
|
| 288 |
+
.collect();
|
| 289 |
+
|
| 290 |
let len = chars.len();
|
| 291 |
for i in 0..len / 2 {
|
| 292 |
+
if chars[i] != chars[len - 1 - i] {
|
| 293 |
return false;
|
| 294 |
}
|
| 295 |
}
|
| 296 |
true
|
| 297 |
}
|
| 298 |
+
|
| 299 |
+
fn main() {
|
| 300 |
+
let test_cases = vec![
|
| 301 |
+
"racecar",
|
| 302 |
+
"A man, a plan, a canal: Panama",
|
| 303 |
+
"Hello, World!",
|
| 304 |
+
];
|
| 305 |
+
|
| 306 |
+
for case in test_cases {
|
| 307 |
+
println!("'{}' -> {}", case, is_palindrome(case));
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
```
|
| 311 |
+
|
| 312 |
+
**Key Features Demonstrated:**
|
| 313 |
+
- β
Memory-safe string processing
|
| 314 |
+
- β
Functional iterator chains
|
| 315 |
+
- β
Comprehensive documentation
|
| 316 |
+
- β
Efficient two-pointer comparison
|
| 317 |
+
|
| 318 |
</details>
|
| 319 |
|
| 320 |
<details>
|
| 321 |
+
<summary><b>πΉ Go</b> β Merge Sorted Arrays</summary>
|
| 322 |
|
| 323 |
```go
|
| 324 |
+
package main
|
| 325 |
+
|
| 326 |
+
import "fmt"
|
| 327 |
+
|
| 328 |
+
// mergeSorted combines two sorted integer slices into a single sorted slice.
|
| 329 |
+
// It runs in O(n + m) time where n and m are the lengths of the inputs.
|
| 330 |
func mergeSorted(a, b []int) []int {
|
| 331 |
result := make([]int, 0, len(a)+len(b))
|
| 332 |
i, j := 0, 0
|
| 333 |
+
|
| 334 |
+
// Merge while both arrays have elements
|
| 335 |
for i < len(a) && j < len(b) {
|
| 336 |
if a[i] < b[j] {
|
| 337 |
result = append(result, a[i])
|
|
|
|
| 341 |
j++
|
| 342 |
}
|
| 343 |
}
|
| 344 |
+
|
| 345 |
+
// Append remaining elements
|
| 346 |
result = append(result, a[i:]...)
|
| 347 |
result = append(result, b[j:]...)
|
| 348 |
+
|
| 349 |
return result
|
| 350 |
}
|
| 351 |
+
|
| 352 |
+
func main() {
|
| 353 |
+
a := []int{1, 3, 5, 7}
|
| 354 |
+
b := []int{2, 4, 6, 8}
|
| 355 |
+
|
| 356 |
+
merged := mergeSorted(a, b)
|
| 357 |
+
fmt.Printf("Merged: %v\n", merged) // [1 2 3 4 5 6 7 8]
|
| 358 |
+
}
|
| 359 |
```
|
| 360 |
+
|
| 361 |
+
**Key Features Demonstrated:**
|
| 362 |
+
- β
Pre-allocated slices for zero-allocation growth
|
| 363 |
+
- β
Two-pointer technique for optimal performance
|
| 364 |
+
- β
Idiomatic Go error-free design
|
| 365 |
+
- β
Clean, readable control flow
|
| 366 |
+
|
| 367 |
</details>
|
| 368 |
|
| 369 |
+
<details>
|
| 370 |
+
<summary><b>β‘ JavaScript</b> β Closure Example</summary>
|
| 371 |
+
|
| 372 |
+
```javascript
|
| 373 |
+
/**
|
| 374 |
+
* Creates a counter with private state using closures.
|
| 375 |
+
* Demonstrates lexical scoping and data encapsulation.
|
| 376 |
+
*/
|
| 377 |
+
function createCounter(initialValue = 0) {
|
| 378 |
+
let count = initialValue; // Private variable
|
| 379 |
+
|
| 380 |
+
return {
|
| 381 |
+
increment() {
|
| 382 |
+
count += 1;
|
| 383 |
+
return count;
|
| 384 |
+
},
|
| 385 |
+
decrement() {
|
| 386 |
+
count -= 1;
|
| 387 |
+
return count;
|
| 388 |
+
},
|
| 389 |
+
getValue() {
|
| 390 |
+
return count;
|
| 391 |
+
},
|
| 392 |
+
reset() {
|
| 393 |
+
count = initialValue;
|
| 394 |
+
return count;
|
| 395 |
+
}
|
| 396 |
+
};
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
// Usage
|
| 400 |
+
const counter = createCounter(10);
|
| 401 |
+
console.log(counter.increment()); // 11
|
| 402 |
+
console.log(counter.increment()); // 12
|
| 403 |
+
console.log(counter.getValue()); // 12
|
| 404 |
+
console.log(counter.reset()); // 10
|
| 405 |
+
```
|
| 406 |
+
|
| 407 |
+
**Key Features Demonstrated:**
|
| 408 |
+
- β
True private state via closures
|
| 409 |
+
- β
Clean object interface
|
| 410 |
+
- β
ES6 method shorthand syntax
|
| 411 |
+
- β
Default parameter values
|
| 412 |
+
|
| 413 |
+
</details>
|
| 414 |
+
|
| 415 |
+
---
|
| 416 |
+
|
| 417 |
+
## π Benchmarks
|
| 418 |
|
| 419 |
+
<div align="center">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
|
| 421 |
+
| Benchmark | Score | Status | Comparison to Base |
|
| 422 |
+
|:---|:---:|:---:|:---|
|
| 423 |
+
| **HumanEval (Python)** | *TBD* | π Pending | vs Qwen2.5-Coder-7B |
|
| 424 |
+
| **HumanEval (Multi-Lang)** | *TBD* | π Pending | vs Qwen2.5-Coder-7B |
|
| 425 |
+
| **MBPP (Python)** | *TBD* | π Pending | vs Qwen2.5-Coder-7B |
|
| 426 |
+
| **DS-1000 (Data Science)** | *TBD* | π Pending | vs Qwen2.5-Coder-7B |
|
| 427 |
|
| 428 |
+
</div>
|
| 429 |
|
| 430 |
+
> π **Coming Soon:** Comprehensive evaluation results based on the Qwen2.5-Coder-7B-Instruct baseline with additional fine-tuning for agentic coding workflows.
|
|
|
|
| 431 |
|
| 432 |
---
|
| 433 |
|
| 434 |
+
## π€ Acknowledgments
|
| 435 |
+
|
| 436 |
+
<div align="center">
|
| 437 |
+
|
| 438 |
+
| Contribution | Team / Resource | Link |
|
| 439 |
+
|:---|:---|:---|
|
| 440 |
+
| **ποΈ Base Model** | Qwen Team | [Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct) |
|
| 441 |
+
| **π€ Hermit AI Agent** | Hermit Team | [GitHub: Soloman2002](https://github.com/Soloman2002) |
|
| 442 |
+
| **π¦ Infrastructure** | Hugging Face | [Transformers](https://github.com/huggingface/transformers) & [vLLM](https://github.com/vllm-project/vllm) |
|
| 443 |
+
|
| 444 |
+
</div>
|
| 445 |
+
|
| 446 |
+
---
|
| 447 |
+
|
| 448 |
+
<div align="center">
|
| 449 |
+
|
| 450 |
+
## π Star Us on GitHub!
|
| 451 |
+
|
| 452 |
+
If you find Hermit Code useful, please consider starring the repository and sharing with your network.
|
| 453 |
+
|
| 454 |
+
<p>
|
| 455 |
+
<a href="https://github.com/Soloman2002/hermit-code-7b">
|
| 456 |
+
<img src="https://img.shields.io/badge/β-Star%20on%20GitHub-181717?style=for-the-badge&logo=github" alt="Star on GitHub"/>
|
| 457 |
+
</a>
|
| 458 |
+
<a href="https://huggingface.co/Soloman2002/hermit-code-7b">
|
| 459 |
+
<img src="https://img.shields.io/badge/π€-Follow%20on%20HF-FFD21E?style=for-the-badge" alt="Follow on Hugging Face"/>
|
| 460 |
+
</a>
|
| 461 |
</p>
|
| 462 |
+
|
| 463 |
+
<sub>Built with β€οΈ for the coding community by the Hermit Team</sub>
|
| 464 |
+
|
| 465 |
+
</div>
|