Skip to content

Commit 0cc99ed

Browse files
committed
Remove unnecessary dependency between repls and llms
Signed-off-by: Sebastiano Mariani <[email protected]>
1 parent 3d7f749 commit 0cc99ed

File tree

4 files changed

+91
-8
lines changed

4 files changed

+91
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,4 @@ pyrightconfig.json
210210
# End of https://www.toptal.com/developers/gitignore/api/python,linux,visualstudiocode
211211
debug.py
212212
styles/debug.css
213+
.env.source

src/llm_repl/llms/chatgpt.py

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class ChatGPTStreamingCallbackHandler(StreamingCallbackHandler):
2727
def __init__(self, repl: BaseREPL) -> None:
2828
super().__init__()
2929
self.repl = repl
30-
self.server_color = repl.style.server_msg_color
3130
self.is_code_mode = False
3231
self.code_block = ""
3332

src/llm_repl/repls/__init__.py

-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ class BaseREPL(ABC):
2020
Base class with all the methods that a REPL should implement
2121
"""
2222

23-
@property
24-
@abstractmethod
25-
def style(self) -> REPLStyle:
26-
"""
27-
Return the style of the REPL
28-
"""
29-
3023
@abstractmethod
3124
def info(self):
3225
"""

src/llm_repl/repls/websocket.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import websockets
2+
import asyncio
3+
4+
from typing import Any
5+
from websockets.server import serve
6+
7+
from llm_repl.repls import BaseREPL, REPLStyle
8+
9+
10+
class WebsockerREPL(BaseREPL):
11+
"""
12+
Base class with all the methods that a REPL should implement
13+
"""
14+
15+
@property
16+
def style(self) -> REPLStyle:
17+
"""
18+
Return the style of the REPL
19+
"""
20+
raise NotImplementedError
21+
22+
def info(self) -> str:
23+
"""
24+
Print the information about the LLM currently loaded
25+
"""
26+
return "This is a websocket REPL"
27+
28+
def exit(self):
29+
"""
30+
Exit the application
31+
"""
32+
pass
33+
34+
def load_llm(self, llm_name: str):
35+
"""
36+
Load the LLM specified by the name and its custom commands if any
37+
38+
:param str llm_name: The name of the LLM to load
39+
"""
40+
pass
41+
42+
def print(self, msg: Any, **kwargs):
43+
"""
44+
Simply prints the message as a normal print statement.
45+
46+
:param Any msg: The message to be printed.
47+
"""
48+
49+
def print_client_msg(self, msg: str):
50+
"""
51+
Prints the client message with the appropriate style
52+
53+
:param str msg: The message to be printed.
54+
"""
55+
56+
def print_server_msg(self, msg: str):
57+
"""
58+
Prints the server message with the appropriate style
59+
60+
:param str msg: The message to be printed.
61+
"""
62+
63+
def print_error_msg(self, msg: str):
64+
"""
65+
Prints the error message with the appropriate style
66+
67+
:param str msg: The message to be printed.
68+
"""
69+
70+
def print_misc_msg(self, msg: str, **kwargs):
71+
"""
72+
Print the miscellaneous message with the appropriate style
73+
74+
:param str msg: The message to be printed.
75+
"""
76+
77+
async def _handle_msg(self, websocket):
78+
async for message in websocket:
79+
print(f"Received message: {message}")
80+
await websocket.send(message)
81+
82+
async def run(self, llm_name):
83+
"""
84+
Starts the REPL
85+
86+
:param str llm_name: The name of the LLM to load
87+
"""
88+
print("Starting websocket REPL")
89+
async with serve(self._handle_msg, "localhost", 8765):
90+
await asyncio.Future()

0 commit comments

Comments
 (0)