Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 1048-docs-initial-cle…
Browse files Browse the repository at this point in the history
…anup-for-mkdocs-migration
  • Loading branch information
harishmohanraj committed Feb 20, 2025
2 parents faaa701 + 7c13751 commit ce527c9
Show file tree
Hide file tree
Showing 36 changed files with 1,108 additions and 355 deletions.
54 changes: 22 additions & 32 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,23 @@
"filename": "autogen/oai/openai_utils.py",
"hashed_secret": "aa5bc2e0df7182f74186f26d6e9063b9d57603ec",
"is_verified": false,
"line_number": 352,
"line_number": 353,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "autogen/oai/openai_utils.py",
"hashed_secret": "cbb43d092552e9af4b21efc76bc8c49c071c1d81",
"is_verified": false,
"line_number": 353,
"line_number": 354,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "autogen/oai/openai_utils.py",
"hashed_secret": "79d8b9da0f827f788759bdbe5b9254a02c74d877",
"is_verified": false,
"line_number": 573,
"line_number": 577,
"is_secret": false
}
],
Expand Down Expand Up @@ -773,7 +773,7 @@
"filename": "test/agentchat/contrib/graph_rag/test_native_neo4j_graph_rag.py",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 78,
"line_number": 75,
"is_secret": false
}
],
Expand All @@ -783,7 +783,7 @@
"filename": "test/agentchat/contrib/graph_rag/test_neo4j_graph_rag.py",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 38,
"line_number": 35,
"is_secret": false
}
],
Expand Down Expand Up @@ -1035,127 +1035,127 @@
"filename": "test/oai/test_utils.py",
"hashed_secret": "f72c85879027f6160ce36e1c5074ef8207bfe105",
"is_verified": false,
"line_number": 26,
"line_number": 30,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "4c88039c5079180dacb0e29d715055d95b2b7589",
"is_verified": false,
"line_number": 35,
"line_number": 39,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "7460e665be1988cc62f1caf9d47716b07d55858c",
"is_verified": false,
"line_number": 65,
"line_number": 69,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "b5c2827eb65bf13b87130e7e3c424ba9ff07cd67",
"is_verified": false,
"line_number": 72,
"line_number": 76,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "178c7a21b087dfafc826a21b61aff284c71fd258",
"is_verified": false,
"line_number": 198,
"line_number": 202,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "aa5c90e1b80bb987f562ac30eaa1a71c832892f5",
"is_verified": false,
"line_number": 199,
"line_number": 203,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "4489f55309f29853a4075cbbdf1f18b584809726",
"is_verified": false,
"line_number": 201,
"line_number": 205,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "95cfb33d5e102631e226e7ff9da4b17d6ba5f3e4",
"is_verified": false,
"line_number": 213,
"line_number": 217,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "7943297a6a2188abe697bd1e0189fdd1274818be",
"is_verified": false,
"line_number": 215,
"line_number": 219,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "8cc86c45479a8e0bbb1ddea57d3e195b611241f2",
"is_verified": false,
"line_number": 235,
"line_number": 239,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "eda6571eea7bd0ac4553ac9d745631f1f2bec7a4",
"is_verified": false,
"line_number": 237,
"line_number": 241,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "0ad02c88ffd9754bfbfc24ade0bf8bc48d76b232",
"is_verified": false,
"line_number": 246,
"line_number": 250,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "test/oai/test_utils.py",
"hashed_secret": "11841233da3f9f37c5fa14e8b482dde913db6edf",
"is_verified": false,
"line_number": 254,
"line_number": 258,
"is_secret": false
},
{
"type": "Base64 High Entropy String",
"filename": "test/oai/test_utils.py",
"hashed_secret": "11cac88cbfa53881646b024097f531c4f234151b",
"is_verified": false,
"line_number": 432,
"line_number": 436,
"is_secret": false
},
{
"type": "OpenAI Token",
"filename": "test/oai/test_utils.py",
"hashed_secret": "8e8324e8ea2ec13efb774680c6e3850625e575e6",
"is_verified": false,
"line_number": 432,
"line_number": 436,
"is_secret": false
},
{
"type": "Base64 High Entropy String",
"filename": "test/oai/test_utils.py",
"hashed_secret": "8e2fa04ab430ff4817e87e3294f33727fc78ed6c",
"is_verified": false,
"line_number": 435,
"line_number": 439,
"is_secret": false
}
],
Expand Down Expand Up @@ -1187,16 +1187,6 @@
"is_secret": false
}
],
"test/tools/experimental/browser_use/test_browser_use.py": [
{
"type": "Secret Keyword",
"filename": "test/tools/experimental/browser_use/test_browser_use.py",
"hashed_secret": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"is_verified": false,
"line_number": 47,
"is_secret": false
}
],
"test/tools/experimental/crawl4ai/test_crawl4ai.py": [
{
"type": "Secret Keyword",
Expand Down Expand Up @@ -1616,5 +1606,5 @@
}
]
},
"generated_at": "2025-02-20T06:43:14Z"
"generated_at": "2025-02-20T10:09:56Z"
}
6 changes: 5 additions & 1 deletion autogen/agentchat/contrib/graph_rag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
#
# SPDX-License-Identifier: Apache-2.0

__all__: list[str] = []
from .document import Document, DocumentType
from .graph_query_engine import GraphQueryEngine, GraphStoreQueryResult
from .graph_rag_capability import GraphRagCapability

__all__ = ["Document", "DocumentType", "GraphQueryEngine", "GraphRagCapability", "GraphStoreQueryResult"]
10 changes: 6 additions & 4 deletions autogen/agentchat/contrib/graph_rag/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
# SPDX-License-Identifier: MIT
from dataclasses import dataclass
from dataclasses import dataclass, field
from enum import Enum, auto
from typing import Optional
from typing import Any, Optional

