mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-27 23:47:46 +00:00
fix: default cost to NaN when calculation fails in LiteLLM backend (#912)
* fix: default cost to NaN when calculation fails in LiteLLM backend * lint * lint
This commit is contained in:
@@ -17,6 +17,7 @@ from typing import Any, Optional, cast
|
||||
import numpy as np
|
||||
import openai
|
||||
import tiktoken
|
||||
from openai.types.chat import ChatCompletion
|
||||
|
||||
from rdagent.core.utils import LLM_CACHE_SEED_GEN, SingletonBaseClass, import_class
|
||||
from rdagent.log import LogColors
|
||||
@@ -385,6 +386,7 @@ class DeprecBackend(APIBackend):
|
||||
if len(chunk.choices) > 0 and chunk.choices[0].finish_reason is not None:
|
||||
finish_reason = chunk.choices[0].finish_reason
|
||||
else:
|
||||
response = cast(ChatCompletion, response)
|
||||
resp = response.choices[0].message.content
|
||||
finish_reason = response.choices[0].finish_reason
|
||||
if LLM_SETTINGS.log_llm_chat_content:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from typing import Any, Literal, cast
|
||||
|
||||
import numpy as np
|
||||
from litellm import (
|
||||
completion,
|
||||
completion_cost,
|
||||
@@ -139,6 +140,7 @@ class LiteLLMAPIBackend(APIBackend):
|
||||
cost = completion_cost(model=model, messages=messages, completion=content)
|
||||
except Exception as e:
|
||||
logger.warning(f"Cost calculation failed for model {model}: {e}. Skip cost statistics.")
|
||||
cost = np.nan
|
||||
else:
|
||||
ACC_COST += cost
|
||||
logger.info(
|
||||
|
||||
@@ -826,7 +826,7 @@ class QTDockerEnv(DockerEnv):
|
||||
def __init__(self, conf: DockerConf = QlibDockerConf()):
|
||||
super().__init__(conf)
|
||||
|
||||
def prepare(self, *args, **kwargs) -> None: # type: ignore[explicit-override, no-untyped-def]
|
||||
def prepare(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def]
|
||||
"""
|
||||
Download image & data if it doesn't exist
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user