Skip to content
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ea2d5fe
feature: implement websocket streaming for inputs
Deepansharora27 Sep 12, 2023
3428ff5
feature: implement event loop for asynch execution of main()
Deepansharora27 Sep 12, 2023
fa2eec4
feature: update websockets connection URI
Deepansharora27 Sep 12, 2023
4110e71
argument parsing
Deepansharora27 Sep 12, 2023
e3620e4
modifications
Deepansharora27 Sep 12, 2023
10f7920
async await changes
Deepansharora27 Sep 12, 2023
de41feb
modify websocket server URI
Deepansharora27 Sep 12, 2023
c9d3385
Modification to input streaming handler over WebSockets
Deepansharora27 Sep 12, 2023
66fcb18
embed websockets connection uri
Deepansharora27 Sep 12, 2023
994eebc
temporary ssl validation removal
Deepansharora27 Sep 12, 2023
d1fd064
role bindings for fashchat
Deepansharora27 Sep 12, 2023
933acef
sending response back to websocket server
Deepansharora27 Sep 12, 2023
5d3898d
temporarily removing response return
Deepansharora27 Sep 12, 2023
6ae53ac
temp return statement
Deepansharora27 Sep 12, 2023
6426e5e
putting back the return statement to avoid infinite loop
Deepansharora27 Sep 12, 2023
42898d4
indentation change
Deepansharora27 Sep 12, 2023
b788cec
further changes
Deepansharora27 Sep 12, 2023
1f15122
changing function signature for prompt for input method
Deepansharora27 Sep 12, 2023
a3a1f0d
amendment to prompt for input method
Deepansharora27 Sep 12, 2023
9bae789
changign method signature to await() method
Deepansharora27 Sep 12, 2023
cb896e5
changes
Deepansharora27 Sep 12, 2023
e143d70
further changes
Deepansharora27 Sep 12, 2023
b078c5d
changing method signature for chat_websocket_client()
Deepansharora27 Sep 12, 2023
1e65e60
removing await()
Deepansharora27 Sep 12, 2023
0a50b89
reverting back changes
Deepansharora27 Sep 12, 2023
99e78e0
changing the method type to receive output
Deepansharora27 Sep 12, 2023
16a4d9f
latest changes
Deepansharora27 Sep 19, 2023
9e8740a
removing the infinite loop
Deepansharora27 Sep 19, 2023
ae43ad9
removing multiline inputs
Deepansharora27 Sep 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions fastchat/serve/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
import re
import sys
import ssl

from prompt_toolkit import PromptSession
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
Expand All @@ -22,29 +23,57 @@
from rich.console import Console
from rich.live import Live
from rich.markdown import Markdown
import asyncio
import websockets

from fastchat.model.model_adapter import add_model_args
from fastchat.modules.gptq import GptqConfig
from fastchat.serve.inference import ChatIO, chat_loop




class SimpleChatIO(ChatIO):
def __init__(self, multiline: bool = False):
def __init__(self, websocket, multiline: bool = False):
self._multiline = multiline
self.websocket = websocket

def prompt_for_input(self, role) -> str:
if not self._multiline:
return input(f"{role}: ")
async def chat_websocket_client(self)-> str:
# URI to Point to the Proxy WebSocket Gin Server so that it can relay the message:
uri = "wss://35.209.170.184:8080/ws"
async with websockets.connect(uri, ssl=ssl.SSLContext()) as websocket:
# while True:
try:
user_input = await websocket.recv()
response = "User Input we got" + user_input
print(response)
print(user_input)
await websocket.send(response)
task = asyncio.create_task(self.prompt_for_input("USER"))
return user_input
except websockets.exceptions.ConnectionClosed:
print("Connection Closed")





async def prompt_for_input(self, role) -> str:
# if not self._multiline:
# return input(f"{role}: ")

prompt_data = []
line = input(f"{role} [ctrl-d/z on empty line to end]: ")
while True:
# line = input(f"{role} [ctrl-d/z on empty line to end]: ")
# line = self.receive_input_from_websocket(role + f" [ctrl-d/z on empty line to end]: ")
line = await self.chat_websocket_client()
while line:
prompt_data.append(line.strip())
try:
line = input()
line = self.chat_websocket_client()
except EOFError as e:
break
return "\n".join(prompt_data)


def prompt_for_output(self, role: str):
print(f"{role}: ", end="", flush=True)
Expand Down Expand Up @@ -160,6 +189,8 @@ def stream_output(self, output_stream):


def main(args):
# First of all we retrieve the Event Loop
# asyncio.get_event_loop().run_until_complete(SimpleChatIO.chat_websocket_client())
if args.gpus:
if len(args.gpus.split(",")) < args.num_gpus:
raise ValueError(
Expand All @@ -169,7 +200,10 @@ def main(args):
os.environ["XPU_VISIBLE_DEVICES"] = args.gpus

if args.style == "simple":
chatio = SimpleChatIO(args.multiline)
websocket = websockets.connect("wss://35.209.170.184:8080/ws")
chatio = SimpleChatIO(websocket,args.multiline)
# asyncio.get_event_loop().run_until_complete(SimpleChatIO.chat_websocket_client())
asyncio.run(chatio.chat_websocket_client())
elif args.style == "rich":
chatio = RichChatIO(args.multiline, args.mouse)
elif args.style == "programmatic":
Expand All @@ -180,6 +214,7 @@ def main(args):
chatio = FileInputChatIO(root_input_file_path)
else:
raise ValueError(f"Invalid style for console: {args.style}")

try:
chat_loop(
args.model_path,
Expand Down