llama-stack-mirror/docs/zero_to_hero_guide/quickstart.md
Justin Lee 6d38b1690b
added quickstart w ollama and toolcalling using together (#413)
* added quickstart w ollama and toolcalling using together

* corrected url for colab

---------

Co-authored-by: Justin Lee <justinai@fb.com>
2024-11-09 10:52:26 -08:00

6.7 KiB

Ollama Quickstart Guide

This guide will walk you through setting up an end-to-end workflow with Llama Stack with ollama, enabling you to perform text generation using the Llama3.2-1B-Instruct model. Follow these steps to get started quickly.

If you're looking for more specific topics like tool calling or agent setup, we have a Zero to Hero Guide that covers everything from Tool Calling to Agents in detail. Feel free to skip to the end to explore the advanced topics you're interested in.

If you'd prefer not to set up a local server, explore our notebook on tool calling with the Together API. This guide will show you how to leverage Together.ai's Llama Stack Server API, allowing you to get started with Llama Stack without the need for a locally built and running server.

Table of Contents

  1. Setup ollama
  2. Install Dependencies and Set Up Environment
  3. Build, Configure, and Run Llama Stack
  4. Run Ollama Model
  5. Next Steps

Setup ollama

  1. Download Ollama App:

  2. Download the Ollama CLI:

    • Ensure you have the ollama command line tool by downloading and installing it from the same website.
  3. Verify Installation:

    • Open the terminal and run:
      ollama run llama3.2:1b
      

Install Dependencies and Set Up Environment

  1. Create a Conda Environment:

    • Create a new Conda environment with Python 3.11:
      conda create -n hack python=3.11
      
    • Activate the environment:
      conda activate hack
      
  2. Install ChromaDB:

    • Install chromadb using pip:
      pip install chromadb
      
  3. Run ChromaDB:

    • Start the ChromaDB server:
      chroma run --host localhost --port 8000 --path ./my_chroma_data
      
  4. Install Llama Stack:

    • Open a new terminal and install llama-stack:
      conda activate hack
      pip install llama-stack
      

Build, Configure, and Run Llama Stack

  1. Build the Llama Stack:

    • Build the Llama Stack using the ollama template:
      llama stack build --template ollama --image-type conda
      
  2. Edit Configuration:

    • Modify the ollama-run.yaml file located at /Users/yourusername/.llama/distributions/llamastack-ollama/ollama-run.yaml:
      • Change the chromadb port to 8000.
      • Remove the pgvector section if present.
  3. Run the Llama Stack:

    • Run the stack with the configured YAML file:
      llama stack run /path/to/your/distro/llamastack-ollama/ollama-run.yaml --port 5050
      

The server will start and listen on http://localhost:5050.


Testing with curl

After setting up the server, open a new terminal window and verify it's working by sending a POST request using curl:

curl http://localhost:5050/inference/chat_completion \
-H "Content-Type: application/json" \
-d '{
    "model": "llama3.2:1b",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Write me a 2-sentence poem about the moon"}
    ],
    "sampling_params": {"temperature": 0.7, "seed": 42, "max_tokens": 512}
}'

Expected Output:

{
  "completion_message": {
    "role": "assistant",
    "content": "The moon glows softly in the midnight sky,\nA beacon of wonder, as it catches the eye.",
    "stop_reason": "out_of_tokens",
    "tool_calls": []
  },
  "logprobs": null
}

Testing with Python

You can also interact with the Llama Stack server using a simple Python script. Below is an example:

1. Active Conda Environment and Install Required Python Packages

The llama-stack-client library offers a robust and efficient python methods for interacting with the Llama Stack server.

conda activate your-llama-stack-conda-env
pip install llama-stack-client

2. Create Python Script (test_llama_stack.py)

touch test_llama_stack.py

3. Create a Chat Completion Request in Python

from llama_stack_client import LlamaStackClient

# Initialize the client
client = LlamaStackClient(base_url="http://localhost:5050")

# Create a chat completion request
response = client.inference.chat_completion(
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Write a two-sentence poem about llama."}
    ],
    model="llama3.2:1b",
)

# Print the response
print(response.completion_message.content)

4. Run the Python Script

python test_llama_stack.py

Expected Output:

The moon glows softly in the midnight sky,
A beacon of wonder, as it catches the eye.

With these steps, you should have a functional Llama Stack setup capable of generating text using the specified model. For more detailed information and advanced configurations, refer to some of our documentation below.

This command initializes the model to interact with your local Llama Stack instance.


Next Steps

Explore Other Guides: Dive deeper into specific topics by following these guides:

Explore Client SDKs: Utilize our client SDKs for various languages to integrate Llama Stack into your applications:

Advanced Configuration: Learn how to customize your Llama Stack distribution by referring to the Building a Llama Stack Distribution guide.

Explore Example Apps: Check out llama-stack-apps for example applications built using Llama Stack.