From the course: Advanced Python Projects: Build AI Applications
Generate chat responses using GPT-3.5 and Langchain - Python Tutorial
From the course: Advanced Python Projects: Build AI Applications
Generate chat responses using GPT-3.5 and Langchain
- [Instructor] Here we're defining a pedantic model named ChatMessageSent using the base model class. Next, we create a function named get response that takes several parameters. This is the name of the file to load data from. This is the session ID for tracking conversation history. This is the user query or question to be used in the conversation. Here we're using the model GPT-3.5 Turbo 16K, and then we're setting the temperature of the model to zero. Temperature parameter is to control the response randomness. The default is set to Zero, which produces a very stable or less random response. Then we print the file name and update it by extracting the last part after the slash using this line over here. So overall, this function generates a response using a conversational model like GPT-3.5 Turbo. It takes a final name to load data, a session ID to track the conversation, a query or question, and optional parameters for model selection and temperature control. The open AI embeddings class is used to convert text to numerical representations, and the S3.download function is used to fetch a file from the S3 bucket. Now we're going to set up document processing based on its file type, either a.docs or a PDF, and then we have the program used to process data to create a conversational retrieval chain with an open AI model. Let's see how to do that. First, we check the file type of the document, whether it's the .docs or PDF file, and then we load the document using the appropriate loader. Next, we load the data and we split the loaded data into chunks that fit the GPT token limit. After that, we store the data in a vector database to an enabled search functionality. F-A-I-S-S is that vector database. After that, we initialize an open AI model with specified parameters. Then we create a conversational retrieval chain with the OpenAI model and the vector database. Once we do that, we use a callback to determine the number of tokens used during the query. After that, we print several metrics related to the tokens. After we do that, we collect garbage from the memory to free up some space. Lastly, we write return answer so that it returns answers to the query along with the total tokens used.
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
-
-
-