🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
feat: merge fixbug/rfc135_merge_geekan_cli_etc_1445
莘权 马8e3922aeaa9a
diff --cc metagpt/llm.pyindex e4ae81735,7c0ad7975..ad4bf6cb2--- a/metagpt/llm.py+++ b/metagpt/llm.py@@@ -21,33 -18,20 +21,33 @@@ from metagpt.provider.zhipuai_api impor_ = HumanProvider() # Avoid pre-commit error-def LLM() -> BaseGPTAPI:- """initialize different LLM instance according to the key field existence"""- # TODO a little trick, can use registry to initialize LLM instance further- if CONFIG.openai_api_key:- llm = OpenAIGPTAPI()- elif CONFIG.spark_api_key:- llm = SparkAPI()- elif CONFIG.zhipuai_api_key:- llm = ZhiPuAIGPTAPI()- elif CONFIG.open_llm_api_base:- llm = OpenLLMGPTAPI()- elif CONFIG.fireworks_api_key:- llm = FireWorksGPTAPI()- else:+# Used in agents+class LLMFactory:+ @staticmethod+ def new_llm() -> "BaseGPTAPI":+ # Determine which type of LLM to use based on the validity of the key.+ if CONFIG.spark_api_key:+ return SparkAPI()+ elif CONFIG.zhipuai_api_key:+ return ZhiPuAIGPTAPI()+ elif CONFIG.open_llm_api_base:+ return OpenLLMGPTAPI()+ elif CONFIG.fireworks_api_key:+ return FireWorksGPTAPI()++ # MetaGPT uses the same parameters as OpenAI.+ constructors = {+ LLMType.OPENAI.value: OpenAIGPTAPI,+ LLMType.METAGPT.value: MetaGPTLLMAPI,+ }+ constructor = constructors.get(CONFIG.LLM_TYPE)+ if constructor:+ return constructor()+- raise ValueError(f"Unsupported LLM TYPE: {CONFIG.LLM_TYPE}")+ raise RuntimeError("You should config a LLM configuration first")- return llm++# Used in metagpt+def LLM() -> "BaseGPTAPI":+ """initialize different LLM instance according to the key field existence"""+ return LLMFactory.new_llm()