Skip to content

Commit

Permalink
### feat: enhance agent message handling and add custom exceptions
Browse files Browse the repository at this point in the history
- **agent.py**: Updated the message handling logic to recognize additional exit commands (`/bye` and `/exit`) alongside `/quit`.
- **exceptions.py**: Introduced a new module to define custom exceptions for the CodyPy application:
  - `CodyPyError`: Base class for all CodyPy exceptions.
  - `AgentAuthenticationError`: Raised for errors in the authentication of the Cody agent.
  - `AgentBinaryDownloadError`: Raised when there is an error downloading the Cody Agent binary.
  - `AgentBinaryNotFoundError`: Raised when the Cody Agent binary is not found.
  - `ServerTCPConnectionError`: Raised when there is an error connecting to the server via TCP.
- **main.py**: Removed an unused import (`YELLOW`) from the `codypy.config` module.

These changes improve the robustness of the agent's message handling and introduce a structured way to handle specific errors in the application.
  • Loading branch information
PriNova committed May 27, 2024
1 parent 75dc76c commit bdb7c8c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion codypy/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def chat(
"""
if context_files is None:
context_files = []
if message == "/quit":
if message in ["/quit", "/bye", "/exit"]:
return "", []

chat_message_request = {
Expand Down
36 changes: 36 additions & 0 deletions codypy/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class CodyPyError(Exception):
"""Base class for all CodyPy exceptions."""

pass


class AgentAuthenticationError(CodyPyError):
"""Exception raised for errors in the authentication of the Cody agent."""

def __init__(self, message="Agent authentication failed"):
self.message = message
super().__init__(self.message)


class AgentBinaryDownloadError(CodyPyError):
"""Raised when there is an error downloading the Cody Agent binary."""

def __init__(self, message="Failed to download the Cody Agent binary"):
self.message = message
super().__init__(self.message)


class AgentBinaryNotFoundError(CodyPyError):
"""Raised when the Cody Agent binary is not found."""

def __init__(self, message="Cody Agent binary not found"):
self.message = message
super().__init__(self.message)


class ServerTCPConnectionError(CodyPyError):
"""Raised when there is an error connecting to the server via TCP."""

def __init__(self, message="Could not connect to server via TCP"):
self.message = message
super().__init__(self.message)
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from codypy.agent import CodyAgent
from codypy.client_info import AgentSpecs, Models
from codypy.config import BLUE, GREEN, RESET, YELLOW
from codypy.config import BLUE, GREEN, RESET
from codypy.context import append_paths
from codypy.server import CodyServer

Expand Down

0 comments on commit bdb7c8c

Please sign in to comment.