Spaces:
Build error
Build error
Update utils/chatbot_interface_test.py
Browse files
utils/chatbot_interface_test.py
CHANGED
|
@@ -17,18 +17,23 @@ class ChatbotInterface:
|
|
| 17 |
meta_prompt_file: Optional[str] = None):
|
| 18 |
"""
|
| 19 |
Initialize the ChatbotInterface with configuration and custom parameters for ResponseManager.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"""
|
| 21 |
self.config = self.load_config(config_path)
|
| 22 |
-
|
| 23 |
self.title = self.config["chatbot_title"]
|
| 24 |
self.description = self.config["chatbot_description"]
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
self.input_placeholder = "How can the CIS agent help you?"
|
| 28 |
-
|
| 29 |
self.output_label = self.config["chatbot_output_label"]
|
| 30 |
-
self.submit_button = self.config["chatbot_submit_button"]
|
| 31 |
|
|
|
|
| 32 |
try:
|
| 33 |
self.response_manager = ResponseManager(
|
| 34 |
model=model,
|
|
@@ -47,6 +52,7 @@ class ChatbotInterface:
|
|
| 47 |
f" - Max Output Tokens: {max_output_tokens}\n"
|
| 48 |
f" - Max Number of Results: {max_num_results}\n"
|
| 49 |
)
|
|
|
|
| 50 |
except Exception as e:
|
| 51 |
logging.error(f"Failed to initialize ResponseManager: {e}")
|
| 52 |
raise
|
|
@@ -95,6 +101,7 @@ class ChatbotInterface:
|
|
| 95 |
|
| 96 |
# Chatbot output area.
|
| 97 |
chatbot_output = gr.Chatbot(label=self.output_label, type="messages")
|
|
|
|
| 98 |
# Use a gr.Row container as the input box with an integrated submit button.
|
| 99 |
with gr.Row(elem_id="input-container", equal_height=True):
|
| 100 |
user_input = gr.Textbox(
|
|
@@ -128,7 +135,6 @@ class ChatbotInterface:
|
|
| 128 |
updated_history = self.response_manager.generate_response(user_message, chat_history)
|
| 129 |
return updated_history, ""
|
| 130 |
|
| 131 |
-
|
| 132 |
# Bind the reset button click to the reset function
|
| 133 |
reset.click(
|
| 134 |
fn=reset_output,
|
|
@@ -136,7 +142,6 @@ class ChatbotInterface:
|
|
| 136 |
outputs=[chatbot_output, user_input]
|
| 137 |
)
|
| 138 |
|
| 139 |
-
|
| 140 |
# Bind the Enter key (textbox submit) to the same processing function
|
| 141 |
user_input.submit(
|
| 142 |
fn=process_input,
|
|
|
|
| 17 |
meta_prompt_file: Optional[str] = None):
|
| 18 |
"""
|
| 19 |
Initialize the ChatbotInterface with configuration and custom parameters for ResponseManager.
|
| 20 |
+
:param config_path: Path to the configuration JSON file.
|
| 21 |
+
:param model: The OpenAI model to use (default: 'gpt-4o-mini').
|
| 22 |
+
:param temperature: The temperature for response generation (default: 0).
|
| 23 |
+
:param max_output_tokens: The maximum number of output tokens (default: 800).
|
| 24 |
+
:param max_num_results: The maximum number of search results to return (default: 15).
|
| 25 |
+
:param vector_store_id: The ID of the vector store to use for file search.
|
| 26 |
+
:param api_key: The OpenAI API key for authentication.
|
| 27 |
+
:param meta_prompt_file: Path to the meta prompt file .
|
| 28 |
"""
|
| 29 |
self.config = self.load_config(config_path)
|
|
|
|
| 30 |
self.title = self.config["chatbot_title"]
|
| 31 |
self.description = self.config["chatbot_description"]
|
| 32 |
+
self.input_label = self.config["chatbot_input_label"]
|
| 33 |
+
self.input_placeholder = self.config["chatbot_input_placeholder"]
|
|
|
|
|
|
|
| 34 |
self.output_label = self.config["chatbot_output_label"]
|
|
|
|
| 35 |
|
| 36 |
+
# Initialize ResponseManager with custom parameters
|
| 37 |
try:
|
| 38 |
self.response_manager = ResponseManager(
|
| 39 |
model=model,
|
|
|
|
| 52 |
f" - Max Output Tokens: {max_output_tokens}\n"
|
| 53 |
f" - Max Number of Results: {max_num_results}\n"
|
| 54 |
)
|
| 55 |
+
|
| 56 |
except Exception as e:
|
| 57 |
logging.error(f"Failed to initialize ResponseManager: {e}")
|
| 58 |
raise
|
|
|
|
| 101 |
|
| 102 |
# Chatbot output area.
|
| 103 |
chatbot_output = gr.Chatbot(label=self.output_label, type="messages")
|
| 104 |
+
|
| 105 |
# Use a gr.Row container as the input box with an integrated submit button.
|
| 106 |
with gr.Row(elem_id="input-container", equal_height=True):
|
| 107 |
user_input = gr.Textbox(
|
|
|
|
| 135 |
updated_history = self.response_manager.generate_response(user_message, chat_history)
|
| 136 |
return updated_history, ""
|
| 137 |
|
|
|
|
| 138 |
# Bind the reset button click to the reset function
|
| 139 |
reset.click(
|
| 140 |
fn=reset_output,
|
|
|
|
| 142 |
outputs=[chatbot_output, user_input]
|
| 143 |
)
|
| 144 |
|
|
|
|
| 145 |
# Bind the Enter key (textbox submit) to the same processing function
|
| 146 |
user_input.submit(
|
| 147 |
fn=process_input,
|