From b60049b030d44ddaebdcc1a33135e926b67957fe Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 7 Sep 2023 18:02:20 -0700 Subject: [PATCH] fix litedebugger double logging error --- litellm/__pycache__/utils.cpython-311.pyc | Bin 89855 -> 90109 bytes litellm/integrations/litedebugger.py | 6 +++--- .../tests/test_litedebugger_integration.py | 8 +++++--- litellm/utils.py | 17 +++++++++++------ pyproject.toml | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/litellm/__pycache__/utils.cpython-311.pyc b/litellm/__pycache__/utils.cpython-311.pyc index b7522252ed69dbf31aee30e36169a3a623000632..50e93a23ed8e92bf414b680cb3b45871d39496a8 100644 GIT binary patch delta 2585 zcma)74Nw%<9pC@%?cQ?ieZcJ<9LL82$_esyK!Bi_07v2O+J-ikh#!HI1p$ecV@(J> zn>1lgHUw5abw;q&$+wD}ne=ca~W(_U0!ccE3z zIP_p@0??t4vq3cP)XJ6xD@i9?DdfsckGC#>p|&_k)&#Y(2|c$?H1rr^B9fC438|$S zzYKDcert4#fmfCk#t_}6T9`_wuqZCtmzqF3=0Z7Q{zzGugt9FS6;qSqZ3vteRGwx; zda|2urr99@^`xb-cVttt4n3WAdnNMFr*8?YB+AR8F^$V&&L}Eil$Rq%x)WYNjp@$Y zYWP)_iBU@j(qts&<$itpmMz`ewm94!vcJ2x-_aE4D5z=jIO_bpy^hZ90Y|&abW09Y znsFT}&C2GX7Mrp}!j($^Y^LC+RhP=hBC{o}28R$^r#dSdD-QQ}BDX=6vXmy)yyiuYLf z5uTzBk$3I^)lD3Fz4#t-Ep8S&)8Zvzgf!=&g*!OktV0k;N3E`8w851CM)ZKot~c6Z zZm1xO_PdHx763_{@A0A_NM;*_hN?w_bejcom6&h$lQ=*R&(ccWIGlt&FUcSYT1u-4y|?sRkc_&^D(8CICKu0DNGRI~DFm+vJ9@p$X&E&4 z?`UuD=ssk)+#CO$jjHQZAn4y-E0YI(pB;4n|kA~;*#MjI;$Y{FJZF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-1=K&6oYcv1h z;6?J+Kb+xVlpOz)mxn)+nNOayKpa=ibpl6@&l%Gp9(`L0Ww1}ari3#byda;{z}p-g zlQ*WrR{+13n={}v3sX_S1UFzdI%k3bxD3?AJ=!=YTN~c=}E3Z;RGBV1-=ef?5Ebyvq&rzipJ?%LSDJvgF@+;4>BF z^kymSf=b!rh5HrI6@9dVR-2SFDZO3il diff --git a/litellm/integrations/litedebugger.py b/litellm/integrations/litedebugger.py index ef33c7edd7..b18a42db74 100644 --- a/litellm/integrations/litedebugger.py +++ b/litellm/integrations/litedebugger.py @@ -40,7 +40,7 @@ class LiteDebugger: litellm_params, optional_params, ): - print_verbose(f"LiteDebugger: Pre-API Call Logging") + print_verbose(f"LiteDebugger: Pre-API Call Logging for call id {litellm_call_id}") try: print_verbose( f"LiteLLMDebugger: Logging - Enters input logging function for model {model}" @@ -101,7 +101,7 @@ class LiteDebugger: pass def post_call_log_event(self, original_response, litellm_call_id, print_verbose, call_type, stream): - print_verbose(f"LiteDebugger: Post-API Call Logging") + print_verbose(f"LiteDebugger: Post-API Call Logging for call id {litellm_call_id}") try: if call_type == "embedding": litellm_data_obj = { @@ -147,7 +147,7 @@ class LiteDebugger: call_type, stream = False ): - print_verbose(f"LiteDebugger: Success/Failure Call Logging") + print_verbose(f"LiteDebugger: Success/Failure Call Logging for call id {litellm_call_id}") try: print_verbose( f"LiteLLMDebugger: Success/Failure Logging - Enters handler logging function for function {call_type} and stream set to {stream} with response object {response_obj}" diff --git a/litellm/tests/test_litedebugger_integration.py b/litellm/tests/test_litedebugger_integration.py index 018a659165..49ea9a7e37 100644 --- a/litellm/tests/test_litedebugger_integration.py +++ b/litellm/tests/test_litedebugger_integration.py @@ -70,13 +70,15 @@ messages = [{"content": user_message, "role": "user"}] # # Redirect stdout # old_stdout = sys.stdout # sys.stdout = new_stdout = io.StringIO() -# litellm.token = "a67abbaf-35b8-4649-8647-68c5fe8d37fb" # generate one here - https://www.uuidgenerator.net/version4 -# response = completion(model="gpt-3.5-turbo", messages=messages) +# litellm.token = "1e6795ea-a75e-4231-8110-dcc721dcffc3" # generate one here - https://www.uuidgenerator.net/version4 + +# completion(model="gpt-3.5-turbo", messages=messages) +# completion(model="claude-instant-1", messages=messages) # # Restore stdout # sys.stdout = old_stdout # output = new_stdout.getvalue().strip() - +# print(output) # if "LiteDebugger: Pre-API Call Logging" not in output: # raise Exception(f"LiteLLMDebugger: pre-api call not logged!") # if "LiteDebugger: Post-API Call Logging" not in output: diff --git a/litellm/utils.py b/litellm/utils.py index 818f46c9d4..d0a6570d56 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -159,7 +159,7 @@ class Logging: def pre_call(self, input, api_key, model=None, additional_args={}): # Log the exact input to the LLM API - print_verbose(f"Logging Details Pre-API Call") + print_verbose(f"Logging Details Pre-API Call for call id {self.litellm_call_id}") try: # print_verbose(f"logging pre call for model: {self.model} with call type: {self.call_type}") self.model_call_details["input"] = input @@ -200,7 +200,7 @@ class Logging: ) elif callback == "lite_debugger": - print_verbose("reaches litedebugger for logging!") + print_verbose(f"reaches litedebugger for logging! - model_call_details {self.model_call_details}") model = self.model_call_details["model"] messages = self.model_call_details["input"] print_verbose(f"liteDebuggerClient: {liteDebuggerClient}") @@ -294,6 +294,7 @@ class Logging: start_time = self.start_time if end_time is None: end_time = datetime.datetime.now() + print_verbose(f"success callbacks: {litellm.success_callback}") for callback in litellm.success_callback: try: if callback == "lite_debugger": @@ -441,9 +442,12 @@ def client(original_function): function_id = kwargs["id"] if "id" in kwargs else None if litellm.use_client or ("use_client" in kwargs and kwargs["use_client"] == True): print_verbose(f"litedebugger initialized") - litellm.input_callback.append("lite_debugger") - litellm.success_callback.append("lite_debugger") - litellm.failure_callback.append("lite_debugger") + if "lite_debugger" not in litellm.input_callback: + litellm.input_callback.append("lite_debugger") + if "lite_debugger" not in litellm.success_callback: + litellm.success_callback.append("lite_debugger") + if "lite_debugger" not in litellm.failure_callback: + litellm.failure_callback.append("lite_debugger") if ( len(litellm.input_callback) > 0 or len(litellm.success_callback) > 0 @@ -540,7 +544,8 @@ def client(original_function): result['litellm_call_id'] = litellm_call_id # LOG SUCCESS - handle streaming success logging in the _next_ object, remove `handle_success` once it's deprecated - threading.Thread(target=logging_obj.success_handler, args=(result, start_time, end_time)).start() + logging_obj.success_handler(result, start_time, end_time) + # threading.Thread(target=logging_obj.success_handler, args=(result, start_time, end_time)).start() my_thread = threading.Thread( target=handle_success, args=(args, kwargs, result, start_time, end_time) ) # don't interrupt execution of main thread diff --git a/pyproject.toml b/pyproject.toml index 139a194412..5fdb4cd1cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "litellm" -version = "0.1.560" +version = "0.1.561" description = "Library to easily interface with LLM API providers" authors = ["BerriAI"] license = "MIT License"