Skip to content

Commit 0b4b74f

Browse files
Wang-Daojiyuan.wangfridayLCaralHsi
authored
Feat/fix palyground bug (#729)
* fix playground bug, internet search judge * fix playground internet bug * modify delete mem * modify tool resp bug in multi cube * fix bug in playground chat handle and search inter * modify prompt * fix bug in playground * fix bug playfround * fix bug * fix code * fix model bug in playground * modify plan b * llm param modify * add logger in playground * modify code * fix bug * modify code * modify code * fix bug * fix search bug in plarground * fixx bug * move schadualr to back * modify pref location * modify fast net search * add tags and new package * modify prompt fix bug * remove nltk due to image promblem * prompt modify * modify bug remove redundant field * modify bug * fix playground bug * fix bug * bust internet topk * bust to 50 * fix bug cite * modify search * remote query add in playground * modify bug * modify pref bug * move add position * modify chat prompt * modify overthinking * add logger in playground chat * midify mem * remove must in prompt * add logger --------- Co-authored-by: yuan.wang <[email protected]> Co-authored-by: chunyu li <[email protected]> Co-authored-by: CaralHsi <[email protected]>
1 parent 9de723b commit 0b4b74f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/memos/api/handlers/chat_handler.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import asyncio
99
import json
1010
import re
11+
import time
1112
import traceback
1213

1314
from collections.abc import Generator
@@ -170,12 +171,18 @@ def handle_chat_complete(self, chat_req: APIChatCompleteRequest) -> dict[str, An
170171
)
171172

172173
model = chat_req.model_name_or_path or next(iter(self.chat_llms.keys()))
174+
175+
self.logger.info(f"[Cloud Service Chat Complete Model]: {model}")
176+
strat = time.time()
173177
response = self.chat_llms[model].generate(current_messages, model_name_or_path=model)
178+
end = time.time()
179+
self.logger.info(f"[Cloud Service Chat Complete Time]: {end - strat} seconds")
174180

175181
# Step 4: start add after chat asynchronously
176182
if chat_req.add_message_on_answer:
177183
# Resolve writable cube IDs (for add)
178184
writable_cube_ids = chat_req.writable_cube_ids or [chat_req.user_id]
185+
start = time.time()
179186
self._start_add_to_memory(
180187
user_id=chat_req.user_id,
181188
writable_cube_ids=writable_cube_ids,
@@ -184,6 +191,8 @@ def handle_chat_complete(self, chat_req: APIChatCompleteRequest) -> dict[str, An
184191
full_response=response,
185192
async_mode="async",
186193
)
194+
end = time.time()
195+
self.logger.info(f"[Cloud Service Chat Add Time]: {end - start} seconds")
187196

188197
match = re.search(r"<think>([\s\S]*?)</think>", response)
189198
reasoning_text = match.group(1) if match else None
@@ -295,9 +304,14 @@ def generate_chat_response() -> Generator[str, None, None]:
295304
)
296305

297306
model = chat_req.model_name_or_path or next(iter(self.chat_llms.keys()))
307+
self.logger.info(f"[Cloud Service Chat Stream Model]: {model}")
308+
309+
start = time.time()
298310
response_stream = self.chat_llms[model].generate_stream(
299311
current_messages, model_name_or_path=model
300312
)
313+
end = time.time()
314+
self.logger.info(f"[Cloud Service Chat Stream Time]: {end - start} seconds")
301315

302316
# Stream the response
303317
buffer = ""
@@ -329,6 +343,7 @@ def generate_chat_response() -> Generator[str, None, None]:
329343
writable_cube_ids = chat_req.writable_cube_ids or (
330344
[chat_req.mem_cube_id] if chat_req.mem_cube_id else [chat_req.user_id]
331345
)
346+
start = time.time()
332347
self._start_add_to_memory(
333348
user_id=chat_req.user_id,
334349
writable_cube_ids=writable_cube_ids,
@@ -337,7 +352,10 @@ def generate_chat_response() -> Generator[str, None, None]:
337352
full_response=full_response,
338353
async_mode="async",
339354
)
340-
355+
end = time.time()
356+
self.logger.info(
357+
f"[Cloud Service Chat Stream Add Time]: {end - start} seconds"
358+
)
341359
except Exception as e:
342360
self.logger.error(f"Error in chat stream: {e}", exc_info=True)
343361
error_data = f"data: {json.dumps({'type': 'error', 'content': str(traceback.format_exc())})}\n\n"

0 commit comments

Comments
 (0)