From c94ee62bcf220a95c2e214abf3e749ff0ff665d2 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 9 Oct 2023 17:07:42 -0700 Subject: [PATCH] (feat) allow messages to be passed in completion_cost --- litellm/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index 55669b0e1f..037be2c7ed 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -869,6 +869,7 @@ def completion_cost( completion_response=None, model="gpt-3.5-turbo", prompt="", + messages: List = [], completion="", total_time=0.0, # used for replicate ): @@ -898,6 +899,8 @@ def completion_cost( - If an error occurs during execution, the function returns 0.0 without blocking the user's execution path. """ try: + if messages != []: + prompt = " ".join([message["content"] for message in messages]) # Handle Inputs to completion_cost prompt_tokens = 0 completion_tokens = 0