Hi! Seems like there are no code examples for Flows - CrewAI, even though they are being reffered to through the text. For example, it says
In the above example, we have created a simple Flow that generates a random city using OpenAI and then generates a fun fact about that city. The Flow consists of two tasks: generate_city and generate_fun_fact.
@horachka This is a bug in the docs. I remembered seeing this example in the docs, so I tracked it down by searching through GitHub commits.
Here you go:
from crewai.flow.flow import Flow, listen, start
from dotenv import load_dotenv
from litellm import completion
class ExampleFlow(Flow):
model = "gpt-4o-mini"
@start()
def generate_city(self):
print("Starting flow")
response = completion(
model=self.model,
messages=[
{
"role": "user",
"content": "Return the name of a random city in the world.",
},
],
)
random_city = response["choices"][0]["message"]["content"]
print(f"Random City: {random_city}")
return random_city
@listen(generate_city)
def generate_fun_fact(self, random_city):
response = completion(
model=self.model,
messages=[
{
"role": "user",
"content": f"Tell me a fun fact about {random_city}",
},
],
)
fun_fact = response["choices"][0]["message"]["content"]
return fun_fact
flow = ExampleFlow()
result = flow.kickoff()
print(f"Generated fun fact: {result}")
@matt@tonykipkemboi Either the code snippet should be added to the docs, or the text referencing this example should be removed from the docs.