Skip to content

Commit 7ea558a

Browse files
committed
Fix #33
1 parent 7738f12 commit 7ea558a

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

llms_wrapper/llms.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,11 @@ def cost_callback(kwargs, completion_response, start_time, end_time):
902902
ret["cost"] = callback_data.get("cost")
903903
ret["n_prompt_tokens"] = callback_data.get("prompt_tokens")
904904
ret["n_completion_tokens"] = callback_data.get("completion_tokens")
905-
self.cost_logger.log(
906-
dict(
907-
model=llm["llm"], modelalias=llm["alias"],
908-
cost=ret["cost"], input_tokens=ret["input_tokens"], output_tokens=ret["output_tokens"]))
905+
if self.cost_logger:
906+
self.cost_logger.log(
907+
dict(
908+
model=llm["llm"], modelalias=llm["alias"],
909+
cost=ret["cost"], input_tokens=ret["input_tokens"], output_tokens=ret["output_tokens"]))
909910
return ret
910911
except Exception as e:
911912
tb = traceback.extract_tb(e.__traceback__)
@@ -979,10 +980,11 @@ def chunk_generator(model_generator, retobj):
979980
ret["n_completion_tokens"] = usage.completion_tokens
980981
ret["n_prompt_tokens"] = usage.prompt_tokens
981982
ret["n_total_tokens"] = usage.total_tokens
982-
self.cost_logger.log(
983-
dict(
984-
model=llm["llm"], modelalias=llm["alias"],
985-
cost=ret["cost"], input_tokens=ret["n_prompt_tokens"], output_tokens=ret["n_completion_tokens"]))
983+
if self.cost_logger:
984+
self.cost_logger.log(
985+
dict(
986+
model=llm["llm"], modelalias=llm["alias"],
987+
cost=ret["cost"], input_tokens=ret["n_prompt_tokens"], output_tokens=ret["n_completion_tokens"]))
986988
# add the cost and tokens from the recursive call info, if available
987989
if recursive_call_info.get("cost") is not None:
988990
ret["cost"] += recursive_call_info["cost"]

llms_wrapper/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import importlib.metadata
2-
__version__ = "0.9.1.9"
2+
__version__ = "0.9.1.10"
33

0 commit comments

Comments
 (0)