Spaces:
Sleeping
Sleeping
Update utils/chatbot_interface.py
Browse files- utils/chatbot_interface.py +11 -32
utils/chatbot_interface.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
import json
|
| 3 |
import logging
|
| 4 |
from typing import Optional
|
| 5 |
-
from uuid import uuid4
|
| 6 |
import gradio as gr
|
| 7 |
from utils.response_manager import ResponseManager
|
| 8 |
|
|
@@ -47,17 +46,16 @@ class ChatbotInterface:
|
|
| 47 |
api_key=api_key,
|
| 48 |
meta_prompt_file=meta_prompt_file
|
| 49 |
)
|
| 50 |
-
|
| 51 |
-
# self.session_id = self.response_manager.start_session()
|
| 52 |
-
# logging.info(f"New session started with session id {self.session_id}.")
|
| 53 |
-
# self.generate_response = lambda query, history: self.response_manager.generate_response(query, self.session_id)
|
| 54 |
-
|
| 55 |
logging.info(
|
| 56 |
"ChatbotInterface initialized with the following parameters:\n"
|
| 57 |
f" - Model: {model}\n"
|
| 58 |
f" - Temperature: {temperature}\n"
|
| 59 |
f" - Max Output Tokens: {max_output_tokens}\n"
|
| 60 |
f" - Max Number of Results: {max_num_results}\n"
|
|
|
|
|
|
|
|
|
|
| 61 |
)
|
| 62 |
except Exception as e:
|
| 63 |
logging.error(f"Failed to initialize ResponseManager: {e}")
|
|
@@ -92,13 +90,12 @@ class ChatbotInterface:
|
|
| 92 |
logging.info("Configuration loaded successfully.")
|
| 93 |
return config
|
| 94 |
|
| 95 |
-
def reset_output(self) ->
|
| 96 |
"""
|
| 97 |
-
Reset the chatbot output
|
| 98 |
-
:return: An empty list
|
| 99 |
"""
|
| 100 |
-
|
| 101 |
-
return [], new_session_id
|
| 102 |
|
| 103 |
def create_interface(self) -> gr.Blocks:
|
| 104 |
"""
|
|
@@ -121,33 +118,15 @@ class ChatbotInterface:
|
|
| 121 |
placeholder=self.input_placeholder
|
| 122 |
)
|
| 123 |
|
| 124 |
-
# Session state
|
| 125 |
-
session_state = gr.State(str(uuid4()))#self.response_manager.start_session())
|
| 126 |
-
|
| 127 |
# Buttons
|
| 128 |
with gr.Row():
|
| 129 |
reset = gr.Button(self.reset_button, variant="secondary")
|
| 130 |
submit = gr.Button(self.submit_button, variant="primary")
|
| 131 |
|
| 132 |
# Button actions
|
| 133 |
-
submit.click(
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
)
|
| 137 |
-
user_input.submit(
|
| 138 |
-
fn=lambda query, session_id: self.response_manager.generate_response(query, session_id),
|
| 139 |
-
inputs=[user_input, session_state], outputs=[chatbot_output]
|
| 140 |
-
)
|
| 141 |
-
reset.click(
|
| 142 |
-
fn=self.reset_output,
|
| 143 |
-
inputs=None,
|
| 144 |
-
outputs=[chatbot_output, session_state]
|
| 145 |
-
)
|
| 146 |
-
|
| 147 |
-
# # Button actions
|
| 148 |
-
# submit.click(fn=self.generate_response, inputs=[user_input, chatbot_output], outputs=chatbot_output)
|
| 149 |
-
# user_input.submit(fn=self.generate_response, inputs=[user_input, chatbot_output], outputs=chatbot_output)
|
| 150 |
-
# reset.click(fn=self.reset_output, inputs=None, outputs=chatbot_output)
|
| 151 |
|
| 152 |
logging.info("Gradio interface created successfully.")
|
| 153 |
return demo
|
|
|
|
| 2 |
import json
|
| 3 |
import logging
|
| 4 |
from typing import Optional
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
from utils.response_manager import ResponseManager
|
| 7 |
|
|
|
|
| 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}")
|
|
|
|
| 90 |
logging.info("Configuration loaded successfully.")
|
| 91 |
return config
|
| 92 |
|
| 93 |
+
def reset_output(self) -> list:
|
| 94 |
"""
|
| 95 |
+
Reset the chatbot output.
|
| 96 |
+
:return: An empty list to reset the output.
|
| 97 |
"""
|
| 98 |
+
return []
|
|
|
|
| 99 |
|
| 100 |
def create_interface(self) -> gr.Blocks:
|
| 101 |
"""
|
|
|
|
| 118 |
placeholder=self.input_placeholder
|
| 119 |
)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
| 121 |
# Buttons
|
| 122 |
with gr.Row():
|
| 123 |
reset = gr.Button(self.reset_button, variant="secondary")
|
| 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.")
|
| 132 |
return demo
|