@@ -32,7 +32,11 @@ def __init__(self, api_key: str):
3232 self .token = None
3333 self .token_expiry = 0
3434 self .token_api_key = None
35- self ._token_path = token_dir / ".quotient" / f"{ api_key [- 6 :]+ '_' if api_key else '' } auth_token.json"
35+ self ._token_path = (
36+ token_dir
37+ / ".quotient"
38+ / f"{ api_key [- 6 :]+ '_' if api_key else '' } auth_token.json"
39+ )
3640
3741 # Try to load existing token
3842 self ._load_token ()
@@ -43,7 +47,8 @@ def __init__(self, api_key: str):
4347 )
4448
4549 super ().__init__ (
46- base_url = "https://api.quotientai.co/api/v1" ,
50+ # base_url="https://api.quotientai.co/api/v1",
51+ base_url = "http://127.0.0.1:8082/api/v1" ,
4752 headers = {"Authorization" : auth_header },
4853 )
4954
@@ -56,11 +61,15 @@ def _save_token(self, token: str, expiry: int):
5661 try :
5762 self ._token_path .parent .mkdir (parents = True , exist_ok = True )
5863 except Exception :
59- logger .error (f"could not create directory for token. if you see this error please notify us at contact@quotientai.co" )
64+ logger .error (
65+ f"could not create directory for token. if you see this error please notify us at contact@quotientai.co"
66+ )
6067 return None
6168 # Save to disk
6269 with open (self ._token_path , "w" ) as f :
63- json .dump ({"token" : token , "expires_at" : expiry , "api_key" : self .api_key }, f )
70+ json .dump (
71+ {"token" : token , "expires_at" : expiry , "api_key" : self .api_key }, f
72+ )
6473
6574 def _load_token (self ):
6675 """Load token from disk if available"""
@@ -80,10 +89,10 @@ def _load_token(self):
8089 def _is_token_valid (self ):
8190 """Check if token exists and is not expired"""
8291 self ._load_token ()
83-
92+
8493 if not self .token :
8594 return False
86-
95+
8796 if self .token_api_key != self .api_key :
8897 return False
8998
@@ -210,7 +219,7 @@ def init(
210219 if not (0.0 <= self .sample_rate <= 1.0 ):
211220 logger .error (f"sample_rate must be between 0.0 and 1.0" )
212221 return None
213-
222+
214223 self .hallucination_detection = hallucination_detection
215224 self .inconsistency_detection = inconsistency_detection
216225 self ._configured = True
@@ -242,7 +251,9 @@ async def log(
242251 underlying non_blocking_create function.
243252 """
244253 if not self ._configured :
245- logger .error (f"Logger is not configured. Please call init() before logging." )
254+ logger .error (
255+ f"Logger is not configured. Please call init() before logging."
256+ )
246257 return None
247258
248259 # Merge default tags with any tags provided at log time.
@@ -269,15 +280,19 @@ async def log(
269280 try :
270281 LogDocument (** doc )
271282 except Exception as e :
272- logger .error (f"Invalid document format: Documents must include 'page_content' field and optional 'metadata' object with string keys." )
283+ logger .error (
284+ f"Invalid document format: Documents must include 'page_content' field and optional 'metadata' object with string keys."
285+ )
273286 return None
274287 else :
275288 actual_type = type (doc ).__name__
276- logger .error (f"Invalid document type: Received { actual_type } , but documents must be strings or dictionaries." )
289+ logger .error (
290+ f"Invalid document type: Received { actual_type } , but documents must be strings or dictionaries."
291+ )
277292 return None
278-
293+
279294 if self ._should_sample ():
280- await self .logs_resource .create (
295+ log_id = await self .logs_resource .create (
281296 app_name = self .app_name ,
282297 environment = self .environment ,
283298 user_query = user_query ,
@@ -290,7 +305,7 @@ async def log(
290305 inconsistency_detection = inconsistency_detection ,
291306 hallucination_detection_sample_rate = self .hallucination_detection_sample_rate ,
292307 )
293-
308+ return log_id
294309 return None
295310
296311
@@ -310,9 +325,11 @@ class AsyncQuotientAI:
310325 def __init__ (self , api_key : Optional [str ] = None ):
311326 self .api_key = api_key or os .environ .get ("QUOTIENT_API_KEY" )
312327 if not self .api_key :
313- logger .error ("could not find API key. either pass api_key to AsyncQuotientAI() or "
328+ logger .error (
329+ "could not find API key. either pass api_key to AsyncQuotientAI() or "
314330 "set the QUOTIENT_API_KEY environment variable. "
315- f"if you do not have an API key, you can create one at https://app.quotientai.co in your settings page" )
331+ f"if you do not have an API key, you can create one at https://app.quotientai.co in your settings page"
332+ )
316333
317334 self ._client = _AsyncQuotientClient (self .api_key )
318335 self .auth = AsyncAuthResource (self ._client )
@@ -331,7 +348,8 @@ def __init__(self, api_key: Optional[str] = None):
331348 except Exception as e :
332349 logger .error (
333350 "If you are seeing this error, please check that your API key is correct.\n "
334- f"If the issue persists, please contact support@quotientai.co\n { traceback .format_exc ()} " )
351+ f"If the issue persists, please contact support@quotientai.co\n { traceback .format_exc ()} "
352+ )
335353 return None
336354
337355 async def evaluate (
@@ -362,9 +380,11 @@ def _validate_parameters(parameters):
362380
363381 invalid_parameters = set (parameters .keys ()) - set (valid_parameters )
364382 if invalid_parameters :
365- logger .error (f"invalid parameters: { ', ' .join (invalid_parameters )} . \n valid parameters are: { ', ' .join (valid_parameters )} " )
383+ logger .error (
384+ f"invalid parameters: { ', ' .join (invalid_parameters )} . \n valid parameters are: { ', ' .join (valid_parameters )} "
385+ )
366386 return None
367-
387+
368388 return parameters
369389
370390 v_parameters = _validate_parameters (parameters )
0 commit comments