AI Tools app
Our Django Boilerplate ships with a tools app, located at your_project/your_project.
This app is a good place to put your AI tool. It is already set up with a simple view and template, and it is ready to be extended with your AI tool.
(venv) interview_db $ cd interview_db/tools
(venv) tools $ tree -L 1
.
├── __init__.py
├── __pycache__
├── apis.py # This is where we handle the request from the front end and response of the API.
├── apps.py
├── gpt.py # This is where we are calling the OpenAI GPT Model and return a stream of response.
├── migrations
├── models.py
├── static
├── templates
├── urls.py
└── views.py
There is a tools.js file located at your_project/your_project/static/js. This file is where you can put your JavaScript code for your AI tool. It is already set up to be included in the base.html template.
(venv) tools $ cd static
(venv) static $ tree
.
└── js
└── tools.js
To try out the cover letter generator, you need to also set up your OPENAI_API_KEY.
- If you are running in local, update it in the .env file. You can get the API key from the OpenAI website.
- If you are running in production, add it with the following command:
heroku config:set OPENAI_API_KEY=your_api_key
Then click the cover letter tool link from the header of your website to try out the cover letter generator.
The app launch button requires a paid membership, this is how we manage user permissions and access to the app. If you are running in local, you can update the requirements by removing the and request.user.is_paid from the cover_letter.html file.
{% if request.user.is_authenticated and request.user.is_paid %}
We are streaming the response from the OpenAI GPT Model. The response is a stream of text, and you will see the typing animation while the response is being generated.
Conclusion
This tutorial has focused on a small sample application, specifically a cover letter generator tool using the OpenAI GPT Model within a Django web framework. While the application itself is modest in scope, it encompasses all the fundamental concepts and steps necessary to scale up to a much larger AI-driven project.
By walking through the setup of the OpenAI API key and integrating it into our Django application, we've laid the groundwork for expanding into more complex and feature-rich AI applications. We hope this guide serves as a solid foundation for your future projects, demonstrating that even from small beginnings, ambitious AI applications can be developed. If you have any questions or would like to share your feedback, please don't hesitate to reach out. Thank you for reading, and we're excited to see what you build next!