CodeNinja is an enhanced version of the renowned model
openchat/openchat-3.5-1210. It having been fine-tuned through Supervised Fine Tuning on two expansive datasets, encompassing over 400,000 coding instructions. Designed to be an indispensable tool for coders, CodeNinja aims to integrate seamlessly into your daily coding routine.
-
Expansive Training Database: CodeNinja has been refined with datasets from
glaiveai/glaive-code-assistant-v2 and
TokenBender/code_instructions_122k_alpaca_style, incorporating around 400,000 coding instructions across various languages including Python, C, C++, Rust, Java, JavaScript, and more.
-
Flexibility and Scalability: Available in a 7B model size, CodeNinja is adaptable for local runtime environments.
-
Advanced Code Completion: With a substantial context window size of 8192, it supports comprehensive project-level code completion.
CodeNinja maintains the same prompt structure as OpenChat 3.5. Effective utilization requires adherence to this format:
The simplest way to engage with CodeNinja is via the
quantized versions on
LM Studio. Ensure you select the "OpenChat" preset, which incorporates the necessary prompt format. The preset is also available in this
gist.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Initialize the model
5model_path = "beowolx/CodeNinja-1.0-OpenChat-7B"
6model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
7# Load the OpenChat tokenizer
8tokenizer = AutoTokenizer.from_pretrained("openchat/openchat-3.5-1210", use_fast=True)
9
10def generate_one_completion(prompt: str):
11 messages = [
12 {"role": "user", "content": prompt},
13 {"role": "assistant", "content": ""} # Model response placeholder
14 ]
15
16 # Generate token IDs using the chat template
17 input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
18
19 # Produce completion
20 generate_ids = model.generate(
21 torch.tensor([input_ids]).to("cuda"),
22 max_length=256,
23 pad_token_id=tokenizer.pad_token_id,
24 eos_token_id=tokenizer.eos_token_id
25 )
26
27 # Process the completion
28 completion = tokenizer.decode(generate_ids[0], skip_special_tokens=True)
29 completion = completion.split("\n\n\n")[0].strip()
30
31 return completion
CodeNinja is licensed under the MIT License, with model usage subject to the Model License.
For queries or support, please open an issue in the repository.