How To Use Code Llama

Codecademy Team
Learn how Code Llama compares to other coding-specific generative AI


Generative AI is almost capable of entirely automating code generation but it isn’t quite there yet. However, Code Llama is the next best tool! Released in 2023, Meta’s newest code generator, Code Llama, is here to help a coder in any of their programming endeavors. Code Llama aims to assist in developer workflows, code generation, completion, and testing. Let’s discuss Code Llama as an individual asset and then compare it to other coding-specific generative AI available.

Code Llama’s Capabilities

Code Llama is a code-specialized large-language model (LLM) that includes three specific prompting models as well as language-specific variations.

Code Llama comes in three models: 7Billion, 13B, and 34B parameter versions. More parameters mean greater complexity and capability but require higher computational power. The 7B and 13B are good for lower latency tasks, such as code completion. The 34B version provides the best results for code generation and development.

Code Llama offers support for development in various programming languages, such as Python, Java, C++, Bash, PHP, Typescript, and C#. It is available in two versions:

  • Code Llama – Python
  • Code Llama – Instruct

The Python variant is specialized for Python development, specifically trained on Python datasets to deliver excellent results. The Instruct variant is designed to enhance the understanding of natural language queries. For example, a beginner can request Code Llama to generate code from a natural language, such as English.

Code Llama is not available directly through a website or platform. Instead, Code Llama is available on GitHub and can be downloaded locally. Here are some of the ways Code Llama can be accessed:

  • Chatbot: Perplexity-AI is a text-based AI used to answer questions, similar to ChatGPT. Recently, Perplexity AI integrated Code Llama’s 34B parameter version, creating a platform for users to generate code through text-based prompting. It has multiple variants focused on specific programming languages: Python, Java, C++, and Javascript.

  • Model Integration: Hugging Face is an open-source platform for the community to host AI models. It does have default models you can use to generate code easily.

  • Integrated Development Environment (IDE): Ollama is a library of Code Llama we can download directly and integrate into our IDE. It allows us to use large language models locally.

In this tutorial, we will use Perplexity AI to demonstrate Code Llama’s capabilities. We will define and create sorting functions. First, we’ll begin by creating a binary sort function. A binary sort function is similar to insertion sort but it uses binary search to locate where an element should go. Next, we’ll ask Perplexity if any other algorithms compare to binary sort. Finally, we’ll then ask Perplexity to create a Sorting class that contains some of those functions.


I have a Python class that would benefit from a binary sorting algorithm. Could you please create a Python class that takes in a list of values, sorts them using binary sort, and returns the sorted list. 


Here's a Python class that implements the binary sort algorithm: 

class BinarySort: 
    def __init__(self, arr): 
        self.arr = arr 

    def sort(self): 
        for i in range(1, len(self.arr)): 
            key = self.arr[i] 
            left, right = 0, i - 1 
            while left <= right: 
                mid = (left + right) // 2 
                if self.arr[mid] < key: 
                    left = mid + 1 
                    right = mid - 1 

            # Insert the key at the correct position 
            self.arr[left + 1:i + 1] = self.arr[left:i] 
            self.arr[left] = key 

        return self.arr 

This `BinarySort` class takes a list of values as input, sorts them using binary sort, and returns the sorted list. You can use it as shown in the example usage. The `sort()` method of the class sorts the list in-place and returns the sorted version. 


Is there another algorithm comparable or better than binary sort? 


Yes, there are several sorting algorithms that are comparable or better than binary sort, depending on the specific use case and the characteristics of the data being sorted. Some of the most commonly used sorting algorithms include: 

- Quick sort: This is a fast and efficient sorting algorithm that works by selecting a pivot element and partitioning the list around the pivot.  

- Merge sort: This is a divide-and-conquer sorting algorithm that works by dividing the list into two halves, sorting each half, and then merging the two sorted halves back together. 

- Heap sort: This is a sorting algorithm that works by building a max-heap and then repeatedly removing the largest element from the heap and placing it at the end of the list.  


I'd actually like to have sorting options for my needs. Can you create a Sorting class with binary sort, quick sort, and merge sort functionality? 


Sure, I can help you with that. Here is a simple Python class that implements binary sort, quick sort, and merge sort functionality: 

