AashitaK commited on
Commit
b18d283
·
verified ·
1 Parent(s): c2fbd9e

Update utils/chatbot_interface.py

Browse files
Files changed (1) hide show
  1. utils/chatbot_interface.py +47 -7
utils/chatbot_interface.py CHANGED
@@ -1,14 +1,30 @@
1
  import os
2
  import json
3
  import logging
 
4
  import gradio as gr
5
  from utils.response_manager import ResponseManager
6
 
7
  class ChatbotInterface:
8
- def __init__(self, config_path: str = 'config/gradio_config.json'):
 
 
 
 
 
 
 
 
9
  """
10
- Initialize the ChatbotInterface with configuration.
11
  :param config_path: Path to the configuration JSON file.
 
 
 
 
 
 
 
12
  """
13
  self.config = self.load_config(config_path)
14
  self.title = self.config["chatbot_title"]
@@ -18,10 +34,34 @@ class ChatbotInterface:
18
  self.output_label = self.config["chatbot_output_label"]
19
  self.reset_button = self.config["chatbot_reset_button"]
20
  self.submit_button = self.config["chatbot_submit_button"]
21
- self.response_manager = ResponseManager()
22
- self.conversation = self.response_manager.generate_response # Shortcut to the conversation method
23
- logging.info("ChatbotInterface initialized with configuration.")
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  @staticmethod
26
  def load_config(config_path: str) -> dict:
27
  """
@@ -84,8 +124,8 @@ class ChatbotInterface:
84
  submit = gr.Button(self.submit_button, variant="primary")
85
 
86
  # Button actions
87
- submit.click(fn=self.conversation, inputs=[user_input, chatbot_output], outputs=chatbot_output)
88
- user_input.submit(fn=self.conversation, inputs=[user_input, chatbot_output], outputs=chatbot_output)
89
  reset.click(fn=self.reset_output, inputs=None, outputs=chatbot_output)
90
 
91
  logging.info("Gradio interface created successfully.")
 
1
  import os
2
  import json
3
  import logging
4
+ from typing import Optional
5
  import gradio as gr
6
  from utils.response_manager import ResponseManager
7
 
8
  class ChatbotInterface:
9
+ def __init__(self,
10
+ config_path: str = 'config/gradio_config.json',
11
+ model: str = "gpt-4o-mini",
12
+ temperature: float = 0,
13
+ max_output_tokens: int = 800,
14
+ max_num_results: int = 15,
15
+ vector_store_id: Optional[str] = None,
16
+ api_key: Optional[str] = None,
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"]
 
34
  self.output_label = self.config["chatbot_output_label"]
35
  self.reset_button = self.config["chatbot_reset_button"]
36
  self.submit_button = self.config["chatbot_submit_button"]
 
 
 
37
 
38
+ # Initialize ResponseManager with custom parameters
39
+ try:
40
+ self.response_manager = ResponseManager(
41
+ model=model,
42
+ temperature=temperature,
43
+ max_output_tokens=max_output_tokens,
44
+ max_num_results=max_num_results,
45
+ vector_store_id=vector_store_id,
46
+ api_key=api_key,
47
+ meta_prompt_file=meta_prompt_file
48
+ )
49
+ self.generate_response = self.response_manager.generate_response
50
+ logging.info(
51
+ "ChatbotInterface initialized with the following parameters:\n"
52
+ f" - Model: {model}\n"
53
+ f" - Temperature: {temperature}\n"
54
+ f" - Max Output Tokens: {max_output_tokens}\n"
55
+ f" - Max Number of Results: {max_num_results}\n"
56
+ f" - Vector Store ID: {vector_store_id}\n"
57
+ f" - API Key: {'Provided' if api_key else 'Not Provided'}\n"
58
+ f" - Meta Prompt File: {meta_prompt_file or 'Default'}"
59
+ )
60
+ except Exception as e:
61
+ logging.error(f"Failed to initialize ResponseManager: {e}")
62
+ raise
63
+
64
+
65
  @staticmethod
66
  def load_config(config_path: str) -> dict:
67
  """
 
124
  submit = gr.Button(self.submit_button, variant="primary")
125
 
126
  # Button actions
127
+ submit.click(fn=self.generate_response, inputs=[user_input, chatbot_output], outputs=chatbot_output)
128
+ user_input.submit(fn=self.generate_response, inputs=[user_input, chatbot_output], outputs=chatbot_output)
129
  reset.click(fn=self.reset_output, inputs=None, outputs=chatbot_output)
130
 
131
  logging.info("Gradio interface created successfully.")