> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bespokelabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Ollama

> Generate structured data with a local model served by Ollama.

You can use a model served by [Ollama](https://ollama.com) with Curator. This guide generates a list of countries and their capitals.

## Prerequisites

* Python 3.10 or later.
* Curator, installed with `pip install bespokelabs-curator`.
* Ollama, from the [Ollama download page](https://ollama.com/download).

<Steps>
  <Step title="Create an LLM subclass">
    ```python theme={null}
    from pydantic import BaseModel, Field

    from bespokelabs import curator


    class Location(BaseModel):
        country: str = Field(description="The name of the country")
        capital: str = Field(description="The name of the capital city")


    class LocationList(BaseModel):
        locations: list[Location] = Field(description="A list of locations")


    class SimpleOllamaGenerator(curator.LLM):
        response_format = LocationList

        def prompt(self, input: dict) -> str:
            return "Return five countries and their capitals."

        def parse(self, input: dict, response: LocationList) -> list:
            return [{"country": loc.country, "capital": loc.capital} for loc in response.locations]
    ```
  </Step>

  <Step title="Start Ollama">
    Pull a model and start the server.

    ```bash theme={null}
    ollama pull llama3.1:8b
    ollama serve
    ```
  </Step>

  <Step title="Connect Curator to Ollama">
    Add the `ollama/` prefix to the model name, and set `base_url` to your Ollama server.

    ```python theme={null}
    llm = SimpleOllamaGenerator(
        model_name="ollama/llama3.1:8b",
        backend_params={"base_url": "http://localhost:11434"},
    )
    ```

    Curator sends Ollama requests through the LiteLLM backend.
  </Step>

  <Step title="Generate the data">
    ```python theme={null}
    locations = llm()
    print(locations.dataset.to_pandas())
    ```
  </Step>
</Steps>

The output looks like this.

| country | capital |
| - | - |
| France | Paris |
| Japan | Tokyo |
| Germany | Berlin |
| India | New Delhi |
| Brazil | Brasília |
