A large language model that can use text prompts to generate and discuss code。

7b 13b 34b 70b

1.7M 6 months ago

Readme

Code Llama is a model for generating and discussing code, built on top of Llama 2。它旨在使开发人员的工作流程更快更高效,并使人们更容易学习如何编写代码。它可以生成代码和关于代码的自然语言。Code Llama 支持当今使用的大多数流行编程语言,包括 Python、C++、Java、PHP、Typescript (Javascript)、C#、Bash 等。

Parameter counts

Parameter Count
7 billion View ollama run codellama:7b
13 billion View ollama run codellama:13b
34 billion View ollama run codellama:34b
70 billion View ollama run codellama:70b

Usage

CLI

ollama run codellama "Write me a function that outputs the fibonacci sequence"

API

curl -X POST http://127.0.0.1:11434/api/generate -d '{
  "model": "codellama",
  "prompt": "Write me a function that outputs the fibonacci sequence"
}'

Variations

instruct Fine-tuned to generate helpful and safe answers in natural language
python A specialized variation of Code Llama further fine-tuned on 100B tokens of Python code
code Base model for code completion

Example prompts

Ask questions

ollama run codellama:7b-instruct 'You are an expert programmer that writes simple, concise code and explanations. Write a python function to generate the nth fibonacci number.'

Fill-in-the-middle (FIM) or infill

ollama run codellama:7b-code '<PRE> def compute_gcd(x, y): <SUF>return result <MID>'

Fill-in-the-middle (FIM) is a special prompt format supported by the code completion model can complete code between two already written code blocks。Code Llama expects a specific format for infilling code

<PRE> {prefix} <SUF>{suffix} <MID>

<PRE><SUF><MID> 是引导模型的特殊 token。

Code review

ollama run codellama '
Where is the bug in this code?

def fib(n):
    if n <= 0:
        return n
    else:
        return fib(n-1) + fib(n-2)
'

Writing tests

ollama run codellama "write a unit test for this function: $(cat example.py)"

Code completion

ollama run codellama:7b-code '# A simple python function to remove whitespace from a string:'

More information