Update llm.py

This commit is contained in:
Zhaoyang Yu 2024-08-15 20:21:07 +08:00
parent 008c5f0f1f
commit c9989c069e

View file

@ -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