Skip to content

Commit

Permalink
realtime deps moved to main deps
Browse files Browse the repository at this point in the history
  • Loading branch information
davorrunje committed Dec 19, 2024
2 parents c193859 + 7f9a2b6 commit bd6d640
Show file tree
Hide file tree
Showing 59 changed files with 2,215 additions and 523 deletions.
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
| Eric Moore | [emooreatx](https://github.com/emooreatx) | IBM | all|
| Evan David | [evandavid1](https://github.com/evandavid1) | - | all |
| Tvrtko Sternak | [sternakt](https://github.com/sternakt) | airt.ai | structured output |

| Jiacheng Shang | [Eric-Shang](https://github.com/Eric-Shang) | Toast | RAG |

**Pending Maintainers list (Marked with \*, Waiting for explicit approval from the maintainers)**
| Name | GitHub Handle | Organization | Features |
Expand Down
2 changes: 2 additions & 0 deletions autogen/agentchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .contrib.swarm_agent import (
AFTER_WORK,
ON_CONDITION,
UPDATE_SYSTEM_MESSAGE,
AfterWorkOption,
SwarmAgent,
SwarmResult,
Expand Down Expand Up @@ -39,4 +40,5 @@
"ON_CONDITION",
"AFTER_WORK",
"AfterWorkOption",
"UPDATE_SYSTEM_MESSAGE",
]
36 changes: 25 additions & 11 deletions autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(
If None, FalkorDB will auto generate an ontology from the input docs.
"""
self.name = name
self.ontology_table_name = name + "_ontology"
self.host = host
self.port = port
self.username = username
Expand All @@ -65,7 +66,7 @@ def connect_db(self):
"""
if self.name in self.falkordb.list_graphs():
try:
self.ontology = self._load_ontology_from_db(self.name)
self.ontology = self._load_ontology_from_db()
except Exception:
warnings.warn("Graph Ontology is not loaded.")

Expand Down Expand Up @@ -103,6 +104,8 @@ def init_db(self, input_doc: List[Document]):
sources=sources,
model=self.model,
)
# Save Ontology to graph for future access.
self._save_ontology_to_db(self.ontology)

self.knowledge_graph = KnowledgeGraph(
name=self.name,
Expand All @@ -118,9 +121,6 @@ def init_db(self, input_doc: List[Document]):

# Establishing a chat session will maintain the history
self._chat_session = self.knowledge_graph.chat_session()

# Save Ontology to graph for future access.
self._save_ontology_to_db(self.name, self.ontology)
else:
raise ValueError("No input documents could be loaded.")

Expand Down Expand Up @@ -149,17 +149,31 @@ def query(self, question: str, n_results: int = 1, **kwargs) -> GraphStoreQueryR

return GraphStoreQueryResult(answer=response["response"], results=[])

def __get_ontology_storage_graph(self, graph_name: str) -> Graph:
ontology_table_name = graph_name + "_ontology"
return self.falkordb.select_graph(ontology_table_name)
def delete(self) -> bool:
"""
Delete graph and its data from database.
"""
all_graphs = self.falkordb.list_graphs()
if self.name in all_graphs:
self.falkordb.select_graph(self.name).delete()
if self.ontology_table_name in all_graphs:
self.falkordb.select_graph(self.ontology_table_name).delete()
return True

def __get_ontology_storage_graph(self) -> Graph:
return self.falkordb.select_graph(self.ontology_table_name)

def _save_ontology_to_db(self, graph_name: str, ontology: Ontology):
def _save_ontology_to_db(self, ontology: Ontology):
"""
Save graph ontology to a separate table with {graph_name}_ontology
"""
graph = self.__get_ontology_storage_graph(graph_name)
if self.ontology_table_name in self.falkordb.list_graphs():
raise ValueError("Knowledge graph {} is already created.".format(self.name))
graph = self.__get_ontology_storage_graph()
ontology.save_to_graph(graph)

def _load_ontology_from_db(self, graph_name: str) -> Ontology:
graph = self.__get_ontology_storage_graph(graph_name)
def _load_ontology_from_db(self) -> Ontology:
if self.ontology_table_name not in self.falkordb.list_graphs():
raise ValueError("Knowledge graph {} has not been created.".format(self.name))
graph = self.__get_ontology_storage_graph()
return Ontology.from_graph(graph)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
database: str = "neo4j",
username: str = "neo4j",
password: str = "neo4j",
llm: LLM = OpenAI(model="gpt-3.5-turbo", temperature=0.0),
llm: LLM = OpenAI(model="gpt-4o", temperature=0.0),
embedding: BaseEmbedding = OpenAIEmbedding(model_name="text-embedding-3-small"),
entities: Optional[TypeAlias] = None,
relations: Optional[TypeAlias] = None,
Expand Down
16 changes: 13 additions & 3 deletions autogen/agentchat/contrib/llamaindex_conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.chat_engine.types import AgentChatResponse
from pydantic import BaseModel
from pydantic import __version__ as pydantic_version

# let's Avoid: AttributeError: type object 'Config' has no attribute 'copy'
# check for v1 like in autogen/_pydantic.py
is_pydantic_v1 = pydantic_version.startswith("1.")
if not is_pydantic_v1:
from pydantic import ConfigDict

Config = ConfigDict(arbitrary_types_allowed=True)
else:

class Config:
arbitrary_types_allowed = True

# Add Pydantic configuration to allow arbitrary types
# Added to mitigate PydanticSchemaGenerationError
class Config:
arbitrary_types_allowed = True

BaseModel.model_config = Config

except ImportError as e:
Expand Down
Loading

0 comments on commit bd6d640

Please sign in to comment.