From 8814e86f8ef3cac8f1949a7adf678606fdec6764 Mon Sep 17 00:00:00 2001 From: Rishabh Srivastava Date: Thu, 23 Jan 2025 17:04:15 +0800 Subject: [PATCH] convert to cost_in_cents --- defog_utils/utils_llm.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/defog_utils/utils_llm.py b/defog_utils/utils_llm.py index 60bae8b..8239cb6 100644 --- a/defog_utils/utils_llm.py +++ b/defog_utils/utils_llm.py @@ -38,7 +38,7 @@ class LLMResponse: input_tokens: int output_tokens: int output_tokens_details: Optional[Dict[str, int]] = None - cost: Optional[float] = None + cost_in_cents: Optional[float] = None def __post_init__(self): if self.model in LLM_COSTS_PER_TOKEN: @@ -59,13 +59,14 @@ def __post_init__(self): model_name = max(potential_model_names, key=len) if model_name: - self.cost = ( + self.cost_in_cents = ( self.input_tokens / 1000 * LLM_COSTS_PER_TOKEN[model_name]["input_cost_per1k"] + self.output_tokens / 1000 * LLM_COSTS_PER_TOKEN[model_name]["output_cost_per1k"] + * 100 ) @@ -289,11 +290,9 @@ async def chat_openai_async( if "response_format" in request_params and request_params["response_format"]: response = await client_openai.beta.chat.completions.parse(**request_params) - print(response) content = response.choices[0].message.parsed else: response = await client_openai.chat.completions.create(**request_params) - print(response) content = response.choices[0].message.content if response.choices[0].finish_reason == "length":