Skip to content

Commit

Permalink
v2.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Nov 2, 2023
1 parent 0347e47 commit 74f7d63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
20 changes: 6 additions & 14 deletions phi/conversation/storage/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
except ImportError:
raise ImportError("`sqlalchemy` not installed")

try:
import psycopg
except ImportError:
raise ImportError("`psycopg` not installed")

from phi.conversation.schemas import ConversationRow
from phi.conversation.storage.base import ConversationStorage
from phi.utils.log import logger
Expand Down Expand Up @@ -111,10 +106,9 @@ def _read(self, session: Session, conversation_id: str) -> Optional[Row[Any]]:
stmt = select(self.table).where(self.table.c.id == conversation_id)
try:
return session.execute(stmt).first()
except Exception as e:
except Exception:
# Create table if it does not exist
if e.__class__ == psycopg.errors.UndefinedTable:
self.create()
self.create()
return None

def read(self, conversation_id: str) -> Optional[ConversationRow]:
Expand All @@ -137,9 +131,8 @@ def get_all_conversation_ids(self, user_name: Optional[str] = None) -> List[str]
for row in rows:
if row is not None and row.id is not None:
conversation_ids.append(row.id)
except psycopg.errors.UndefinedTable:
except Exception:
logger.debug(f"Table does not exist: {self.table.name}")
pass
return conversation_ids

def get_all_conversations(self, user_name: Optional[str] = None) -> List[ConversationRow]:
Expand All @@ -157,9 +150,8 @@ def get_all_conversations(self, user_name: Optional[str] = None) -> List[Convers
for row in rows:
if row.id is not None:
conversations.append(ConversationRow.model_validate(row))
except psycopg.errors.UndefinedTable:
except Exception:
logger.debug(f"Table does not exist: {self.table.name}")
pass
return conversations

def upsert(self, conversation: ConversationRow) -> Optional[ConversationRow]:
Expand Down Expand Up @@ -199,8 +191,8 @@ def upsert(self, conversation: ConversationRow) -> Optional[ConversationRow]:

try:
sess.execute(stmt)
except psycopg.errors.UndefinedTable:
# Create table if it does not exist
except Exception:
# Create table and try again
self.create()
sess.execute(stmt)
return self.read(conversation_id=conversation.id)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.0.23"
version = "2.0.24"
description = "AI Toolkit for Engineers"
requires-python = ">=3.7"
readme = "README.md"
Expand Down

0 comments on commit 74f7d63

Please sign in to comment.