import os from utils.response_manager import ResponseManager # Import the ResponseManager class # Vector store ID for the retrieval of knowledge base documents # Load the vector store ID from the environment variable vector_store_id = os.getenv('VECTOR_STORE_ID') # Check if the VECTOR_STORE_ID environment variable is set if not vector_store_id: raise ValueError("VECTOR_STORE_ID environment variable is not set.") # Initialize the ResponseManager with the vector store ID response_manager = ResponseManager(vector_store_id) # Set parameters for the response generation model = "gpt-4o-mini" # Set the model to be used for response generation temperature = 0 # Set the temperature for response generation max_output_tokens = 800 # Set the maximum number of output tokens max_num_results = 15 # Set the maximum number of knowledge base documents to return for retrieval def conversation(query: str, history): """ Function to handle the chatbot interaction and maintain conversation history. :param query: The user query to respond to. :param history: The conversation history (list of [input, output] pairs). :return: Updated conversation history. """ try: if query.strip(): response = response_manager.create_response(query, model, temperature, max_output_tokens, max_num_results) if not response: response = "Sorry, I couldn't generate a response at this time. Please try again later." # Append the conversation history.append((query, response)) else: history.append((query, "Please enter a valid query.")) return history except Exception as e: history.append((query, str(e))) return history