Flask and CrewAI

I am trying to put my CrewAI behind a Flask server to connect it to a NextJS WebAPP.
However because getting the result from CrewAI takes 30s the NextJS disconnect before getting the results.
How do you set up Flask to handle the long timeline for the results?

I am no Flask expert, but most, if not all TCP based (HTTP) servers have a timeout setting. With most HTTP servers it defaults to 30 seconds. Try looking for where you can set that to the time you require

Hi guys. And @Dabnis - I was actually trying to DM you about almost this very problem. Iā€™ve scoured the internet, and I canā€™t seem to find any reasonable way to deploy my crew so that I can call it with requests :man_shrugging:t2: Do you have any resources to point me to?

Hi @Michael_Birkeland ,
Does this help?

As far as I know Flask is the only viable option for a Python based server.

Get back to me.

Regards.
Dab

Update:
Also take a look here that points to these settings. It seems that if you set timeout to 0, it disables timeouts :slight_smile:

To do it without Flask: I would set up a simple Nginx HTTP server, dockerise your Python/CrewAI and proxy the API requests from Nginx ā†’ dockerised .
You could just expose your HTTP port value on the docker container and allow the API requests from Nginx to route to the docker container directly.

Woah! That was quick @Dabnis :sweat_smile: I am about to expose my noobness.

I like to code. Iā€™m a decent hobby developer. However, Iā€™m woefully lacking in things that are more ā€œproductionā€ related. Like deploying stuff. Making sure dependencies are ok. Installing libraries in environmentsā€¦ So right now Iā€™m really struggling to take my crew and put it somewhere where I can go to https://somedomain.com/api/crew/run-something, pass it a request body and have it return something. (Setting the timeout wouldā€™ve been an issue though, and now I learned how to resolve that :pray:t2:)

It seems like Flask is the way to go, but it is not obvious to me what service I should use to deploy it :man_shrugging:t2:

Hi Michael_Birkeland,
My advice is this:
Larn how to set-up a Flask server with endpoints that you can call locally on your box. Search youtube.
Then search youtube for how to set up API endpoints on your local Flask server.
It will be great fun and you will learn 99% of what you will need to know to set the same up on a cheap DigitalOcean droplet, about $6/month.

**REM: Iā€™m a Python noob myself, more Golang/Rust/C++, etc.

Alright @Dabnis :muscle:t2: Challenge accepted. I spent some hours on this yesterday and went to bed feeling so useless. But The gauntlet has been thrown. Once I get it working Iā€™ll make a video for others like me :wink:

Ok. So, quick update @Dabnis :
I was able to get a skeleton Flask app up and running on Vercel (which I really like). https://fa-02.vercel.app/

Then I installed crewai using pip and added those to the requirements.txt

I have two questions or topics to discuss:

  1. I think it may fail because my repo is now more than 300 mb of sheer dependencies. And I believe this will fail with on Hobby plan.
  2. Surely, I cannot be the only person in the world to run large apps like this? How do people usually handle large amounts of dependencies? Do you reference them externally?

I did create the app with same idealogy

On flask route i called the crew ai function that makes it run

Hi Michael_Birkeland,
The issue is Python, not you or your app. I have often wrote on this discord: ā€œPython is holding AI hostageā€.
300Mb is not bad for a Python app, Iā€™ve seen many that are 1Gb+!. **REM a similar app in such as Go, Rust, etc will be 10-20 Mb.
I still maintain that getting what you want working on your box locallyy is the way to go for you as any online deployment is going to cost you, and cost you more because itā€™s Python.
FYI: I build my own AI applications in Go and Rust because of all of these Python issues.
Everybody on this discord should know and understand: Python as originally created was a ā€˜scriptingā€™ language, used primarily by data scientistā€™s. It was never meant to be a full blown software language in the same realm as c,C++, Go, Rust.
Many will see my views as those of an old guy who has been a software engineer for 50+ years, but I stand by all that I have wrote above. Time to get off my ā€˜soap-boxā€™.
So why has Python get to where it is? Humans are lazy by design, it started with the wheel and continues today. If you can just use a library/package with just a few clicks then people will. The downside is that you learn nothing and inherit all of the issues that Python gives people trying to work with AI today with Python.

Having said all of the above, I still believe that your best route is to get something working on your local box. You will learn key skills. After that, look at learning a software language, itā€™s not hard and it will open up oportunities for you that could change the hrest of your life.

If I knew more about Python Michael I would offer to help you. For now all I can give is the advice above.

Best of luck.
Dab

1 Like

:soap::package:!

Thanks @Dabnis
Iā€™m an older guy myself (although, perhaps a few years younger than you). Experience is undervalued :raising_hand_man:t2:

Iā€™m currently running the Flask app locally, but how would I make sure the endpoint is accessible to the world? Iā€™m going to investigate and let you know what I come up with :wink:

Perhaps Iā€™ll finally take the plunge and learn a real programming language

Thanks for taking the time Dab :pray:t2:

Hi Michael,
The easiest route to getting your app online is to learn how to containerise, make a docker image of it. Then you can deploy that container onto a cloud based server, like DigitalOcean as a docker container.
Hereā€™s your YouTube search

Let me know how you get on, Iā€™ll continue to help where I can.

Best of luck :slight_smile:
Dab

Once you get your app containerised, hereā€™s your YouTube search on how to deploy it to DigitalOcean (by far the cheapest option)

**REM: Todays is the first day of the rest of your life, imagine what you could achieve if you put your mind to it :slight_smile:

Dab

Hi Michael,
hereā€™s you YouTube search on how to expose Flask API endpoints

Regards.
Dab