This project implements a basic chatbot using OpenAI's Language Model (LLM). The chatbot dynamically retrieves context from external sources, such as APIs and documents, to answer user queries effectively.
- Python 3.x
openai
libraryrequests
library
- Install dependencies
- Replace
api_key
in the code with your actual OpenAI API key.
Initialize the OpenAI client with your API key.
Define functions to retrieve external data, such as get_hotel_details
, which retrieves hotel details based on rating.
Define available functions and their descriptions, specifying parameters required for each function.
Define a function to get a response from the GPT-3.5 model, incorporating available functions and messages.
Define a function to execute function calls extracted from the GPT-3.5 response, calling the appropriate function with provided arguments.
Execute the chatbot interaction loop:
- Step 6: Generate a response from the GPT-3.5 model based on the user query.
- Step 7: Execute the function call extracted from the GPT-3.5 response.
- Step 8: Append messages and function responses to maintain conversation history.
- Step 9: Obtain the final response incorporating the function execution.