Views
No views yet

1# pip install transformers
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_id = "CohereLabs/North-Mini-Code-1.0"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id)
7
8prompt = "Write a python program to check if a string is a palindrome or not."
9
10# Format message with the North-Mini-Code-1.0 chat template
11messages = [{"role": "user", "content": prompt}]
12input_ids = tokenizer.apply_chat_template(
13 messages,
14 tokenize=True,
15 add_generation_prompt=True,
16 return_tensors="pt",
17)
18
19gen_tokens = model.generate(
20 **input_ids,
21 max_new_tokens=1024,
22 do_sample=True,
23 temperature=1.0,
24 top_p=0.95
25)
26
27gen_text = tokenizer.decode(gen_tokens[0])
28print(gen_text)pipeline abstraction:1from transformers import pipeline
2import torch
3
4model_id = "CohereLabs/North-Mini-Code-1.0"
5
6prompt = """Given a list of unique words each of size k and an n sized word, w, where n is a multiple of k,
7Write a program in python to determine the number of unique combinations of words in the list that can be concatenated to form an anagram of the word w.
8"""
9
10pipe = pipeline(
11 "text-generation",
12 model=model_id,
13 torch_dtype="auto",
14 device_map="auto",
15)
16
17messages = [
18 {"role": "user", "content": f"{prompt}"},
19]
20
21text = tokenizer.apply_chat_template(
22 messages,
23 tokenize=False,
24 add_generation_prompt=True,
25)
26
27
28outputs = pipe(
29 messages,
30 max_new_tokens=1024,
31 do_sample=True,
32 temperature=1.0,
33 top_p=0.95
34
35)
36
37print(outputs[0]["generated_text"][-1])
381# Define tools
2tools = [{
3 "type": "function",
4 "function": {
5 "name": "bash",
6 "description": "Execute a bash command in the terminal.",
7 "parameters": {
8 "type": "object",
9 "properties": {
10 "command": {
11 "description": "The bash command to execute.",
12 "type": "string"
13 }
14 },
15 "required": ["command"]
16 },
17 }
18}]
19
20# Define conversation input
21conversation = [{"role": "user", "content": "Find out if there is any json file in this folder"}]
22
23
24# Get the Tool Use prompt
25input_prompt = tokenizer.apply_chat_template(conversation=conversation, tools=tools, tokenize=False, add_generation_prompt=True, return_tensors="pt")
26
27# Tokenize the prompt
28input_ids = tokenizer(input_prompt, return_tensors="pt")1# Pass on the tool_call and thinking
2tool_call = {"name": "bash", "arguments": {"command": "ls -al"}}
3reasoning = "The user wants to find if there are any JSON files in the current folder. I should use the `ls` command to list files and then check if there are any JSON files (files ending with .json). Let me first list the files in the current directory."
4
5conversation.append({"role": "assistant", "tool_calls": [{"id": "0", "type": "function", "function": tool_call}], "reasoning": reasoning})1# This needs to be a dictionary
2tool_result = {"stdout": "test.json\ntest.py", "return_code": "0"}
3
4# Append tool results
5conversation.append({"role": "tool", "tool_call_id": "0", "content": tool_result})generate() again to let the model use the tool result in the chat.1uv pip install "git+https://github.com/vllm-project/vllm.git"
2uv pip install cohere_melody>=0.9.01vllm serve CohereLabs/North-Mini-Code-1.0 \
2 -tp 2 \
3 --max-model-len 320000 \
4 --tool-call-parser cohere_command4 \
5 --reasoning-parser cohere_command4 \
6 --enable-auto-tool-choice1# Example commands to install on linux
2git clone https://github.com/anomalyco/opencode.gitcd opencode
3
4# Install Bun
5curl -fsSL https://bun.sh/install | bash
6export BUN_INSTALL="$HOME/.bun"
7export PATH="$BUN_INSTALL/bin:$PATH"
8
9# node-gyp was needed by a dependency
10bun add -g node-gyp
11
12# Install dependencies
13bun install
14
15# Build CLI
16bun run --cwd packages/opencode build/usr/bin/install -m 755 \
17 ./opencode/packages/opencode/dist/opencode-linux-x64/bin/opencode \
18 /root/.local/bin/opencode1{
2 "$schema": "https://opencode.ai/config.json",
3 "model": "vllm/CohereLabs/North-Mini-Code-1.0",
4 "provider": {
5 "vllm": {
6 "npm": "@ai-sdk/openai-compatible",
7 "name": "Local vLLM server",
8 "options": {
9 "baseURL": "http://127.0.0.1:8000/v1",
10 "apiKey": "EMPTY"
11 },
12 "models": {
13 "North-Mini-Code-1.0": {
14 "name": "North-Mini-Code-1.0",
15 "interleaved": {
16 "field": "reasoning"
17 },
18 "limit": {
19 "context": 256000,
20 "output": 64000
21 }
22 }
23 }
24 }
25 }
26}
27