From 2f1d68b4117d990bacecf886f85c549c2341537b Mon Sep 17 00:00:00 2001 From: Yue Pan <79363355+dcloud347@users.noreply.github.com> Date: Wed, 2 Jul 2025 21:09:42 +0800 Subject: [PATCH 1/7] Update README.md to reflect changes in OpenAI API key naming and add base URL configuration --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2be69b9c..fc573601 100644 --- a/README.md +++ b/README.md @@ -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_BASE_URL` ### 🔹 Other Settings From 1b01bbe20ef2a2e885e9964a06e7e30f87508590 Mon Sep 17 00:00:00 2001 From: Yue Pan <79363355+dcloud347@users.noreply.github.com> Date: Wed, 2 Jul 2025 21:10:01 +0800 Subject: [PATCH 2/7] Update README.md to reflect changes in OpenAI base URL configuration --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc573601..5d573ff1 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Set the following variables in your `.env` file: * `PROMETHEUS_GEMINI_API_KEY` * Base URL for LLMs: - * `PROMETHEUS_OPENAI_BASE_URL` + * `PROMETHEUS_OPENAI_FORMAT_BASE_URL` ### 🔹 Other Settings From 8890ebda73c30e0c200ac8a063e2fdf7820005bb Mon Sep 17 00:00:00 2001 From: Yue Pan <79363355+dcloud347@users.noreply.github.com> Date: Thu, 3 Jul 2025 15:36:52 +0800 Subject: [PATCH 3/7] Update graph_types.py and service_coordinator.py to allow None values for https_url and commit_id, and improve code comments for clarity --- prometheus/app/services/service_coordinator.py | 3 +++ prometheus/graph/graph_types.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/prometheus/app/services/service_coordinator.py b/prometheus/app/services/service_coordinator.py index 693f317e..05955eb2 100644 --- a/prometheus/app/services/service_coordinator.py +++ b/prometheus/app/services/service_coordinator.py @@ -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 ) diff --git a/prometheus/graph/graph_types.py b/prometheus/graph/graph_types.py index 512c26b9..cf7138a0 100644 --- a/prometheus/graph/graph_types.py +++ b/prometheus/graph/graph_types.py @@ -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( From 149230383fc335d1a72414b556726a17524c140c Mon Sep 17 00:00:00 2001 From: Yue Pan <79363355+dcloud347@users.noreply.github.com> Date: Fri, 4 Jul 2025 11:46:31 +0800 Subject: [PATCH 4/7] Refactor knowledge_graph_handler.py to streamline writing ParentOfEdge relationships to Neo4j and improve batch processing --- prometheus/neo4j/knowledge_graph_handler.py | 38 ++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/prometheus/neo4j/knowledge_graph_handler.py b/prometheus/neo4j/knowledge_graph_handler.py index c8989b6e..7a9d3276 100644 --- a/prometheus/neo4j/knowledge_graph_handler.py +++ b/prometheus/neo4j/knowledge_graph_handler.py @@ -144,20 +144,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) + parent_of_edges_batch = parent_of_edges[i: i + self.batch_size] + 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] @@ -193,14 +200,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.""" From db776e496f28e2856d76dc26a8dfe182140262c7 Mon Sep 17 00:00:00 2001 From: Yue Pan <79363355+dcloud347@users.noreply.github.com> Date: Fri, 4 Jul 2025 11:47:37 +0800 Subject: [PATCH 5/7] Refactor knowledge_graph_handler.py to remove unused imports and improve batch processing readability --- prometheus/neo4j/knowledge_graph_handler.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/prometheus/neo4j/knowledge_graph_handler.py b/prometheus/neo4j/knowledge_graph_handler.py index 7a9d3276..70869c4c 100644 --- a/prometheus/neo4j/knowledge_graph_handler.py +++ b/prometheus/neo4j/knowledge_graph_handler.py @@ -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 @@ -16,7 +15,6 @@ Neo4jHasTextEdge, Neo4jMetadataNode, Neo4jNextChunkEdge, - Neo4jParentOfEdge, Neo4jTextNode, ) from prometheus.graph.knowledge_graph import KnowledgeGraph @@ -155,7 +153,7 @@ def write_parent_of_edges(self, parent_of_edges): """ for i in range(0, len(parent_of_edges), self.batch_size): - parent_of_edges_batch = parent_of_edges[i: i + self.batch_size] + parent_of_edges_batch = parent_of_edges[i : i + self.batch_size] edge_dicts = [ { "source": {"node_id": e.source.node_id}, From a66853f412b09d5446b9578e9d95417253a3aa6c Mon Sep 17 00:00:00 2001 From: Yue Pan <79363355+dcloud347@users.noreply.github.com> Date: Fri, 4 Jul 2025 12:03:22 +0800 Subject: [PATCH 6/7] Enhance error logging in context_retrieval_subgraph_node.py to include exception type and stack trace during retries --- .../nodes/context_retrieval_subgraph_node.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/prometheus/lang_graph/nodes/context_retrieval_subgraph_node.py b/prometheus/lang_graph/nodes/context_retrieval_subgraph_node.py index 79e4f838..13b1ff31 100644 --- a/prometheus/lang_graph/nodes/context_retrieval_subgraph_node.py +++ b/prometheus/lang_graph/nodes/context_retrieval_subgraph_node.py @@ -1,4 +1,5 @@ import logging +import traceback from typing import Dict import neo4j @@ -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") From 917cdd7eae08e7da3aadb2f80754b9569f2fc65e Mon Sep 17 00:00:00 2001 From: Yue Pan <79363355+dcloud347@users.noreply.github.com> Date: Fri, 4 Jul 2025 13:09:58 +0800 Subject: [PATCH 7/7] Update test_llm_service.py to use configurable temperature and max_output_tokens settings --- prometheus/script/test_llm_service.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prometheus/script/test_llm_service.py b/prometheus/script/test_llm_service.py index 9919714b..76f97635 100644 --- a/prometheus/script/test_llm_service.py +++ b/prometheus/script/test_llm_service.py @@ -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