add response ms to response object

This commit is contained in:
Krrish Dholakia 2023-09-20 19:50:38 -07:00
parent fc922bc300
commit 39c3f2d6ec
4 changed files with 9 additions and 3 deletions

View file

@ -791,7 +791,8 @@ def test_completion_ai21():
try: try:
response = completion(model=model_name, messages=messages) response = completion(model=model_name, messages=messages)
# Add any assertions here to check the response # Add any assertions here to check the response
print(response) print(response["response_ms"])
print(response.response_ms)
except Exception as e: except Exception as e:
pytest.fail(f"Error occurred: {e}") pytest.fail(f"Error occurred: {e}")

View file

@ -123,7 +123,7 @@ class StreamingChoices(OpenAIObject):
self.delta = Delta() self.delta = Delta()
class ModelResponse(OpenAIObject): class ModelResponse(OpenAIObject):
def __init__(self, id=None, choices=None, created=None, model=None, usage=None, stream=False, **params): def __init__(self, id=None, choices=None, created=None, model=None, usage=None, stream=False, response_ms=None, **params):
if stream: if stream:
self.object = "chat.completion.chunk" self.object = "chat.completion.chunk"
self.choices = [StreamingChoices()] self.choices = [StreamingChoices()]
@ -141,6 +141,10 @@ class ModelResponse(OpenAIObject):
self.created = int(time.time()) self.created = int(time.time())
else: else:
self.created = created self.created = created
if response_ms:
response_ms = response_ms
else:
response_ms = None
self.model = model self.model = model
self.usage = ( self.usage = (
usage usage
@ -624,6 +628,7 @@ def client(original_function):
) # don't interrupt execution of main thread ) # don't interrupt execution of main thread
my_thread.start() my_thread.start()
# RETURN RESULT # RETURN RESULT
result.response_ms = (end_time - start_time).total_seconds() * 1000 # return response latency in ms like openai
return result return result
except Exception as e: except Exception as e:
traceback_exception = traceback.format_exc() traceback_exception = traceback.format_exc()

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "litellm" name = "litellm"
version = "0.1.717" version = "0.1.718"
description = "Library to easily interface with LLM API providers" description = "Library to easily interface with LLM API providers"
authors = ["BerriAI"] authors = ["BerriAI"]
license = "MIT License" license = "MIT License"