Skip to content

Commit

Permalink
fix: Pass openai for sequential crew
Browse files Browse the repository at this point in the history
  • Loading branch information
erichare committed Nov 15, 2024
1 parent 2881346 commit 394d44b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/backend/base/langflow/components/crewai/sequential_crew.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

from crewai import Agent, Crew, Process, Task

from langflow.base.agents.crewai.crew import BaseCrewComponent
from langflow.io import HandleInput
from langflow.io import HandleInput, SecretStrInput
from langflow.schema.message import Message


Expand All @@ -14,13 +16,24 @@ class SequentialCrewComponent(BaseCrewComponent):
inputs = [
*BaseCrewComponent._base_inputs,
HandleInput(name="tasks", display_name="Tasks", input_types=["SequentialTask"], is_list=True),
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 get_tasks_and_agents(self) -> tuple[list[Task], list[Agent]]:
return self.tasks, [task.agent for task in self.tasks]

def build_crew(self) -> Message:
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,
Expand Down

0 comments on commit 394d44b

Please sign in to comment.