Skip to content
Merged

Dev #84

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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ Set the following variables in your `.env` file:
* `PROMETHEUS_BASE_MODEL`
* API Keys:

* `PROMETHEUS_OPENAI_API_KEY`
* `PROMETHEUS_OPENAI_FORMAT_API_KEY`
* `PROMETHEUS_ANTHROPIC_API_KEY`
* `PROMETHEUS_GEMINI_API_KEY`
* `PROMETHEUS_OPENROUTER_API_KEY`
* Base URL for LLMs:

* `PROMETHEUS_OPENAI_FORMAT_BASE_URL`

### 🔹 Other Settings

Expand Down
3 changes: 3 additions & 0 deletions prometheus/app/services/service_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@ def upload_github_repository(self, https_url: str, commit_id: Optional[str] = No
https_url: HTTPS URL of the GitHub repository.
commit_id: Optional specific commit to analyze.
"""
# CLean the existing knowledge graph and repository state
self.clear()
# Clone the repository
saved_path = self.repository_service.clone_github_repo(
self.github_token, https_url, commit_id
)
# Build and save the knowledge graph from the cloned repository
self.knowledge_graph_service.build_and_save_knowledge_graph(
saved_path, https_url, commit_id
)
Expand Down
4 changes: 2 additions & 2 deletions prometheus/graph/graph_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class MetadataNode:

local_path: str

https_url: str
commit_id: str
https_url: str | None
commit_id: str | None

def to_neo4j_node(self) -> "Neo4jMetadataNode":
return Neo4jMetadataNode(
Expand Down
11 changes: 7 additions & 4 deletions prometheus/lang_graph/nodes/context_retrieval_subgraph_node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import traceback
from typing import Dict

import neo4j
Expand Down Expand Up @@ -41,10 +42,12 @@ def __call__(self, state: Dict, max_tries: int = 3) -> Dict[str, str]:
)
break
except Exception as e:
if attempt < max_tries:
self._logger.warning(
f"Context retrieval failed, retrying {attempt}/{max_tries} times: {e}"
)
self._logger.warning(
f"Context retrieval failed, retrying {attempt}/{max_tries} times:\n"
f"{type(e).__name__}: {e}\n"
f"{traceback.format_exc()}"
)

if output_state is None:
self._logger.error("Context retrieval failed after maximum attempts")
raise RuntimeError("Failed to retrieve context after maximum attempts")
Expand Down
38 changes: 18 additions & 20 deletions prometheus/neo4j/knowledge_graph_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The neo4j handler for writing the knowledge graph to neo4j."""

import logging
import time
from typing import Mapping, Sequence

from neo4j import GraphDatabase, ManagedTransaction
Expand All @@ -16,7 +15,6 @@
Neo4jHasTextEdge,
Neo4jMetadataNode,
Neo4jNextChunkEdge,
Neo4jParentOfEdge,
Neo4jTextNode,
)
from prometheus.graph.knowledge_graph import KnowledgeGraph
Expand Down Expand Up @@ -144,20 +142,27 @@ def _write_has_text_edges(
has_text_edges_batch = has_text_edges[i : i + self.batch_size]
tx.run(query, edges=has_text_edges_batch)

def _write_parent_of_edges(
self, tx: ManagedTransaction, parent_of_edges: Sequence[Neo4jParentOfEdge]
):
"""Write Neo4jParentOfEdge to neo4j."""
def write_parent_of_edges(self, parent_of_edges):
self._logger.debug(f"Writing {len(parent_of_edges)} ParentOfEdge to neo4j")

query = """
UNWIND $edges AS edge
MATCH (source:ASTNode), (target:ASTNode)
WHERE source.node_id = edge.source.node_id AND target.node_id = edge.target.node_id
CREATE (source) -[:PARENT_OF]-> (target)
"""
UNWIND $edges AS edge
MATCH (source:ASTNode {node_id: edge.source.node_id})
MATCH (target:ASTNode {node_id: edge.target.node_id})
CREATE (source)-[:PARENT_OF]->(target)
"""

for i in range(0, len(parent_of_edges), self.batch_size):
parent_of_edges_batch = parent_of_edges[i : i + self.batch_size]
tx.run(query, edges=parent_of_edges_batch)
edge_dicts = [
{
"source": {"node_id": e.source.node_id},
"target": {"node_id": e.target.node_id},
}
for e in parent_of_edges_batch
]
with self.driver.session() as session:
session.write_transaction(lambda tx: tx.run(query, edges=edge_dicts))

def _write_next_chunk_edges(
self, tx: ManagedTransaction, next_chunk_edges: Sequence[Neo4jNextChunkEdge]
Expand Down Expand Up @@ -193,14 +198,7 @@ def write_knowledge_graph(self, kg: KnowledgeGraph):
session.execute_write(self._write_has_file_edges, kg.get_neo4j_has_file_edges())
session.execute_write(self._write_has_text_edges, kg.get_neo4j_has_text_edges())
session.execute_write(self._write_next_chunk_edges, kg.get_neo4j_next_chunk_edges())
for i in range(0, len(kg.get_neo4j_parent_of_edges()), 50000):
with self.driver.session() as session:
# Write PARENT_OF edges in batches to avoid transaction size limits
self._logger.info("Writing parent of edges to neo4j")
session.execute_write(
self._write_parent_of_edges, kg.get_neo4j_parent_of_edges()[i : i + 50000]
)
time.sleep(10)
self.write_parent_of_edges(kg.get_parent_of_edges())

def _read_metadata_node(self, tx: ManagedTransaction) -> MetadataNode:
"""Read MetadataNode from neo4j."""
Expand Down
4 changes: 2 additions & 2 deletions prometheus/script/test_llm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def test_model_response():
openai_format_base_url=settings.OPENAI_FORMAT_BASE_URL,
anthropic_api_key=settings.ANTHROPIC_API_KEY,
gemini_api_key=settings.GEMINI_API_KEY,
temperature=0.3,
max_output_tokens=55000,
temperature=settings.TEMPERATURE,
max_output_tokens=settings.MAX_OUTPUT_TOKENS,
)

# Test base model
Expand Down