AashitaK commited on
Commit
4fdd41b
·
verified ·
1 Parent(s): 25e1fc0

Delete utils/chatbot_logic.py

Browse files
Files changed (1) hide show
  1. utils/chatbot_logic.py +0 -61
utils/chatbot_logic.py DELETED
@@ -1,61 +0,0 @@
1
- import os
2
- import logging
3
- from utils.response_manager import ResponseManager # Import the ResponseManager class
4
-
5
- # Vector store ID for the retrieval of knowledge base documents
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
- logging.error("VECTOR_STORE_ID environment variable is not set.")
11
- raise ValueError("VECTOR_STORE_ID environment variable is not set.")
12
-
13
- # Initialize the ResponseManager with the vector store ID
14
- response_manager = ResponseManager(vector_store_id)
15
-
16
- # Constants for response generation
17
- DEFAULT_MODEL = "gpt-4o-mini" # Set the model to be used for response generation
18
- DEFAULT_TEMPERATURE = 0 # Set the temperature for response generation
19
- DEFAULT_MAX_OUTPUT_TOKENS = 800 # Set the maximum number of output tokens
20
- DEFAULT_MAX_NUM_RESULTS = 15 # Set the maximum number of knowledge base documents to return for retrieval
21
-
22
- def conversation(query: str, history: list) -> list:
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
- logging.info("Received query: %s", query)
30
- try:
31
- # Validate the query
32
- if not query.strip():
33
- logging.warning("Empty or invalid query received.")
34
- history.append((query, "Please enter a valid query."))
35
- return history
36
-
37
- # Generate a response using the ResponseManager
38
- logging.info("Generating response for the query...")
39
- response = response_manager.create_response(
40
- query=query,
41
- model=DEFAULT_MODEL,
42
- temperature=DEFAULT_TEMPERATURE,
43
- max_output_tokens=DEFAULT_MAX_OUTPUT_TOKENS,
44
- max_num_results=DEFAULT_MAX_NUM_RESULTS
45
- )
46
-
47
- # Handle cases where no response is generated
48
- if not response:
49
- logging.warning("No response generated for the query.")
50
- response = "Sorry, I couldn't generate a response at this time. Please try again later."
51
-
52
- # Append the query and response to the conversation history
53
- history.append((query, response))
54
- logging.info("Response generated successfully.")
55
- return history
56
-
57
- except Exception as e:
58
- # Log the error and append it to the conversation history
59
- logging.error("An error occurred while generating a response: %s", str(e))
60
- history.append((query, f"An error occurred: {str(e)}"))
61
- return history