From 939dea1c075070545e5bb8641d908bb8b1b7701c Mon Sep 17 00:00:00 2001 From: Ashpreet Bedi Date: Sun, 1 Oct 2023 15:22:02 +0100 Subject: [PATCH] v2.0.11 --- phi/ai/phi_ai.py | 14 ++++++-------- phi/api/ai.py | 10 +++++++--- phi/api/schemas/ai.py | 2 +- phi/conversation/conversation.py | 6 +++++- phi/docker/app/redis/redis.py | 2 +- pyproject.toml | 2 +- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/phi/ai/phi_ai.py b/phi/ai/phi_ai.py index c6d2c460d..487642227 100644 --- a/phi/ai/phi_ai.py +++ b/phi/ai/phi_ai.py @@ -80,7 +80,7 @@ def __init__( self.phi_config: PhiCliConfig = _phi_config self.user: UserSchema = _user self.active_workspace: Optional[WorkspaceConfig] = _active_workspace - self.conversation_id: int = _conversation_id + self.conversation_id: str = _conversation_id self.conversation_history: List[Dict[str, Any]] = _conversation_history or [] self.conversation_type: ConversationType = conversation_type @@ -92,24 +92,22 @@ def start_conversation(self, stream: bool = False): while conversation_active: username = self.user.username or "You" console.rule() + user_message_str = None user_message_str_valid = False while not user_message_str_valid: user_message_str = Prompt.ask(f"[bold] :sunglasses: {username} [/bold]", console=console) - if ( - user_message_str - is None - # or user_message_str == "" - # or user_message_str == "{}" - # or len(user_message_str) == 0 - ): + if user_message_str is None or user_message_str == "": console.print("Please enter a valid message") continue user_message_str_valid = True + if user_message_str is None: + raise ValueError("Message invalid") self.conversation_history.append({"role": "user", "content": user_message_str}) # -*- Quit conversation if user_message_str in ("exit", "quit", "bye"): conversation_active = False + break # -*- Send message to Phi AI api_response: Optional[Iterator[str]] = conversation_chat( diff --git a/phi/api/ai.py b/phi/api/ai.py index b1b69c0a7..e1dae5e1d 100644 --- a/phi/api/ai.py +++ b/phi/api/ai.py @@ -54,7 +54,7 @@ def conversation_create( def conversation_chat( user: UserSchema, - conversation_id: int, + conversation_id: str, message: Message, conversation_type: ConversationType = ConversationType.RAG, functions: Optional[Dict[str, Function]] = None, @@ -87,7 +87,9 @@ def conversation_chat( for chunk in streaming_resp.iter_text(): yield chunk except Exception as e: - logger.debug(f"Failed conversation chat: {e}") + logger.error(f"Error: {e}") + logger.info("Please message us on https://discord.gg/4MtYHHrgA8 for help.") + exit(1) else: logger.debug("--o-o-- Conversation Chat") try: @@ -119,7 +121,9 @@ def conversation_chat( yield response_json.get("response") except Exception as e: - logger.debug(f"Failed conversation chat: {e}") + logger.error(f"Error: {e}") + logger.info("Please message us on https://discord.gg/4MtYHHrgA8 for help.") + exit(1) return None diff --git a/phi/api/schemas/ai.py b/phi/api/schemas/ai.py index b1f7684bf..70deb909e 100644 --- a/phi/api/schemas/ai.py +++ b/phi/api/schemas/ai.py @@ -15,5 +15,5 @@ class ConversationClient(str, Enum): class ConversationCreateResponse(BaseModel): - id: int + id: str chat_history: List[Dict[str, Any]] diff --git a/phi/conversation/conversation.py b/phi/conversation/conversation.py index e9a732be3..834dab318 100644 --- a/phi/conversation/conversation.py +++ b/phi/conversation/conversation.py @@ -33,7 +33,7 @@ class Conversation(BaseModel): # -*- Conversation settings # Conversation UUID - id: str = Field(default_factory=lambda: str(uuid4())) + id: Optional[str] = Field(None, validate_default=True) # Conversation name name: Optional[str] = None # True if this conversation is active i.e. not ended @@ -133,6 +133,10 @@ class Conversation(BaseModel): model_config = ConfigDict(arbitrary_types_allowed=True) + @field_validator("id", mode="before") + def set_conversation_id(cls, v: Optional[str]) -> str: + return v if v is not None else str(uuid4()) + @field_validator("debug_mode", mode="before") def set_log_level(cls, v: bool) -> bool: if v: diff --git a/phi/docker/app/redis/redis.py b/phi/docker/app/redis/redis.py index 6d6296d1d..149a9bae7 100644 --- a/phi/docker/app/redis/redis.py +++ b/phi/docker/app/redis/redis.py @@ -10,7 +10,7 @@ class Redis(DockerApp, DbApp): # -*- Image Configuration image_name: str = "redis" - image_tag: str = "7.2.0" + image_tag: str = "7.2.1" # -*- App Ports # Open a container port if open_port=True diff --git a/pyproject.toml b/pyproject.toml index 830e34a72..6e27b695a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "phidata" -version = "2.0.10" +version = "2.0.11" description = "AI Toolkit for Engineers" requires-python = ">=3.7" readme = "README.md"