1
1
import json
2
2
import multiprocessing
3
+ import redis
3
4
from threading import Lock
4
5
from functools import partial
5
6
from typing import Iterator , List , Optional , Union , Dict
@@ -85,13 +86,22 @@ class Settings(BaseSettings):
85
86
port : int = Field (
86
87
default = 8000 , description = "Listen port"
87
88
)
89
+ redishost : str = Field (
90
+ default = "None" , description = "Redis server address"
91
+ )
92
+ redisport : int = Field (
93
+ default = 6379 , description = "Redis server port"
94
+ )
95
+ redisdb : int = Field (
96
+ default = 0 , description = "Redis server db"
97
+ )
88
98
89
99
90
100
router = APIRouter ()
91
101
92
102
settings : Optional [Settings ] = None
93
103
llama : Optional [llama_cpp .Llama ] = None
94
-
104
+ rediscon : Optional [ redis . StrictRedis ] = None
95
105
96
106
def create_app (settings : Optional [Settings ] = None ):
97
107
if settings is None :
@@ -108,6 +118,14 @@ def create_app(settings: Optional[Settings] = None):
108
118
allow_headers = ["*" ],
109
119
)
110
120
app .include_router (router )
121
+
122
+ if settings .redishost != 'None' :
123
+ global rediscon
124
+ try :
125
+ redscon = redis .StrictRedis (host = settings .redishost , port = settings .redisport , db = settings .redisdb )
126
+ except Exception as e :
127
+ print (e )
128
+
111
129
global llama
112
130
llama = llama_cpp .Llama (
113
131
model_path = settings .model ,
@@ -506,7 +524,11 @@ async def event_publisher(inner_send_chan: MemoryObjectSendStream):
506
524
raise anyio .get_cancelled_exc_class ()()
507
525
await inner_send_chan .send (dict (data = "[DONE]" ))
508
526
log ['messages' ].append ({'role' :streamRole , 'content' :streamContent })
509
- print (json .dumps (log ,indent = 4 ))
527
+
528
+ #print(json.dumps(log,indent=4))
529
+ if rediscon is not None :
530
+ logstr = json .dumps (log )
531
+ rediscon .rpush ('llama.cpp' , logstr )
510
532
511
533
except anyio .get_cancelled_exc_class () as e :
512
534
print ("disconnected" )
0 commit comments