Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
venv/
.pytest_cache/
.ruff_cache/
.vscode/
data_neo4j/
data_postgres/
.coverage
.env
config.json
__pycache__/
settings.toml
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ venv/
.pytest_cache/
.ruff_cache/
.vscode/
data_neo4j/
data_postgres/
.coverage
.env
config.json
__pycache__/
__pycache__/
settings.toml
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.11-slim

ENV PYTHONUNBUFFERED=1

RUN apt-get update && apt-get install -y git

WORKDIR /app

COPY . /app

RUN pip install --upgrade pip \
&& pip install hatchling \
&& pip install .

EXPOSE 8000

CMD ["uvicorn", "prometheus.app.main:app", "--host", "0.0.0.0", "--port", "8000"]
61 changes: 61 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: "3.9"

services:
neo4j:
image: neo4j:5.20.0
container_name: neo4j_container
environment:
- NEO4J_AUTH=neo4j/password
- NEO4J_PLUGINS=["apoc"]
ports:
- "7474:7474"
- "7687:7687"
volumes:
- ./data_neo4j:/data
healthcheck:
test: ["CMD-SHELL", "neo4j status || exit 1"]
interval: 15s
timeout: 30s
retries: 3


postgres:
image: postgres
container_name: postgres_container
user: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
ports:
- "5432:5432"
volumes:
- ./data_postgres:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 15s
timeout: 30s
retries: 3

app:
build: .
container_name: prometheus
ports:
- "8000:8000"
environment:
- PROMETHEUS_NEO4J_URI="bolt://neo4j:7687"
- PROMETHEUS_NEO4J_USERNAME=neo4j
- PROMETHEUS_NEO4J_PASSWORD=password
- PROMETHEUS_NEO4J_BATCH_SIZE=1000
- PROMETHEUS_KNOWLEDGE_GRAPH_MAX_AST_DEPTH=5
- PROMETHEUS_LITELLM_MODEL=${PROMETHEUS_LITELLM_MODEL}
- PROMETHEUS_LITELLM_ANTHROPIC_API_KEY=${PROMETHEUS_LITELLM_ANTHROPIC_API_KEY}
- PROMETHEUS_WORKING_DIRECTORY="/app/working_dir"
- PROMETHEUS_GITHUB_ACCESS_TOKEN=${PROMETHEUS_GITHUB_ACCESS_TOKEN}
- PROMETHEUS_POSTGRES_URI="postgresql://postgres:password@postgres:5432/postgres?sslmode=disable"
volumes:
- .:/app
depends_on:
neo4j:
condition: service_healthy
postgres:
condition: service_healthy
22 changes: 12 additions & 10 deletions prometheus/app/shared_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from psycopg import Connection
from psycopg.rows import dict_row

