From the course: Advanced Python Projects: Build AI Applications

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Setup FastAPI app, CORS, S3 session, and obtain a chat response

Setup FastAPI app, CORS, S3 session, and obtain a chat response - Python Tutorial

From the course: Advanced Python Projects: Build AI Applications

Setup FastAPI app, CORS, S3 session, and obtain a chat response

- [Instructor] Here we are initializing a FastAPI application named app. Next in this block of code, we're adding the CORS middleware to the FastAPI application. This is allowing requests from any origin, credential, HTTP methods or headers. Here we are creating AWS S3 session using boto3 with the provided AWS access credentials. The AWS S3 variable holds a session configured with AWS access key, secret key, and region. Next, we're defining a FastAPI endpoint /chat using the HTTP post method. The create_chat_message function is an asynchronous function that handles the /chat endpoint. Next, what we're going to do is we are going to create a chat message and obtain a response based on the user input and the session ID. If it's a new session, we create a new session ID. If it's an existing session, then we add onto the conversation history using the session ID. Let's check out how they do that. So we're going to check…

Contents