AashitaK commited on
Commit
e0ac28f
·
verified ·
1 Parent(s): c402e13

Upload chatbot_logic.py

Browse files
Files changed (1) hide show
  1. utils/chatbot_logic.py +41 -0
utils/chatbot_logic.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from utils.response_manager import ResponseManager # Import the ResponseManager class
3
+
4
+ # Vector store ID for the retrieval of knowledge base documents
5
+ # Load the vector store ID from the environment variable
6
+ vector_store_id = os.getenv('VECTOR_STORE_ID')
7
+
8
+ # Check if the VECTOR_STORE_ID environment variable is set
9
+ if not vector_store_id:
10
+ raise ValueError("VECTOR_STORE_ID environment variable is not set.")
11
+
12
+ # Initialize the ResponseManager with the vector store ID
13
+ response_manager = ResponseManager(vector_store_id)
14
+
15
+ # Set parameters for the response generation
16
+ model = "gpt-4o-mini" # Set the model to be used for response generation
17
+ temperature = 0 # Set the temperature for response generation
18
+ max_output_tokens = 800 # Set the maximum number of output tokens
19
+ max_num_results = 15 # Set the maximum number of knowledge base documents to return for retrieval
20
+
21
+
22
+ def conversation(query: str, history):
23
+ """
24
+ Function to handle the chatbot interaction and maintain conversation history.
25
+ :param query: The user query to respond to.
26
+ :param history: The conversation history (list of [input, output] pairs).
27
+ :return: Updated conversation history.
28
+ """
29
+ try:
30
+ if query.strip():
31
+ response = response_manager.create_response(query, model, temperature, max_output_tokens, max_num_results)
32
+ if not response:
33
+ response = "Sorry, I couldn't generate a response at this time. Please try again later."
34
+ # Append the conversation
35
+ history.append((query, response))
36
+ else:
37
+ history.append((query, "Please enter a valid query."))
38
+ return history
39
+ except Exception as e:
40
+ history.append((query, str(e)))
41
+ return history