From 33b12ebc45ad4ee9abfcbdde56d6786d1504b0d5 Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Tue, 12 Nov 2024 15:54:11 -0800 Subject: [PATCH] fix: Pass the OpenAI API Key to Crew() --- .../components/crewai/hierarchical_crew.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/components/crewai/hierarchical_crew.py b/src/backend/base/langflow/components/crewai/hierarchical_crew.py index c56144d534e..8295554013e 100644 --- a/src/backend/base/langflow/components/crewai/hierarchical_crew.py +++ b/src/backend/base/langflow/components/crewai/hierarchical_crew.py @@ -1,7 +1,9 @@ +import os + from crewai import Crew, Process from langflow.base.agents.crewai.crew import BaseCrewComponent -from langflow.io import HandleInput +from langflow.io import HandleInput, SecretStrInput class HierarchicalCrewComponent(BaseCrewComponent): @@ -18,10 +20,21 @@ class HierarchicalCrewComponent(BaseCrewComponent): HandleInput(name="tasks", display_name="Tasks", input_types=["HierarchicalTask"], is_list=True), HandleInput(name="manager_llm", display_name="Manager LLM", input_types=["LanguageModel"], required=False), HandleInput(name="manager_agent", display_name="Manager Agent", input_types=["Agent"], required=False), + SecretStrInput( + name="openai_api_key", + display_name="OpenAI API Key", + info="The OpenAI API Key to use for the OpenAI model.", + value="OPENAI_API_KEY", + ), ] def build_crew(self) -> Crew: tasks, agents = self.get_tasks_and_agents() + + # Set the OpenAI API Key + if self.openai_api_key: + os.environ["OPENAI_API_KEY"] = self.openai_api_key + return Crew( agents=agents, tasks=tasks,