Shreyas094 commited on
Commit
1b0938e
·
verified ·
1 Parent(s): 8b5e7fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -139,13 +139,21 @@ async def respond(message, system_prompt, history, model, temperature, num_calls
139
  logging.info(f"Number of API Calls: {num_calls}")
140
  logging.info(f"Use Embeddings: {use_embeddings}")
141
  logging.info(f"System Prompt: {system_prompt}")
 
142
 
143
  # Convert gradio history to the format expected by get_response_with_search
144
  chat_history = []
145
- for human, assistant in history:
146
- chat_history.append({"role": "user", "content": human})
147
- if assistant:
148
- chat_history.append({"role": "assistant", "content": assistant})
 
 
 
 
 
 
 
149
 
150
  try:
151
  full_response = ""
@@ -190,8 +198,16 @@ css = """
190
  def create_gradio_interface():
191
  custom_placeholder = "Enter your question here for web search."
192
 
 
 
 
 
 
 
 
 
193
  demo = gr.ChatInterface(
194
- fn=respond,
195
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),
196
  additional_inputs=[
197
  gr.Textbox(value=DEFAULT_SYSTEM_PROMPT, lines=6, label="System Prompt", placeholder="Enter your system prompt here"),
 
139
  logging.info(f"Number of API Calls: {num_calls}")
140
  logging.info(f"Use Embeddings: {use_embeddings}")
141
  logging.info(f"System Prompt: {system_prompt}")
142
+ logging.info(f"History: {history}") # Log the history for debugging
143
 
144
  # Convert gradio history to the format expected by get_response_with_search
145
  chat_history = []
146
+ if history:
147
+ for entry in history:
148
+ if isinstance(entry, (list, tuple)) and len(entry) == 2:
149
+ human, assistant = entry
150
+ chat_history.append({"role": "user", "content": human})
151
+ if assistant:
152
+ chat_history.append({"role": "assistant", "content": assistant})
153
+ elif isinstance(entry, str):
154
+ # If it's a string, assume it's a user message
155
+ chat_history.append({"role": "user", "content": entry})
156
+ # Ignore any other formats
157
 
158
  try:
159
  full_response = ""
 
198
  def create_gradio_interface():
199
  custom_placeholder = "Enter your question here for web search."
200
 
201
+ async def wrapped_respond(*args):
202
+ try:
203
+ async for response in respond(*args):
204
+ yield response
205
+ except Exception as e:
206
+ logging.error(f"Error in wrapped_respond: {str(e)}")
207
+ yield f"An error occurred: {str(e)}"
208
+
209
  demo = gr.ChatInterface(
210
+ fn=wrapped_respond, # Use the wrapped version
211
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),
212
  additional_inputs=[
213
  gr.Textbox(value=DEFAULT_SYSTEM_PROMPT, lines=6, label="System Prompt", placeholder="Enter your system prompt here"),