Create A REST API using Python Flask and ChatGPT

preview_player
Показать описание
In this video, we'll be learning how to create a REST API using Python, Flask, and ChatGPT.

If you're interested in developing a web application or MVP using Python, Flask, and ChatGPT, this video is for you! We'll walk you through the steps required to create a REST API using Python and ChatGPT. This REST API will interact with OpenAI models and return the AI-generated content to the user. We are also going to explore different AI models provided by OpenAI. So if you're looking to learn how to create a REST API using Python Flask and ChatGPT, this video is for you!

0:00 - Introduction
1:58 - Setup OpenAI account
3:10 - Create code (initial version)
22:12 - Create code (extended API)
28:46 - Conclusion
Рекомендации по теме
Комментарии
Автор

Sorry, but it doesn't work for me. I admit that this would be my first Flask api, and I followed everything to the letter (up to 20:00, which is the main part). Two issues (both in chat_gpt_controller.py):
One: If I just keep this code: @chat_gpt_route.route('/message', methods=['POST']) (only a POST request), the server(postman or otherwise throws the error: Method Not Allowed, The method is not allowed for the requested URL (this was true even until this point, so I changed this code in @chat_gpt_route.route('/message', methods=['GET', 'POST'])
Second: Now, with @chat_gpt_route.route('/message', methods=['GET', 'POST']), the main issue seems to be in chat_gpt_controller.py at
body = request.json . This throws the error: Bad Request: Did not attempt to load JSON data because the request Content-Type was not 'application/json'.
So it has to do with the type of data in body (which needs to be json) but the browser does not recognize it as such? It may be an easy fix, but this being my first experience with flask, I don't know where to look for a fix.

sapariucioan