1414
1515import json
1616import threading
17- from veadk . utils . misc import getenv
17+
1818from volcengine .ApiInfo import ApiInfo
1919from volcengine .auth .SignerV4 import SignerV4
2020from volcengine .base .Service import Service
2121from volcengine .Credentials import Credentials
2222from volcengine .ServiceInfo import ServiceInfo
2323
24+ from veadk .utils .misc import getenv
25+
2426
2527class VikingDBMemoryException (Exception ):
2628 def __init__ (self , code , request_id , message = None ):
@@ -56,7 +58,9 @@ def __init__(
5658 socket_timeout = 30 ,
5759 ):
5860 env_host = getenv (
59- "DATABASE_VIKINGMEM_BASE_URL" , default_value = None , allow_false_values = True
61+ "DATABASE_VIKINGMEM_BASE_URL" ,
62+ default_value = None ,
63+ allow_false_values = True ,
6064 )
6165 if env_host :
6266 if env_host .startswith ("http://" ):
@@ -85,7 +89,9 @@ def __init__(
8589 self .get_body ("Ping" , {}, json .dumps ({}))
8690 except Exception as e :
8791 raise VikingDBMemoryException (
88- 1000028 , "missed" , "host or region is incorrect: {}" .format (str (e ))
92+ 1000028 ,
93+ "missed" ,
94+ "host or region is incorrect: {}" .format (str (e )),
8995 ) from None
9096
9197 def setHeader (self , header ):
@@ -118,49 +124,70 @@ def get_api_info():
118124 "/api/memory/collection/create" ,
119125 {},
120126 {},
121- {"Accept" : "application/json" , "Content-Type" : "application/json" },
127+ {
128+ "Accept" : "application/json" ,
129+ "Content-Type" : "application/json" ,
130+ },
122131 ),
123132 "GetCollection" : ApiInfo (
124133 "POST" ,
125134 "/api/memory/collection/info" ,
126135 {},
127136 {},
128- {"Accept" : "application/json" , "Content-Type" : "application/json" },
137+ {
138+ "Accept" : "application/json" ,
139+ "Content-Type" : "application/json" ,
140+ },
129141 ),
130142 "DropCollection" : ApiInfo (
131143 "POST" ,
132144 "/api/memory/collection/delete" ,
133145 {},
134146 {},
135- {"Accept" : "application/json" , "Content-Type" : "application/json" },
147+ {
148+ "Accept" : "application/json" ,
149+ "Content-Type" : "application/json" ,
150+ },
136151 ),
137152 "UpdateCollection" : ApiInfo (
138153 "POST" ,
139154 "/api/memory/collection/update" ,
140155 {},
141156 {},
142- {"Accept" : "application/json" , "Content-Type" : "application/json" },
157+ {
158+ "Accept" : "application/json" ,
159+ "Content-Type" : "application/json" ,
160+ },
143161 ),
144162 "SearchMemory" : ApiInfo (
145163 "POST" ,
146164 "/api/memory/search" ,
147165 {},
148166 {},
149- {"Accept" : "application/json" , "Content-Type" : "application/json" },
167+ {
168+ "Accept" : "application/json" ,
169+ "Content-Type" : "application/json" ,
170+ },
150171 ),
151172 "AddMessages" : ApiInfo (
152173 "POST" ,
153174 "/api/memory/messages/add" ,
154175 {},
155176 {},
156- {"Accept" : "application/json" , "Content-Type" : "application/json" },
177+ {
178+ "Accept" : "application/json" ,
179+ "Content-Type" : "application/json" ,
180+ },
157181 ),
158182 "Ping" : ApiInfo (
159183 "GET" ,
160184 "/api/memory/ping" ,
161185 {},
162186 {},
163- {"Accept" : "application/json" , "Content-Type" : "application/json" },
187+ {
188+ "Accept" : "application/json" ,
189+ "Content-Type" : "application/json" ,
190+ },
164191 ),
165192 }
166193 return api_info
@@ -199,7 +226,9 @@ def get_body_exception(self, api, params, body):
199226 res_json = json .loads (e .args [0 ].decode ("utf-8" ))
200227 except Exception as e :
201228 raise VikingDBMemoryException (
202- 1000028 , "missed" , "json load res error, res:{}" .format (str (e ))
229+ 1000028 ,
230+ "missed" ,
231+ "json load res error, res:{}" .format (str (e )),
203232 ) from None
204233 code = res_json .get ("code" , 1000028 )
205234 request_id = res_json .get ("request_id" , 1000028 )
@@ -223,7 +252,9 @@ def get_exception(self, api, params):
223252 res_json = json .loads (e .args [0 ].decode ("utf-8" ))
224253 except Exception as e :
225254 raise VikingDBMemoryException (
226- 1000028 , "missed" , "json load res error, res:{}" .format (str (e ))
255+ 1000028 ,
256+ "missed" ,
257+ "json load res error, res:{}" .format (str (e )),
227258 ) from None
228259 code = res_json .get ("code" , 1000028 )
229260 request_id = res_json .get ("request_id" , 1000028 )
@@ -241,13 +272,15 @@ def create_collection(
241272 self ,
242273 collection_name ,
243274 description = "" ,
275+ project = "default" ,
244276 custom_event_type_schemas = [],
245277 custom_entity_type_schemas = [],
246278 builtin_event_types = [],
247279 builtin_entity_types = [],
248280 ):
249281 params = {
250282 "CollectionName" : collection_name ,
283+ "ProjectName" : project ,
251284 "Description" : description ,
252285 "CustomEventTypeSchemas" : custom_event_type_schemas ,
253286 "CustomEntityTypeSchemas" : custom_entity_type_schemas ,
0 commit comments