Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
🔧 Add ollama in devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary-H9 committed Jul 3, 2024
1 parent b81bb1b commit 2a9df00
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
29 changes: 29 additions & 0 deletions contrib/docker-compose-ollama.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
version: '3.8'

services:
ollama:
image: ollama/ollama
ports:
- 11434:11434
# command: >
# echo "Starting Ollama server..."
# ollama serve &
# ollama run llama3


# echo "Waiting for Ollama server to be active..."
# while [ "$(ollama list | grep 'NAME')" == "" ]; do
# sleep 1
# done

# command: "ollama pull llama3"
# volumes:
# - ./data:/app/data
# environment:
# - ENV_VARIABLE=value
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:11434/health"]
# interval: 30s
# timeout: 10s
# retries: 3
6 changes: 4 additions & 2 deletions ollamate/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
import os
# from pathlib import Path

import environ

# from pathlib import Path


# Initialize environment variables
env = environ.Env()

Expand Down Expand Up @@ -44,7 +46,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = [""]
ALLOWED_HOSTS: list = ["127.0.0.1"]

PROJECT_NAME = "ollamate"

Expand Down
1 change: 1 addition & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ flake8==6.1.0
isort==5.12.0
mypy==1.6.1
pre-commit==3.5.0
types-requests==2.31.0
6 changes: 6 additions & 0 deletions scripts/devcontainer/post-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ npm install --global npm@latest
# Start Postgres
docker compose --file contrib/docker-compose-postgres.yml up --detach

# Start Ollama Container
docker compose --file contrib/docker-compose-ollama.yml up --detach

# Start Ollama Model
docker exec -it contrib-ollama-1 ollama run orca-mini

# Upgrade Pip
pip install --break-system-package --upgrade pip

Expand Down
7 changes: 6 additions & 1 deletion streamingapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ def call_ollama(request):

url = "http://localhost:11434/api/chat"
headers = {"Content-Type": "application/json"}
data = {"model": "llama3", "messages": conversation_history, "stream": False}
data = {
"model": "orca-mini",
"messages": conversation_history,
"stream": False,
} # The model is hardcoded here, this will be parameterised in future

logging.debug("Sending data to Ollama API: %s", json.dumps(data, indent=2))

try:
response = requests.post(url, json=data, headers=headers)
logging.debug("HTTP status code: %s", response.status_code)
response.raise_for_status()
response_data = response.json()
logging.debug("Response data: %s", json.dumps(response_data, indent=2))
Expand Down

0 comments on commit 2a9df00

Please sign in to comment.