From c6e12a7862f6374ac5392bde91e88843ba6a2029 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 13 Jul 2023 12:01:37 -0400 Subject: [PATCH] envs + string pass in build_llm Former-commit-id: 8adcad110fab29f7725d5a3ff8cf293fedfe9763 --- swarms/agents/utils/AgentBuilder.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/swarms/agents/utils/AgentBuilder.py b/swarms/agents/utils/AgentBuilder.py index ada152a9..cfbbf33f 100644 --- a/swarms/agents/utils/AgentBuilder.py +++ b/swarms/agents/utils/AgentBuilder.py @@ -23,7 +23,12 @@ class AgentBuilder: self.toolsets = toolsets def build_llm(self, callback_manager: BaseCallbackManager = None, openai_api_key: str = None): - self.llm = ChatOpenAI(openai_api_key=openai_api_key, temperature=0, callback_manager=callback_manager, verbose=True) + if openai_api_key is None: + openai_api_key = os.getenv('OPENAI_API_KEY') + if openai_api_key is None: + raise ValueError("OpenAI API key is missing. It should either be set as an environment variable or passed as a parameter.") + + self.llm = ChatOpenAI(openai_api_key=openai_api_key, temperature=0.5, callback_manager=callback_manager, verbose=True) def build_parser(self): self.parser = EvalOutputParser()