from prometheus.configuration import config
from prometheus.configuration.config import settings
from prometheus.git.git_repository import GitRepository
from prometheus.graph.knowledge_graph import KnowledgeGraph
from prometheus.lang_graph.subgraphs import context_provider_subgraph, issue_answer_subgraph
Expand All @@ -21,16 +21,18 @@ class SharedState:
def __init__(self):
self.kg = None
self.neo4j_driver = GraphDatabase.driver(
config.config["neo4j"]["uri"],
auth=(config.config["neo4j"]["username"], config.config["neo4j"]["password"]),
settings.NEO4J_URI,
auth=(settings.NEO4J_USERNAME, settings.NEO4J_PASSWORD),
)
self.kg_handler = knowledge_graph_handler.KnowledgeGraphHandler(
self.neo4j_driver,
config.config["neo4j"]["batch_size"],
settings.NEO4J_BATCH_SIZE,
)
self.model = ChatLiteLLM(
model=settings.LITELLM_MODEL, anthropic_api_key=settings.LITELLM_ANTHROPIC_API_KEY
)
self.model = ChatLiteLLM(**config.config["litellm"])
self.postgres_conn = Connection.connect(
config.config["postgres"]["db_uri"],
settings.POSTGRES_URI,
autocommit=True,
prepare_threshold=0,
row_factory=dict_row,
Expand All @@ -39,7 +41,7 @@ def __init__(self):
self.checkpointer.setup()
self.cp_subgraph = None
self.ia_subgraph = None
self.git_repo = GitRepository(config.config["github"]["access_token"])
self.git_repo = GitRepository(settings.GITHUB_ACCESS_TOKEN)

self._logger = logging.getLogger("prometheus.app.shared_state")

Expand Down Expand Up @@ -78,7 +80,7 @@ def get_all_conversation_messages(self, conversation_id: str) -> Sequence[Mappin
return postgres_util.get_messages(self.checkpointer, conversation_id)

def upload_local_repository(self, path: Path):
kg = KnowledgeGraph(config.config["knowledge_graph"]["max_ast_depth"])
kg = KnowledgeGraph(settings.KNOWLEDGE_GRAPH_MAX_AST_DEPTH)
kg.build_graph(path)
self.kg = kg
self.kg_handler.write_knowledge_graph(kg)
Expand All @@ -90,10 +92,10 @@ def upload_local_repository(self, path: Path):
)

def upload_github_repository(self, https_url: str):
target_directory = Path(config.config["prometheus"]["working_directory"]) / "repositories"
target_directory = Path(settings.WORKING_DIRECTORY) / "repositories"
target_directory.mkdir(parents=True, exist_ok=True)
saved_path = self.git_repo.clone_repository(https_url, target_directory)
kg = KnowledgeGraph(config.config["knowledge_graph"]["max_ast_depth"])
kg = KnowledgeGraph(settings.KNOWLEDGE_GRAPH_MAX_AST_DEPTH)
kg.build_graph(saved_path)
self.kg = kg
self.kg_handler.write_knowledge_graph(kg)
Expand Down
29 changes: 9 additions & 20 deletions prometheus/configuration/config.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import json
import os
from pathlib import Path

CONFIG_FILE = Path(__file__).parent / "config.json"
from dynaconf import Dynaconf

settings_file = Path(__file__).resolve().parent / "settings.toml"

def load_config():
if not CONFIG_FILE.exists():
return {}
settings = Dynaconf(
envvar_prefix="PROMETHEUS",
settings_files=[str(settings_file)],
environments=True,
)

with open(CONFIG_FILE, "r") as f:
config_data = json.load(f)

if "litellm" in config_data:
if "anthropic_api_key" in config_data["litellm"]:
os.environ["ANTHROPIC_API_KEY"] = config_data["litellm"]["anthropic_api_key"]
elif "azure_api_key" in config_data["litellm"]:
os.environ["AZURE_API_KEY"] = config_data["litellm"]["azure_api_key"]
elif "openai_api_key" in config_data["litellm"]:
os.environ["OPENAI_API_KEY"] = config_data["litellm"]["openai_api_key"]
return config_data


config = load_config()
# `envvar_prefix` = export envvars with `export DYNACONF_FOO=bar`.
# `settings_files` = Load these files in the order.
21 changes: 0 additions & 21 deletions prometheus/configuration/example_config.json

This file was deleted.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ dependencies = [
"neo4j==5.20.0",
"fastapi[standard]>=0.115.2",
"langchain-anthropic>=0.2.3",
"langchain_community>=0.3.2",
"igittigitt>=2.1.5",
"litellm>=1.50.1",
"GitPython>=3.1.43",
"langgraph>=0.2.41",
"langgraph-checkpoint-postgres>=2.0.2",
"psycopg[binary]>=3.2.3",
"dynaconf>=3.2.6",
]
requires-python = ">= 3.11"

Expand All @@ -27,7 +29,6 @@ test = [
"pytest>=8.3.3",
"pytest-cov>=5.0.0",
"testcontainers==4.8.2",
"langchain_community>=0.3.2",
]

[tool.ruff]
Expand Down
Loading