amagastya's picture
update llm to 4.1-nano
a9075c9 verified
import os
from crewai import LLM, Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from dotenv import load_dotenv
from models import *
load_dotenv()
@CrewBase
class SizzleReelCrew:
"""Sizzle Reel Script Generation Crew"""
def __init__(self, inputs, *args, **kwargs):
super().__init__(*args, **kwargs)
# Get OpenAI API key from environment
openai_api_key = os.getenv('OPENAI_API_KEY')
if not openai_api_key:
raise ValueError("OpenAI API Key is not set. Please set the OPENAI_API_KEY environment variable.")
# Configure LLM with explicit provider
self.llm = LLM(
model="openai/gpt-4.1-nano",
temperature=0.7,
api_key=openai_api_key
)
self.inputs = inputs
# self.llm = LLM(
# model="gemini/gemini-2.0-flash-lite",
# temperature=0.7,
# api_key=os.getenv('GEMINI_API_KEY')
# )
@agent
def hero_research_specialist(self) -> Agent:
return Agent(
config=self.agents_config['hero_research_specialist'],
verbose=True,
llm=self.llm # Use the configured LLM
)
@agent
def content_strategist(self) -> Agent:
return Agent(
config=self.agents_config['content_strategist'],
verbose=True,
llm=self.llm # Use the configured LLM
)
@agent
def narrative_scriptwriter(self) -> Agent:
return Agent(
config=self.agents_config['narrative_scriptwriter'],
verbose=True,
llm=self.llm # Use the configured LLM
)
@task
def hero_research_task(self) -> Task:
return Task(
description=f"""Identify the hero user and their primary use case. Understand why they would use the app and what problem it solves for them.
Identify the hero-user, hero-usecase, and hero user journey from app name {self.inputs['app_name']}.
App Description: {self.inputs['customer_idea']}""",
expected_output="""Outline the steps the hero user takes in their journey within the app, from start to finish.""",
agent=self.hero_research_specialist(),
output_pydantic=HeroResearchOutput
)
@task
def content_plan_task(self) -> Task:
return Task(
description=f"""Generate a detailed content plan for the sizzle reel for App {self.inputs['app_name']}""",
expected_output="""A detailed content plan for the sizzle reel""",
agent=self.content_strategist(),
context=[self.hero_research_task()]
)
@task
def script_generation_task(self) -> Task:
return Task(
description=f"""Develop the final script for the sizzle reel for app: '{self.inputs['app_name']}', including engaging narrations and screen actions for each step in the hero's journey.""",
expected_output="""A detailed script with narrations and screen actions.""",
agent=self.narrative_scriptwriter(),
output_pydantic=ScriptOutput,
context=[self.hero_research_task(), self.content_plan_task()]
)
@crew
def crew(self) -> Crew:
return Crew(
agents=self.agents,
tasks=self.tasks,
process=Process.sequential,
verbose=True,
llm=self.llm # Use the configured LLM for the entire crew
)