From 79f1f857fe103bbd9dc0c075df2e881ae734be94 Mon Sep 17 00:00:00 2001 From: Ashpreet Bedi Date: Sat, 1 Jun 2024 16:38:41 -0700 Subject: [PATCH] v2.4.18 --- cookbook/tools/exa_tools.py | 6 ++++-- phi/storage/assistant/sqllite.py | 7 ++++--- phi/tools/postgres.py | 12 ++---------- phi/vectordb/qdrant/qdrant.py | 3 +-- phi/workspace/enums.py | 1 + phi/workspace/operator.py | 2 ++ pyproject.toml | 3 ++- 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cookbook/tools/exa_tools.py b/cookbook/tools/exa_tools.py index 66e13384f1..0611cf1361 100644 --- a/cookbook/tools/exa_tools.py +++ b/cookbook/tools/exa_tools.py @@ -3,7 +3,9 @@ from phi.assistant import Assistant from phi.tools.exa import ExaTools -os.environ['EXA_API_KEY'] = 'your api key' +os.environ["EXA_API_KEY"] = "your api key" -assistant = Assistant(tools=[ExaTools(include_domains=['cnbc.com', 'reuters.com', 'bloomberg.com'])], show_tool_calls=True) +assistant = Assistant( + tools=[ExaTools(include_domains=["cnbc.com", "reuters.com", "bloomberg.com"])], show_tool_calls=True +) assistant.print_response("Search for AAPL news", debug_mode=True, markdown=True) diff --git a/phi/storage/assistant/sqllite.py b/phi/storage/assistant/sqllite.py index 0fe2401f25..c5b51fb71b 100644 --- a/phi/storage/assistant/sqllite.py +++ b/phi/storage/assistant/sqllite.py @@ -207,18 +207,19 @@ def upsert(self, row: AssistantRun) -> Optional[AssistantRun]: sess.commit() # Make sure to commit the changes to the database return self.read(run_id=row.run_id) except OperationalError as oe: - logger.error(f"OperationalError occurred: {oe}") + logger.debug(f"OperationalError occurred: {oe}") self.create() # This will only create the table if it doesn't exist try: sess.execute(stmt) sess.commit() return self.read(run_id=row.run_id) except Exception as e: - logger.error(f"Error during upsert: {e}") + logger.warning(f"Error during upsert: {e}") sess.rollback() # Rollback the session in case of any error except Exception as e: - logger.error(f"Error during upsert: {e}") + logger.warning(f"Error during upsert: {e}") sess.rollback() + return None def delete(self) -> None: if self.table_exists(): diff --git a/phi/tools/postgres.py b/phi/tools/postgres.py index 3d384d1443..ba281ac693 100644 --- a/phi/tools/postgres.py +++ b/phi/tools/postgres.py @@ -10,8 +10,8 @@ class PostgresTools(Toolkit): - """A basic tool to connect to a PostgreSQL database and perform read-only operations on it. - """ + """A basic tool to connect to a PostgreSQL database and perform read-only operations on it.""" + def __init__( self, connection: Optional[psycopg2.extensions.connection] = None, @@ -33,7 +33,6 @@ def __init__( self.host: Optional[str] = host self.port: Optional[int] = port - self.register(self.show_tables) self.register(self.describe_table) if inspect_queries: @@ -45,7 +44,6 @@ def __init__( if export_tables: self.register(self.export_table_to_path) - @property def connection(self) -> psycopg2.extensions.connection: """ @@ -71,7 +69,6 @@ def connection(self) -> psycopg2.extensions.connection: return self._connection - def show_tables(self) -> str: """Function to show tables in the database @@ -82,7 +79,6 @@ def show_tables(self) -> str: logger.debug(f"Tables: {tables}") return tables - def describe_table(self, table: str) -> str: """Function to describe a table @@ -95,7 +91,6 @@ def describe_table(self, table: str) -> str: logger.debug(f"Table description: {table_description}") return f"{table}\n{table_description}" - def summarize_table(self, table: str, table_schema: Optional[str] = "public") -> str: """Function to compute a number of aggregates over a table. The function launches a query that computes a number of aggregates over all columns, @@ -165,7 +160,6 @@ def summarize_table(self, table: str, table_schema: Optional[str] = "public") -> logger.debug(f"Table summary: {table_summary}") return table_summary - def inspect_query(self, query: str) -> str: """Function to inspect a query and return the query plan. Always inspect your query before running them. @@ -178,7 +172,6 @@ def inspect_query(self, query: str) -> str: logger.debug(f"Explain plan: {explain_plan}") return explain_plan - def export_table_to_path(self, table: str, path: Optional[str] = None) -> str: """Save a table in CSV format. If the path is provided, the table will be saved under that path. @@ -202,7 +195,6 @@ def export_table_to_path(self, table: str, path: Optional[str] = None) -> str: return result - def run_query(self, query: str) -> str: """Function that runs a query and returns the result. diff --git a/phi/vectordb/qdrant/qdrant.py b/phi/vectordb/qdrant/qdrant.py index 72f2caf7bb..70ca4d0f75 100644 --- a/phi/vectordb/qdrant/qdrant.py +++ b/phi/vectordb/qdrant/qdrant.py @@ -6,8 +6,7 @@ from qdrant_client.http import models except ImportError: raise ImportError( - "The `qdrant-client` package is not installed. " - "Please install it via `pip install qdrant-client`." + "The `qdrant-client` package is not installed. " "Please install it via `pip install qdrant-client`." ) from phi.document import Document diff --git a/phi/workspace/enums.py b/phi/workspace/enums.py index 4d098a8819..1a90b107dd 100644 --- a/phi/workspace/enums.py +++ b/phi/workspace/enums.py @@ -6,4 +6,5 @@ class WorkspaceStarterTemplate(str, Enum): ai_api = "ai-api" django_app = "django-app" streamlit_app = "streamlit-app" + llm_os = "llm-os" agentic_rag = "personalized-agentic-rag" diff --git a/phi/workspace/operator.py b/phi/workspace/operator.py index 06fb3600ee..9a5a794793 100644 --- a/phi/workspace/operator.py +++ b/phi/workspace/operator.py @@ -29,6 +29,7 @@ WorkspaceStarterTemplate.ai_api: "ai-api", WorkspaceStarterTemplate.django_app: "django-app", WorkspaceStarterTemplate.streamlit_app: "streamlit-app", + WorkspaceStarterTemplate.llm_os: "llm-os", WorkspaceStarterTemplate.agentic_rag: "agentic-rag", } TEMPLATE_TO_REPO_MAP: Dict[WorkspaceStarterTemplate, str] = { @@ -36,6 +37,7 @@ WorkspaceStarterTemplate.ai_api: "https://github.com/phidatahq/ai-api.git", WorkspaceStarterTemplate.django_app: "https://github.com/phidatahq/django-app.git", WorkspaceStarterTemplate.streamlit_app: "https://github.com/phidatahq/streamlit-app.git", + WorkspaceStarterTemplate.llm_os: "https://github.com/phidatahq/llm-os.git", WorkspaceStarterTemplate.agentic_rag: "https://github.com/phidatahq/personalized-agentic-rag.git", } diff --git a/pyproject.toml b/pyproject.toml index 1f99a3cd95..c7e2cc931b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "phidata" -version = "2.4.17" +version = "2.4.18" description = "Memory, knowledge and tools for LLMs." requires-python = ">=3.7" readme = "README.md" @@ -108,6 +108,7 @@ module = [ "pyarrow.*", "pgvector.*", "psycopg.*", + "psycopg2.*", "pypdf.*", "qdrant_client.*", "rapidocr_onnxruntime.*",