Skip to content

Commit

Permalink
refactor: rename CodyClient to CodyServer and update related methods
Browse files Browse the repository at this point in the history
- Rename the `CodyClient` class to `CodyServer` to better reflect its purpose
- Update the `init` method to instantiate `CodyServer` instead of `CodyClient`
- Rename `set_agent_specs` method to `initialize_agent` for clarity
- Rename `cleanup_server_connection` method to `cleanup_server` for consistency
- Update `CodyAgent` constructor and `init` method to accept `CodyServer` instead of `CodyClient`
- Rename `submit_chat_message` method to `chat` for simplicity
- Update references to `CodyClient` in `main.py` to use `CodyServer` instead
  • Loading branch information
PriNova committed Apr 5, 2024
1 parent c194e48 commit 13f2d0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions cody_agent_py/cody_agent_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from .server_info import CodyAgentSpecs


class CodyClient:
class CodyServer:

async def init(
binary_path: str, use_tcp: bool = False, is_debugging: bool = False
) -> Self:
cody_agent = CodyClient(binary_path, use_tcp, is_debugging)
cody_agent = CodyServer(binary_path, use_tcp, is_debugging)
await cody_agent._create_server_connection()
return cody_agent

Expand Down Expand Up @@ -74,7 +74,7 @@ async def _create_server_connection(self):
print("Could not connect to server. Exiting...")
sys.exit(1)

async def set_agent_specs(
async def initialize_agent(
self,
agent_specs: AgentSpecs,
debug_method_map,
Expand All @@ -88,7 +88,7 @@ async def callback(result):
print("--- Server is authenticated ---")
else:
print("--- Server is not authenticated ---")
await self.cleanup_server_connection(self)
await self.cleanup_server(self)
return None
return await CodyAgent.init(self)

Expand All @@ -102,21 +102,21 @@ async def callback(result):
callback,
)

async def cleanup_server_connection(self):
async def cleanup_server(self):
await _send_jsonrpc_request(self._writer, "shutdown", None)
if self._process.returncode is None:
self._process.terminate()
await self._process.wait()


class CodyAgent:
def __init__(self, cody_client: CodyClient) -> None:
def __init__(self, cody_client: CodyServer) -> None:
self._cody_client = cody_client
self.chat_id: str | None = None
async def init(cody_client: CodyClient):

async def init(cody_client: CodyServer):
return CodyAgent(cody_client)

async def new_chat(self, debug_method_map, is_debugging: bool = False):
async def callback(result):
self.chat_id = result
Expand Down Expand Up @@ -170,18 +170,18 @@ async def callback(result):
callback,
)

async def submit_chat_message(
async def chat(
self,
message,
enhanced_context: bool,
debug_method_map,
is_debugging: bool = False,
) -> Tuple[str, str]:

if message == "/quit":
await self._cody_client.cleanup_server_connection()
await self._cody_client.cleanup_server()
sys.exit(0)

chat_message_request = {
"id": f"{self.chat_id}",
"message": {
Expand Down
12 changes: 6 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dotenv import load_dotenv

from cody_agent_py.client_info import AgentSpecs
from cody_agent_py.cody_agent_py import CodyAgent, CodyClient
from cody_agent_py.cody_agent_py import CodyAgent, CodyServer
from cody_agent_py.config import get_debug_map

load_dotenv()
Expand All @@ -17,7 +17,7 @@ async def main():
debug_method_map: Dict[str, Any] = await get_debug_map()

print("--- Create Server Connection ---")
cody_client: CodyClient = await CodyClient.init(
cody_server: CodyServer = await CodyServer.init(
binary_path="/home/prinova/CodeProjects/cody/agent/dist", is_debugging=True
)

Expand All @@ -31,7 +31,7 @@ async def main():
)

print("--- Initialize Agent ---")
cody_agent: CodyAgent = await cody_client.set_agent_specs(
cody_agent: CodyAgent = await cody_server.initialize_agent(
agent_specs=agent_specs, debug_method_map=debug_method_map, is_debugging=True
)

Expand All @@ -57,7 +57,7 @@ async def main():

# Wait for input from user in the CLI terminal
message: str = input("Human: ")
(speaker, message) = await cody_agent.submit_chat_message(
(speaker, message) = await cody_agent.chat(
message=message,
enhanced_context=False,
debug_method_map=debug_method_map,
Expand All @@ -66,15 +66,15 @@ async def main():

if speaker == "" or message == "":
print("--- Failed to submit chat message ---")
await cody_client.cleanup_server_connection()
await cody_server.cleanup_server()
return None

output = f"{speaker.capitalize()}: {message}\n"
print(output)

debug_method_map["webview/postMessage"] = True

await cody_client.cleanup_server_connection()
await cody_server.cleanup_server()
return None


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="CodyAgentPy",
version="0.1.0",
version="0.1.1",
description="A Python wrapper binding to Cody Agent through establishing a connection to the Cody-Agent server from Sourcegraph Cody using JSON-RPC protocol over a TCP/stdio connection.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 13f2d0f

Please sign in to comment.