@@ -198,10 +198,6 @@ def accumulate(self, chunk):
198198 chunk_copy ["content" ] = ""
199199 self .messages .append (chunk_copy )
200200
201- print ("ADDED CHUNK:" , chunk )
202- print ("MESSAGES IS NOW:" , self .messages )
203- # time.sleep(5)
204-
205201 elif type (chunk ) == bytes :
206202 if self .messages [- 1 ]["content" ] == "" : # We initialize as an empty string ^
207203 self .messages [- 1 ]["content" ] = b"" # But it actually should be bytes
@@ -282,7 +278,7 @@ async def home():
282278 } else {
283279 var startMessageBlock = {
284280 "role": "user",
285- "type": "message",
281+ // "type": "message",
286282 "start": true
287283 };
288284 ws.send(JSON.stringify(startMessageBlock));
@@ -296,7 +292,7 @@ async def home():
296292
297293 var endMessageBlock = {
298294 "role": "user",
299- "type": "message",
295+ // "type": "message",
300296 "end": true
301297 };
302298 ws.send(JSON.stringify(endMessageBlock));
@@ -649,21 +645,38 @@ async def chat_completion(request: ChatCompletionRequest):
649645
650646
651647class Server :
652- def __init__ (self , async_interpreter , host = host , port = port ):
648+ def __init__ (self , async_interpreter , host = "127.0.0.1" , port = 8000 ):
653649 self .app = FastAPI ()
654650 router = create_router (async_interpreter )
655651 self .app .include_router (router )
656- self .host = host
657- self .port = port
658-
659- def run (self , retries = 5 , * args , ** kwargs ):
660- if "host" in kwargs :
661- self .host = kwargs .pop ("host" )
662- if "port" in kwargs :
663- self .port = kwargs .pop ("port" )
664- if "app" in kwargs :
665- self .app = kwargs .pop ("app" )
666-
652+ self .config = uvicorn .Config (app = self .app , host = host , port = port )
653+ self .uvicorn_server = uvicorn .Server (self .config )
654+
655+ @property
656+ def host (self ):
657+ return self .config .host
658+
659+ @host .setter
660+ def host (self , value ):
661+ self .config .host = value
662+ self .uvicorn_server = uvicorn .Server (self .config )
663+
664+ @property
665+ def port (self ):
666+ return self .config .port
667+
668+ @port .setter
669+ def port (self , value ):
670+ self .config .port = value
671+ self .uvicorn_server = uvicorn .Server (self .config )
672+
673+ def run (self , host = None , port = None , retries = 5 ):
674+ if host is not None :
675+ self .host = host
676+ if port is not None :
677+ self .port = port
678+
679+ # Print server information
667680 if self .host == "0.0.0.0" :
668681 print (
669682 "Warning: Using host `0.0.0.0` will expose Open Interpreter over your local network."
@@ -672,12 +685,12 @@ def run(self, retries=5, *args, **kwargs):
672685 s .connect (("8.8.8.8" , 80 )) # Google's public DNS server
673686 print (f"Server will run at http://{ s .getsockname ()[0 ]} :{ self .port } " )
674687 s .close ()
688+ else :
689+ print (f"Server will run at http://{ self .host } :{ self .port } " )
675690
676691 for _ in range (retries ):
677692 try :
678- uvicorn .run (
679- app = self .app , host = self .host , port = self .port , * args , ** kwargs
680- )
693+ self .uvicorn_server .run ()
681694 break
682695 except KeyboardInterrupt :
683696 break
0 commit comments