Chris4K commited on
Commit
d10f874
·
verified ·
1 Parent(s): c757f82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -86,8 +86,6 @@ async def chat_fn(user_input: str, history: list, input_graph_state: dict, uuid:
86
  try:
87
  logger.info(f"Processing user input: {user_input[:100]}...")
88
  logger.info(f"History format: {type(history)}, length: {len(history) if history else 0}")
89
- if history:
90
- logger.info(f"Sample history entry: {history[0] if len(history) > 0 else 'None'}")
91
 
92
  # Initialize input_graph_state if None
93
  if input_graph_state is None:
@@ -132,7 +130,7 @@ async def chat_fn(user_input: str, history: list, input_graph_state: dict, uuid:
132
  )
133
 
134
  output: str = ""
135
- final_state: dict = {}
136
  waiting_output_seq: list[str] = []
137
 
138
  # Add user message to history immediately
@@ -158,14 +156,14 @@ async def chat_fn(user_input: str, history: list, input_graph_state: dict, uuid:
158
  # Update the last tuple with current status
159
  if updated_history:
160
  updated_history[-1] = (user_input, "\n".join(waiting_output_seq))
161
- yield updated_history, gr.skip(), gr.skip()
162
 
163
  elif tool_name == "download_website_text":
164
  url = msg_tool_call['args']['url']
165
  waiting_output_seq.append(f"📥 Downloading text from '{url}'...")
166
  if updated_history:
167
  updated_history[-1] = (user_input, "\n".join(waiting_output_seq))
168
- yield updated_history, gr.skip(), gr.skip()
169
 
170
  elif tool_name == "human_assistance":
171
  query = msg_tool_call["args"]["query"]
@@ -185,7 +183,7 @@ async def chat_fn(user_input: str, history: list, input_graph_state: dict, uuid:
185
  waiting_output_seq.append(f"🔧 Running {tool_name}...")
186
  if updated_history:
187
  updated_history[-1] = (user_input, "\n".join(waiting_output_seq))
188
- yield updated_history, gr.skip(), gr.skip()
189
 
190
  elif stream_mode == "messages":
191
  msg, metadata = chunk
@@ -207,13 +205,13 @@ async def chat_fn(user_input: str, history: list, input_graph_state: dict, uuid:
207
  # Update the last tuple with accumulated output
208
  if updated_history:
209
  updated_history[-1] = (user_input, output)
210
- yield updated_history, gr.skip(), gr.skip()
211
 
212
  # Final yield with complete response
213
  if updated_history:
214
- updated_history[-1] = (user_input, output + " ")
215
  logger.info(f"Final response: {output[:100]}...")
216
- yield updated_history, dict(final_state), True
217
 
218
  except Exception as e:
219
  logger.exception("Exception occurred in chat_fn")
@@ -221,7 +219,8 @@ async def chat_fn(user_input: str, history: list, input_graph_state: dict, uuid:
221
  if not isinstance(history, list):
222
  history = []
223
  error_history = history + [(user_input, error_message)]
224
- yield error_history, gr.skip(), False
 
225
 
226
 
227
  def convert_to_tuples_format(messages_list):
 
86
  try:
87
  logger.info(f"Processing user input: {user_input[:100]}...")
88
  logger.info(f"History format: {type(history)}, length: {len(history) if history else 0}")
 
 
89
 
90
  # Initialize input_graph_state if None
91
  if input_graph_state is None:
 
130
  )
131
 
132
  output: str = ""
133
+ final_state: dict = input_graph_state.copy() # Initialize with current state
134
  waiting_output_seq: list[str] = []
135
 
136
  # Add user message to history immediately
 
156
  # Update the last tuple with current status
157
  if updated_history:
158
  updated_history[-1] = (user_input, "\n".join(waiting_output_seq))
159
+ yield updated_history, final_state, False
160
 
161
  elif tool_name == "download_website_text":
162
  url = msg_tool_call['args']['url']
163
  waiting_output_seq.append(f"📥 Downloading text from '{url}'...")
164
  if updated_history:
165
  updated_history[-1] = (user_input, "\n".join(waiting_output_seq))
166
+ yield updated_history, final_state, False
167
 
168
  elif tool_name == "human_assistance":
169
  query = msg_tool_call["args"]["query"]
 
183
  waiting_output_seq.append(f"🔧 Running {tool_name}...")
184
  if updated_history:
185
  updated_history[-1] = (user_input, "\n".join(waiting_output_seq))
186
+ yield updated_history, final_state, False
187
 
188
  elif stream_mode == "messages":
189
  msg, metadata = chunk
 
205
  # Update the last tuple with accumulated output
206
  if updated_history:
207
  updated_history[-1] = (user_input, output)
208
+ yield updated_history, final_state, False
209
 
210
  # Final yield with complete response
211
  if updated_history:
212
+ updated_history[-1] = (user_input, output.strip() if output else "I'm here to help with your DIY projects!")
213
  logger.info(f"Final response: {output[:100]}...")
214
+ yield updated_history, final_state, True
215
 
216
  except Exception as e:
217
  logger.exception("Exception occurred in chat_fn")
 
219
  if not isinstance(history, list):
220
  history = []
221
  error_history = history + [(user_input, error_message)]
222
+ # Return safe values instead of gr.skip()
223
+ yield error_history, input_graph_state or {}, False
224
 
225
 
226
  def convert_to_tuples_format(messages_list):