Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

132/llama3.2+nomic #138

Merged
merged 13 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.venv
.env.local
.env.sample
.gitignore
.pre-commit-config.yaml
.github
.idea
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ lint:
format:
black --config pyproject.toml labs

## Teardown local database
## Stops and removes all the services
.PHONY: down
down:
docker compose --env-file=$(ENV_FILE) down

## Setup local database
## Start all the services
.PHONY: up
up: down
docker compose --env-file=$(ENV_FILE) up --build -d

## Start a python shell
.PHONY: shell
shell:
ipython

## Run project tests
.PHONY: tests
tests:
pytest
Expand All @@ -54,13 +56,11 @@ clean_tests:
rm -rf labs/test/vcr_cassettes; \
fi

.PHONY: local_llm_up
local_llm_up:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
## Pull given model from ollama (use `make ollama model=<model name>`)
.PHONY: ollama
ollama:
docker compose exec ollama ollama pull $(model)

.PHONY: local_llm_run
local_llm_run: local_llm_up
docker exec ollama ollama run llama3.2

#################################################################################
# Self Documenting Commands #
Expand Down
1 change: 1 addition & 0 deletions asgi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
fastapi_app.include_router(codemonkey_endpoints.router)
fastapi_app.include_router(github_endpoints.router)


# ASGI application to route to Django or FastAPI
async def app(scope, receive, send):
if scope["type"] == "http" and scope["path"].startswith("/admin"):
Expand Down
5 changes: 3 additions & 2 deletions config/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib import admin
from .models import Config


@admin.register(Config)
class ConfigAdmin(admin.ModelAdmin):
list_display = ('llm_model', 'key', 'value', 'type', 'created_at', 'updated_at')
search_fields = (['key', 'llm_model'])
list_display = ("llm_model", "key", "value", "type", "created_at", "updated_at")
search_fields = ["key", "llm_model"]
3 changes: 1 addition & 2 deletions config/configuration_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from labs.logger import setup_logger


setup_logger()


Expand Down Expand Up @@ -52,4 +51,4 @@
REDIS_PORT = os.environ.get("REDIS_PORT")

LOCAL_LLM = eval(os.environ.get("LOCAL_LLM", "False"))
LOCAL_LLM_HOST = os.environ.get("LOCAL_LLM_HOST", "http://localhost:11434")
LOCAL_LLM_HOST = os.environ.get("LOCAL_LLM_HOST", "http://ollama:11434")
1 change: 0 additions & 1 deletion config/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
7 changes: 3 additions & 4 deletions config/models/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.db import models
from django.utils import timezone


class Config(models.Model):
llm_model = models.TextField(blank=True, null=True)
llm_model = models.TextField(blank=True, null=True)
key = models.TextField(unique=True)
value = models.TextField(blank=True, null=True)
type = models.TextField(blank=True, null=True)
Expand All @@ -13,6 +14,4 @@ def __str__(self):
return f"{self.key}: {self.value}"

class Meta:
indexes = [
models.Index(fields=['key', 'llm_model'])
]
indexes = [models.Index(fields=["key", "llm_model"])]
7 changes: 4 additions & 3 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

import os
from pathlib import Path

Expand All @@ -19,12 +20,12 @@
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', '')
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG', "True") == "True"
DEBUG = os.environ.get("DJANGO_DEBUG", "True") == "True"

ALLOWED_HOSTS = [s.strip() for s in os.environ.get("DJANGO_ALLOWED_HOSTS", []).split(",")]
ALLOWED_HOSTS = [s.strip() for s in os.environ.get("DJANGO_ALLOWED_HOSTS", []).split(",")]


# Application definition
Expand Down
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path

Expand Down
2 changes: 1 addition & 1 deletion database_scripts/postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS embeddings (
id SERIAL PRIMARY KEY,
repository text,
embedding vector,
file_and_path text,
file_path text,
text text,
created_at timestamptz DEFAULT now()
);
2 changes: 1 addition & 1 deletion database_scripts/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS embeddings (
id SERIAL PRIMARY KEY,
repository text,
embedding vector,
file_and_path text,
file_path text,
text text,
created_at timestamptz DEFAULT now()
);
20 changes: 11 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
services:
postgres:
container_name: postgres
image: postgres:13
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASS}
POSTGRES_DB: ${POSTGRES_DB}

labs-db:
container_name: labs-db
image: pgvector/pgvector:pg16
Expand Down Expand Up @@ -70,4 +62,14 @@ services:
- labs-db
volumes:
- .:/app
- ${LOCAL_REPOS_PATH}:/local-repos/
- ${LOCAL_REPOS_PATH}:/local-repos/

ollama:
image: ollama/ollama:latest
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama

volumes:
ollama:
7 changes: 3 additions & 4 deletions docs/diagram/class_diagram_script.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import ast
import os

import graphviz


Expand Down Expand Up @@ -28,9 +29,7 @@ def extract_classes(file_path):
args.append(f"{arg.arg}: {arg.annotation.id}")
elif isinstance(arg.annotation, ast.Subscript):
if isinstance(arg.annotation.value, ast.Name):
args.append(
f"{arg.arg}: {arg.annotation.value.id}[{arg.annotation.slice.value.id}]"
)
args.append(f"{arg.arg}: {arg.annotation.value.id}[{arg.annotation.slice.value.id}]")
else:
args.append(arg.arg)
method_signature = f"{visibility} {method_name}({', '.join(args)})"
Expand Down
4 changes: 1 addition & 3 deletions labs/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
LOW_PRIORITY_QUEUE_NAME = f"{CELERY_QUEUE_PREFIX}-low"
HIGH_PRIORITY_QUEUE_NAME = f"{CELERY_QUEUE_PREFIX}-high"

redis_client = redis.StrictRedis(
host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0, decode_responses=True
)
redis_client = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0, decode_responses=True)


app = Celery(
Expand Down
13 changes: 7 additions & 6 deletions labs/database/connect.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from config import configuration_variables as settings
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
import logging

from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, sessionmaker

from config import configuration_variables as settings

logger = logging.getLogger(__name__)

Expand All @@ -14,16 +15,16 @@

def db_connector():
def decorator(original_function):
def new_function(*args, **kwargs):
def new_function(self, *args, **kwargs):
if settings.TEST_ENVIRONMENT:
# This is necessary because when we're running tests, we are already using db_session.
# Which has the rollback feature.
return original_function(*args, **kwargs)
return original_function(self, *args, **kwargs)

connection = engine.connect()

try:
return original_function(connection, *args, **kwargs)
return original_function(self, connection, *args, **kwargs)
except Exception:
logger.exception("Error while getting data from DB.")
finally:
Expand Down
71 changes: 0 additions & 71 deletions labs/database/embeddings.py

This file was deleted.

17 changes: 17 additions & 0 deletions labs/database/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging

from pgvector.sqlalchemy import Vector
from sqlalchemy import Column, Integer, String

from labs.database.connect import Base

logger = logging.getLogger(__name__)


class EmbeddingModel(Base):
__tablename__ = "embeddings"
id = Column(Integer, primary_key=True, autoincrement=True)
repository = Column(String)
file_path = Column(String)
text = Column(String)
embedding = Column(Vector())
Empty file added labs/embeddings/__init__.py
Empty file.
Loading
Loading