Update app.py
Browse files
app.py
CHANGED
@@ -128,7 +128,7 @@ def truncate_history(history: list[tuple[str, str]], system_message: str, max_le
|
|
128 |
|
129 |
def respond(
|
130 |
message,
|
131 |
-
|
132 |
system_message,
|
133 |
max_tokens,
|
134 |
temperature,
|
@@ -136,6 +136,7 @@ def respond(
|
|
136 |
):
|
137 |
"""Responds to a user message, maintaining conversation history. Returns history."""
|
138 |
|
|
|
139 |
formatted_system_message = system_message # Use the provided system message
|
140 |
|
141 |
truncated_history = truncate_history(history, formatted_system_message, MAX_CONTEXT_LENGTH - max_tokens - 100)
|
@@ -173,7 +174,7 @@ def clear_memory():
|
|
173 |
# --- Gradio Interface ---
|
174 |
with gr.Blocks() as demo:
|
175 |
history_state = gr.State([]) # Initialize history as a state
|
176 |
-
chatbot = gr.Chatbot(label="Roos NVC Chatbot", value=
|
177 |
msg = gr.Textbox(label="Your Message", placeholder="Type your message here...") # Added placeholder
|
178 |
with gr.Row():
|
179 |
send_btn = gr.Button("Send")
|
|
|
128 |
|
129 |
def respond(
|
130 |
message,
|
131 |
+
history_state, # Receive history_state instead of history
|
132 |
system_message,
|
133 |
max_tokens,
|
134 |
temperature,
|
|
|
136 |
):
|
137 |
"""Responds to a user message, maintaining conversation history. Returns history."""
|
138 |
|
139 |
+
history = history_state # Access the value of history_state
|
140 |
formatted_system_message = system_message # Use the provided system message
|
141 |
|
142 |
truncated_history = truncate_history(history, formatted_system_message, MAX_CONTEXT_LENGTH - max_tokens - 100)
|
|
|
174 |
# --- Gradio Interface ---
|
175 |
with gr.Blocks() as demo:
|
176 |
history_state = gr.State([]) # Initialize history as a state
|
177 |
+
chatbot = gr.Chatbot(label="Roos NVC Chatbot", value=[]) # Initialize chatbot with empty list, not history_state directly
|
178 |
msg = gr.Textbox(label="Your Message", placeholder="Type your message here...") # Added placeholder
|
179 |
with gr.Row():
|
180 |
send_btn = gr.Button("Send")
|