From c9989c069e980fddee278ec2b1829869eb96ca88 Mon Sep 17 00:00:00 2001 From: Zhaoyang Yu Date: Thu, 15 Aug 2024 20:21:07 +0800 Subject: [PATCH] Update llm.py --- metagpt/llm.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/metagpt/llm.py b/metagpt/llm.py index 465e419a1..88fe8bd44 100644 --- a/metagpt/llm.py +++ b/metagpt/llm.py @@ -10,11 +10,18 @@ from typing import Optional from metagpt.configs.llm_config import LLMConfig from metagpt.context import Context from metagpt.provider.base_llm import BaseLLM +from metagpt.utils.cost_manager import CostManager +global cost_manager + +if not globals().get("cost_manager"): + cost_manager = CostManager() def LLM(llm_config: Optional[LLMConfig] = None, context: Context = None) -> BaseLLM: """get the default llm provider if name is None""" ctx = context or Context() if llm_config is not None: return ctx.llm_with_cost_manager_from_llm_config(llm_config) - return ctx.llm() + llm = ctx.llm() + llm.cost_manager = cost_manager + return llm