__all__ = ["Document", "DocumentType"]


class DocumentType(Enum):
Expand All @@ -23,5 +25,5 @@ class Document:
"""A wrapper of graph store query results."""

doctype: DocumentType
data: Optional[object] = None
path_or_url: Optional[str] = ""
data: Optional[Any] = None
path_or_url: Optional[str] = field(default_factory=lambda: "")
20 changes: 10 additions & 10 deletions autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import warnings
from typing import Optional
from typing import Any, Optional

from ....import_utils import optional_import_block, require_optional_import
from .document import Document
Expand All @@ -23,7 +23,7 @@
class FalkorGraphQueryEngine:
"""This is a wrapper for FalkorDB KnowledgeGraph."""

def __init__(
def __init__( # type: ignore[no-any-unimported]
self,
name: str,
host: str = "127.0.0.1",
Expand Down Expand Up @@ -57,10 +57,10 @@ def __init__(
self.model = model or OpenAiGenerativeModel("gpt-4o")
self.model_config = KnowledgeGraphModelConfig.with_model(model)
self.ontology = ontology
self.knowledge_graph = None
self.knowledge_graph: Optional["KnowledgeGraph"] = None # type: ignore[no-any-unimported]
self.falkordb = FalkorDB(host=self.host, port=self.port, username=self.username, password=self.password)

def connect_db(self):
def connect_db(self) -> None:
"""Connect to an existing knowledge graph."""
if self.name in self.falkordb.list_graphs():
try:
Expand All @@ -86,11 +86,11 @@ def connect_db(self):
else:
raise ValueError(f"Knowledge graph '{self.name}' does not exist")

def init_db(self, input_doc: list[Document]):
def init_db(self, input_doc: list[Document]) -> None:
"""Build the knowledge graph with input documents."""
sources = []
for doc in input_doc:
if os.path.exists(doc.path_or_url):
if doc.path_or_url and os.path.exists(doc.path_or_url):
sources.append(Source(doc.path_or_url))

if sources:
Expand Down Expand Up @@ -123,7 +123,7 @@ def init_db(self, input_doc: list[Document]):
def add_records(self, new_records: list[Document]) -> bool:
raise NotImplementedError("This method is not supported by FalkorDB SDK yet.")

def query(self, question: str, n_results: int = 1, **kwargs) -> GraphStoreQueryResult:
def query(self, question: str, n_results: int = 1, **kwargs: Any) -> GraphStoreQueryResult:
"""Query the knowledge graph with a question and optional message history.
Args:
Expand Down Expand Up @@ -153,17 +153,17 @@ def delete(self) -> bool:
self.falkordb.select_graph(self.ontology_table_name).delete()
return True

def __get_ontology_storage_graph(self) -> "Graph":
def __get_ontology_storage_graph(self) -> "Graph": # type: ignore[no-any-unimported]
return self.falkordb.select_graph(self.ontology_table_name)

def _save_ontology_to_db(self, ontology: "Ontology"):
def _save_ontology_to_db(self, ontology: "Ontology") -> None: # type: ignore[no-any-unimported]
"""Save graph ontology to a separate table with {graph_name}_ontology"""
if self.ontology_table_name in self.falkordb.list_graphs():
raise ValueError(f"Knowledge graph {self.name} is already created.")
graph = self.__get_ontology_storage_graph()
ontology.save_to_graph(graph)

def _load_ontology_from_db(self) -> "Ontology":
def _load_ontology_from_db(self) -> "Ontology": # type: ignore[no-any-unimported]
if self.ontology_table_name not in self.falkordb.list_graphs():
raise ValueError(f"Knowledge graph {self.name} has not been created.")
graph = self.__get_ontology_storage_graph()
Expand Down
18 changes: 12 additions & 6 deletions autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ def __init__(self, query_engine: FalkorGraphQueryEngine):
"""Initialize GraphRAG capability with a graph query engine"""
self.query_engine = query_engine

def add_to_agent(self, agent: UserProxyAgent):
def add_to_agent(self, agent: ConversableAgent) -> None:
"""Add FalkorDB GraphRAG capability to a UserProxyAgent.
Args:
agent: The UserProxyAgent instance to add the capability to.
The restriction to a UserProxyAgent to make sure the returned message does not contain information retrieved from the graph DB instead of any LLMs.
"""
if not isinstance(agent, UserProxyAgent):
raise Exception("FalkorDB GraphRAG capability can only be added to a UserProxyAgent.")

self.graph_rag_agent = agent

# Validate the agent config
Expand Down Expand Up @@ -62,7 +70,8 @@ def _reply_using_falkordb_query(
Returns:
A tuple containing a boolean indicating success and the assistant's reply.
"""
question = self._messages_summary(messages, recipient.system_message)
# todo: fix typing, this is not correct
question = self._messages_summary(messages, recipient.system_message) # type: ignore[arg-type]
result: GraphStoreQueryResult = self.query_engine.query(question)

return True, result.answer if result.answer else "I'm sorry, I don't have an answer for that."
Expand All @@ -77,10 +86,7 @@ def _messages_summary(self, messages: Union[dict[str, Any], str], system_message
<content>
"""
if isinstance(messages, str):
if system_message:
summary = f"IMPORTANT: {system_message}\nContext:\n\n{messages}"
else:
return messages
return (f"IMPORTANT: {system_message}\n" if system_message else "") + f"Context:\n\n{messages}"

elif isinstance(messages, list):
summary = ""
Expand Down
Loading

0 comments on commit ce527c9

Please sign in to comment.