@@ -198,10 +198,6 @@ def accumulate(self, chunk):
198
198
chunk_copy ["content" ] = ""
199
199
self .messages .append (chunk_copy )
200
200
201
- print ("ADDED CHUNK:" , chunk )
202
- print ("MESSAGES IS NOW:" , self .messages )
203
- # time.sleep(5)
204
-
205
201
elif type (chunk ) == bytes :
206
202
if self .messages [- 1 ]["content" ] == "" : # We initialize as an empty string ^
207
203
self .messages [- 1 ]["content" ] = b"" # But it actually should be bytes
@@ -282,7 +278,7 @@ async def home():
282
278
} else {
283
279
var startMessageBlock = {
284
280
"role": "user",
285
- "type": "message",
281
+ // "type": "message",
286
282
"start": true
287
283
};
288
284
ws.send(JSON.stringify(startMessageBlock));
@@ -296,7 +292,7 @@ async def home():
296
292
297
293
var endMessageBlock = {
298
294
"role": "user",
299
- "type": "message",
295
+ // "type": "message",
300
296
"end": true
301
297
};
302
298
ws.send(JSON.stringify(endMessageBlock));
@@ -649,21 +645,38 @@ async def chat_completion(request: ChatCompletionRequest):
649
645
650
646
651
647
class Server :
652
- def __init__ (self , async_interpreter , host = host , port = port ):
648
+ def __init__ (self , async_interpreter , host = "127.0.0.1" , port = 8000 ):
653
649
self .app = FastAPI ()
654
650
router = create_router (async_interpreter )
655
651
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
667
680
if self .host == "0.0.0.0" :
668
681
print (
669
682
"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):
672
685
s .connect (("8.8.8.8" , 80 )) # Google's public DNS server
673
686
print (f"Server will run at http://{ s .getsockname ()[0 ]} :{ self .port } " )
674
687
s .close ()
688
+ else :
689
+ print (f"Server will run at http://{ self .host } :{ self .port } " )
675
690
676
691
for _ in range (retries ):
677
692
try :
678
- uvicorn .run (
679
- app = self .app , host = self .host , port = self .port , * args , ** kwargs
680
- )
693
+ self .uvicorn_server .run ()
681
694
break
682
695
except KeyboardInterrupt :
683
696
break
0 commit comments