class Sorting: 
    def __init__(self): 

    def binary_sort(self): 
        def binary_insertion_sort(arr): 
            for i in range(1, len(arr)): 
                key = arr[i] 
                left, right = 0, i - 1 
                while left <= right: 
                    mid = (left + right) // 2 
                    if arr[mid] < key: 
                        left = mid + 1 
                        right = mid - 1 
                arr[left + 1:i + 1] = arr[left:i] 
                arr[left] = key 
        return self.arr 

    def quick_sort(self): 
        def partition(arr, low, high): 
            pivot = arr[high] 
            i = low - 1 
            for j in range(low, high): 
                if arr[j] < pivot: 
                    i += 1 
                    arr[i], arr[j] = arr[j], arr[i] 
            arr[i + 1], arr[high] = arr[high], arr[i + 1] 
            return i + 1 
        def quicksort(arr, low, high): 
            if low < high: 
                pivot_index = partition(arr, low, high) 
                quicksort(arr, low, pivot_index - 1) 
                quicksort(arr, pivot_index + 1, high) 
        quicksort(self.arr, 0, len(self.arr) - 1) 
        return self.arr 
    def merge_sort(self): 
        def merge(left, right): 
            result = [] 
            i = j = 0 
            while i < len(left) and j < len(right): 
                if left[i] < right[j]: 
                    i += 1 
                    j += 1 
            return result 

        if len(self.arr) <= 1: 
            return self.arr 
        mid = len(self.arr) // 2 
        left = self.arr[:mid] 
        right = self.arr[mid:] 
        left = Sorting(left).merge_sort() 
        right = Sorting(right).merge_sort() 
        return merge(left, right) 

This class has three methods, `binary_sort()`, `quick_sort()`, and `merge_sort()`, which implement the binary sort, quick sort, and merge sort algorithms, respectively. 

Code Llama is a great development tool for both beginners and experts. It can complete code, provide comments, and even solve some of our programming problems. With its varying models, there isn’t a problem we can’t solve. Let’s see how it compares to other generative AI.

Code Llama Comparatively

Code Llama has some incredible features, but how does it compare to other programming AI tools? Let’s take a look at some statistics comparing GitHub CoPilot, ChatGPT, and Meta’s newest AI, Code Llama.

GitHub CoPilot Code Llama ChatGPT
Developer GitHub Meta University of California, Berkeley
Training Data Natural language + 100GB of GitHub Code 100GB of code snippets 100GB of text conversations
Supported Programming Languages Most all Languages Most all Languages Common Languages and some Uncommon
Model Sizes Individuals + Businesses 7B, 13B, 34B parameter versions
Prompt Sizing 1024 1024 characters 4096 characters
Context Window 8k 100k 16k
Code Location Cloud-based Local

Here’s a concise summary of the AI code-generating tools:

ChatGPT: Although ChatGPT isn’t a programming-specific AI tool, it can help with basic needs. It is capable of assisting with the use of common programming languages at a basic level. ChatGPT doesn’t have all the fancy programming features its competitors but it can assist in completing basic programming problems.

GitHub CoPilot: CoPilot is an AI programming tool available for individuals and businesses. Its design is to help our coding needs by assisting in code completion, code generation, and support. It is trained on the data within GitHub, providing a more extensive training set allowing CoPilot to be familiar with more uncommon programming languages.

Code Llama: Code Llama is a local AI programming tool with different options depending on our programming needs. Not only does it provide multiple parameters, but it also has language-dependent options. Trained on a lot of code, it focuses on the more common languages.

In summary, Code Llama is a strong competitor as an AI programming tool! It is capable of most of our programming needs in a localized fashion. Since there is no website or tool to use Code Llama directly, there are websites that have imported it for us to use or we can import it ourselves.


Code Llama is a unique tool capable of assisting with our programming projects. Code Llama allows us to shift our focus from code generation to project objectives. It can help in code completion, writing human-readable comments in our code, and even generating code for us.

Comparatively, Code Llama is a strong competitor as an AI programming tool, especially with offline capability. We can import this tool into an IDE and don’t even need the internet! It is trained on 100GB of data and can help with code completion and generation. There are quite a few options for Code Llama to include 7B, 13B, and 43B parameter versions, -Python, and -Instruct to name a few. Take your pick and good luck on your programming endeavors!

If you are interested in reading more about how generative AI can be applied in your daily life, please check out our AI Catalog of articles!