Skip to content

Commit

Permalink
v2.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Oct 1, 2023
1 parent 7fa1b4e commit 939dea1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
14 changes: 6 additions & 8 deletions phi/ai/phi_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions phi/api/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion phi/api/schemas/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ class ConversationClient(str, Enum):


class ConversationCreateResponse(BaseModel):
id: int
id: str
chat_history: List[Dict[str, Any]]
6 changes: 5 additions & 1 deletion phi/conversation/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion phi/docker/app/redis/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.10"
version = "2.0.11"
description = "AI Toolkit for Engineers"
requires-python = ">=3.7"
readme = "README.md"
Expand Down

0 comments on commit 939dea1

Please sign in to comment.