ABAO77 commited on
Commit
6b7a285
·
verified ·
1 Parent(s): e390496

Upload 164 files

Browse files
src/apis/controllers/__pycache__/chat_controller.cpython-311.pyc CHANGED
Binary files a/src/apis/controllers/__pycache__/chat_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/chat_controller.cpython-311.pyc differ
 
src/apis/controllers/__pycache__/planner_controller.cpython-311.pyc CHANGED
Binary files a/src/apis/controllers/__pycache__/planner_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/planner_controller.cpython-311.pyc differ
 
src/apis/controllers/chat_controller.py CHANGED
@@ -80,7 +80,7 @@ async def chat_streaming_function(user, data: Chat, background_tasks: Background
80
  process_history = post_process_history(history) if history is not None else None
81
  except Exception as e:
82
  logger.error(f"Error processing chat history: {str(e)}")
83
- yield json.dumps({"type": "error", "content": "Error processing chat history" + str(e)}, ensure_ascii=False) + "\n"
84
  return
85
 
86
  config = {
@@ -128,7 +128,7 @@ async def chat_streaming_function(user, data: Chat, background_tasks: Background
128
  {"type": "tool_call", "content": tool_name}, ensure_ascii=False
129
  )
130
  print(message_yield)
131
- yield message_yield + "\n"
132
 
133
  if metadata["langgraph_node"] in [
134
  "primary_assistant",
@@ -141,12 +141,12 @@ async def chat_streaming_function(user, data: Chat, background_tasks: Background
141
  {"type": "message", "content": temp}, ensure_ascii=False
142
  )
143
  print(message_yield)
144
- yield message_yield + "\n"
145
  if event_type == "values":
146
  last_output_state = event_message
147
  except Exception as e:
148
  logger.error(f"Error processing stream event: {str(e)}")
149
- yield json.dumps({"type": "error", "content": "Error processing response" + str(e)}, ensure_ascii=False) + "\n"
150
  return
151
 
152
  if last_output_state is None:
@@ -169,12 +169,12 @@ async def chat_streaming_function(user, data: Chat, background_tasks: Background
169
 
170
  except Exception as e:
171
  logger.error(f"Error in workflow stream processing: {str(e)}")
172
- yield json.dumps({"type": "error", "content": "Error processing chat stream" + str(e)}, ensure_ascii=False) + "\n"
173
  return
174
 
175
  except Exception as e:
176
  logger.error(f"Unexpected error in chat streaming: {str(e)}")
177
- yield json.dumps({"type": "error", "content": "An unexpected error occurred" + str(e)}, ensure_ascii=False) + "\n"
178
  return
179
 
180
  background_tasks.add_task(
@@ -245,7 +245,7 @@ async def chat_streaming_no_login_function(
245
  {"type": "tool_call", "content": tool_name}, ensure_ascii=False
246
  )
247
  print(message_yield)
248
- yield message_yield + "\n"
249
 
250
  if metadata["langgraph_node"] in [
251
  "primary_assistant",
@@ -258,12 +258,12 @@ async def chat_streaming_no_login_function(
258
  {"type": "message", "content": temp}, ensure_ascii=False
259
  )
260
  print(message_yield)
261
- yield message_yield + "\n"
262
  if event_type == "values":
263
  last_output_state = event_message
264
  except Exception as e:
265
  logger.error(f"Error processing stream event: {str(e)}")
266
- yield json.dumps({"type": "error", "content": "Error processing response" + str(e)}, ensure_ascii=False) + "\n"
267
  return
268
 
269
  if last_output_state is None:
@@ -286,12 +286,12 @@ async def chat_streaming_no_login_function(
286
 
287
  except Exception as e:
288
  logger.error(f"Error in workflow stream processing: {str(e)}")
289
- yield json.dumps({"type": "error", "content": "Error processing chat stream" + str(e)}, ensure_ascii=False) + "\n"
290
  return
291
 
292
  except Exception as e:
293
  logger.error(f"Unexpected error in chat streaming: {str(e)}")
294
- yield json.dumps({"type": "error", "content": "An unexpected error occurred" + str(e)}, ensure_ascii=False) + "\n"
295
  return
296
 
297
 
 
80
  process_history = post_process_history(history) if history is not None else None
81
  except Exception as e:
82
  logger.error(f"Error processing chat history: {str(e)}")
83
+ yield json.dumps({"type": "error", "content": "Error processing chat history" + str(e)}, ensure_ascii=False)
84
  return
85
 
86
  config = {
 
128
  {"type": "tool_call", "content": tool_name}, ensure_ascii=False
129
  )
130
  print(message_yield)
131
+ yield message_yield
132
 
133
  if metadata["langgraph_node"] in [
134
  "primary_assistant",
 
141
  {"type": "message", "content": temp}, ensure_ascii=False
142
  )
143
  print(message_yield)
144
+ yield message_yield
145
  if event_type == "values":
146
  last_output_state = event_message
147
  except Exception as e:
148
  logger.error(f"Error processing stream event: {str(e)}")
149
+ yield json.dumps({"type": "error", "content": "Error processing response" + str(e)}, ensure_ascii=False)
150
  return
151
 
152
  if last_output_state is None:
 
169
 
170
  except Exception as e:
171
  logger.error(f"Error in workflow stream processing: {str(e)}")
172
+ yield json.dumps({"type": "error", "content": "Error processing chat stream" + str(e)}, ensure_ascii=False)
173
  return
174
 
175
  except Exception as e:
176
  logger.error(f"Unexpected error in chat streaming: {str(e)}")
177
+ yield json.dumps({"type": "error", "content": "An unexpected error occurred" + str(e)}, ensure_ascii=False)
178
  return
179
 
180
  background_tasks.add_task(
 
245
  {"type": "tool_call", "content": tool_name}, ensure_ascii=False
246
  )
247
  print(message_yield)
248
+ yield message_yield
249
 
250
  if metadata["langgraph_node"] in [
251
  "primary_assistant",
 
258
  {"type": "message", "content": temp}, ensure_ascii=False
259
  )
260
  print(message_yield)
261
+ yield message_yield
262
  if event_type == "values":
263
  last_output_state = event_message
264
  except Exception as e:
265
  logger.error(f"Error processing stream event: {str(e)}")
266
+ yield json.dumps({"type": "error", "content": "Error processing response" + str(e)}, ensure_ascii=False)
267
  return
268
 
269
  if last_output_state is None:
 
286
 
287
  except Exception as e:
288
  logger.error(f"Error in workflow stream processing: {str(e)}")
289
+ yield json.dumps({"type": "error", "content": "Error processing chat stream" + str(e)}, ensure_ascii=False)
290
  return
291
 
292
  except Exception as e:
293
  logger.error(f"Unexpected error in chat streaming: {str(e)}")
294
+ yield json.dumps({"type": "error", "content": "An unexpected error occurred" + str(e)}, ensure_ascii=False)
295
  return
296
 
297
 
src/apis/controllers/planner_controller.py CHANGED
@@ -26,12 +26,19 @@ async def message_generator(input_graph, config, background: BackgroundTasks):
26
  {"type": "message", "content": temp},
27
  ensure_ascii=False,
28
  )
29
- yield message_yield + "\n\n"
 
30
  if event_type == "values":
31
  last_output_state = event_message
32
  except Exception as e:
33
  logger.error(f"Error processing stream event: {str(e)}")
34
- yield json.dumps({"type": "error", "content": "Error processing planner response " + str(e)}, ensure_ascii=False) + "\n\n"
 
 
 
 
 
 
35
  return
36
 
37
  if last_output_state is None:
@@ -49,20 +56,39 @@ async def message_generator(input_graph, config, background: BackgroundTasks):
49
  },
50
  ensure_ascii=False,
51
  )
52
- yield final_response + "\n\n"
 
53
  except Exception as e:
54
  logger.error(f"Error parsing itinerary: {str(e)}")
55
- yield json.dumps({"type": "error", "content": "Error parsing the generated itinerary" + str(e)}, ensure_ascii=False) + "\n\n"
 
 
 
 
 
 
56
  return
57
 
58
  except Exception as e:
59
  logger.error(f"Error in planner workflow stream: {str(e)}")
60
- yield json.dumps({"type": "error", "content": "Error processing planner stream" + str(e)}, ensure_ascii=False) + "\n\n"
 
 
 
 
 
 
61
  return
62
 
63
  except Exception as e:
64
  logger.error(f"Unexpected error in planner: {str(e)}")
65
- yield json.dumps({"type": "error", "content": "An unexpected error occurred in the planner" + str(e)}, ensure_ascii=False) + "\n\n"
 
 
 
 
 
 
66
  return
67
 
68
 
 
26
  {"type": "message", "content": temp},
27
  ensure_ascii=False,
28
  )
29
+ # Remove extra newlines to prevent JSON parsing issues
30
+ yield message_yield
31
  if event_type == "values":
32
  last_output_state = event_message
33
  except Exception as e:
34
  logger.error(f"Error processing stream event: {str(e)}")
35
+ yield json.dumps(
36
+ {
37
+ "type": "error",
38
+ "content": "Error processing planner response " + str(e),
39
+ },
40
+ ensure_ascii=False,
41
+ )
42
  return
43
 
44
  if last_output_state is None:
 
56
  },
57
  ensure_ascii=False,
58
  )
59
+ # Send final response without extra newlines
60
+ yield final_response
61
  except Exception as e:
62
  logger.error(f"Error parsing itinerary: {str(e)}")
63
+ yield json.dumps(
64
+ {
65
+ "type": "error",
66
+ "content": "Error parsing the generated itinerary" + str(e),
67
+ },
68
+ ensure_ascii=False,
69
+ )
70
  return
71
 
72
  except Exception as e:
73
  logger.error(f"Error in planner workflow stream: {str(e)}")
74
+ yield json.dumps(
75
+ {
76
+ "type": "error",
77
+ "content": "Error processing planner stream" + str(e),
78
+ },
79
+ ensure_ascii=False,
80
+ )
81
  return
82
 
83
  except Exception as e:
84
  logger.error(f"Unexpected error in planner: {str(e)}")
85
+ yield json.dumps(
86
+ {
87
+ "type": "error",
88
+ "content": "An unexpected error occurred in the planner" + str(e),
89
+ },
90
+ ensure_ascii=False,
91
+ )
92
  return
93
 
94