Create a FastAPI + Langchain Project in 5 Easy Steps: A Step-by-Step Guide
At the end of these steps you will obtain a FastAPI + Langchain project with which you can add the functionalities you want, It will include an agent that has various tools available, all this without writing a line of code, since it will be generated by a FastAPI template script! This project uses create-fastapi-project to start a sample project template.
Requirements:
- Docker
Template Folder Structure:
.
├───backend
│ └───app
│ ├───app
│ │ ├───api
│ │ │ └───v1
│ │ │ └───endpoints
│ │ ├───core
│ │ ├───schemas
│ │ ├───templates
│ │ │ └───general_pages
│ │ └───utils
│ │ ├───adaptive_cards
│ │ └───exceptions
│ └───test
├───caddy
├───frontend
│ └───app
└───static
Containers Architecture:
Step 1: Download the Python script to execute the template generator
pip install create-fastapi-project
Step 2: Execute the script
create-fastapi-project
Step 3: Follow the CLI instructions
In this step just put your project name and choose langchain_basic template
Step 4: Set up enviroment variables
To run this project you need to set almost the OPENAI_API_KEY because the agent is powered by OPENAI.
.env
OPENAI_API_KEY=
Optionals ENVs:
If you want to use the image search and keyword search video tools, you will need to use the following ENVs.
UNSPLASH_API_KEY for image search and SERP_API_KEY for video search
.env
OPENAI_API_KEY=
UNSPLASH_API_KEY=
SERP_API_KEY=
Step 5: Run the project
make run-dev-build
Congratulations, you already have your FastAPI + Langchain project running and ready for you to continue adding new features.
You can test the agents with the different tools in http://fastapi.localhost/chat
You can also try it on the Streamlit frontend server at http://frontend.localhost
Conclusion
In conclusion, whether you’re embarking on a new FastAPI + Langchain project or simply a FastAPI project, the template generator stands out as an exceptional starting point. This tool not only facilitates the creation of a fully functional project, but it also provides the added advantage of a meticulously organized folder structure and adherence to industry best coding practices.
The template generator streamlines the initial setup process, allowing you to focus more on the unique aspects of your project rather than spending excessive time on foundational elements. By utilizing this tool, developers can expedite their development workflow while ensuring a consistent and maintainable codebase.
Incorporating this approach early in your project can lead to improved efficiency, enhanced collaboration, and ultimately, a more successful outcome. As the technology landscape continues to evolve, having a strong foundation becomes increasingly crucial, and the template generator empowers you to establish that foundation with confidence.
In summary, the template generator not only jumpstarts your project but also nurtures its growth through its thoughtful structure and adherence to coding excellence. Whether you’re a seasoned developer or just starting your coding journey, this tool is a valuable asset that paves the way for a successful and sustainable project development experience.
You can also use this template here:
https://github.com/allient/create-fastapi-project
Thanks for your time reading this post 😃 !!
Feel free to give me your feedback and comments and if you want me to cover another topic please let me know in the comments. You can also subscribe 👍 to our newsletter to receive post like this😄.
Do you need some help with a project?
We are ready to listen to you. If you need some help, you can contact our team at info@allient.io or schedule a meeting with us here.