From the course: Advanced Python Projects: Build AI Applications
Create new sessions and add chat history to existing sessions - Python Tutorial
From the course: Advanced Python Projects: Build AI Applications
Create new sessions and add chat history to existing sessions
- [Instructor] In this lesson, we're going to explore how to create a new session ID for a chat or how to add conversation history if there's an existing session. First, we define a function named get_session that generates a new session ID and return it as a string. Next, we use the UUID module to create a universal unique identifier, ensuring the uniqueness in each of these sessions. Next, we retrieve the MongoDB document with the specific session ID using conversationcol.find_one. In this line, the function checks if the document exists. If it does, it appends the new conversation values to the existing conversation list. If not, it inserts a new document with the provided session ID and new values into the MongoDB collection conversationcol. This kind of organization is crucial for applications that involve maintaining user interactions or dialogues over multiple sessions. So this code allows for seamless storage and retrieval of conversation data tied to specific session IDs.
Contents
-
-
-
-
-
Setting up MongoDB4m 24s
-
Generate chat responses using GPT-3.5 and Langchain2m 46s
-
Load conversation history for a given session ID1m 16s
-
Create new sessions and add chat history to existing sessions1m 11s
-
Setup FastAPI app, CORS, S3 session, and obtain a chat response3m 43s
-
Upload files to Amazon S3 storage bucket2m 39s
-
Deploy and run the chatbot4m 2s
-
Challenge: Complete the backend code for file upload2m 13s
-
Solution: Complete the backend code for file upload9m 52s
-
-
-