Skip to content

Commit

Permalink
feat: print trace-id and alb_receive_time
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Oct 24, 2024
1 parent 46a5db3 commit f449fb4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions agents/ten_packages/extension/minimax_v2v_python/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,26 @@ def _complete_with_history(self, ts: datetime, buff: bytearray) -> Iterator[byte
try:
# 发送 POST 请求
with self.client.stream("POST", url, headers=headers, json=payload) as response:
trace_id = ""
alb_receive_time = ""
try:
trace_id = response.headers.get("Trace-Id")
except:
logger.warning("Get response, no Trace-Id")
try:
alb_receive_time = response.headers.get("alb_receive_time")
except:
logger.warning("Get response, no alb_receive_time")
logger.info(
f"Get response trace-id: {trace_id}, alb_receive_time: {alb_receive_time}, cost_time {self._duration_in_ms_since(start_time)}ms"
)

response.raise_for_status() # 检查响应状态

for line in response.iter_lines():
# logger.info(f"-> line {line}")
if self._need_interrupt(ts):
logger.warning("interrupted")
logger.warning(f"trace-id: {trace_id}, interrupted")
if self.transcript:
self.transcript += "[interrupted]"
self._append_message("assistant", self.transcript)
Expand All @@ -296,7 +311,7 @@ def _complete_with_history(self, ts: datetime, buff: bytearray) -> Iterator[byte
self._send_transcript(content, "assistant", False)
if not assistant_transcript_ttfb:
assistant_transcript_ttfb = self._duration_in_ms_since(start_time)
logger.info(f"assistant_transcript_ttfb {assistant_transcript_ttfb}ms")
logger.info(f"trace-id: {trace_id}, assistant_transcript_ttfb {assistant_transcript_ttfb}ms")
if delta.get("audio_content") and delta["audio_content"] != "":
logger.info(f"[sse] data chunck-{i} get audio_content")
base64_str = delta["audio_content"]
Expand All @@ -306,15 +321,15 @@ def _complete_with_history(self, ts: datetime, buff: bytearray) -> Iterator[byte
self._send_audio_out(buff)
if not assistant_audio_ttfb:
assistant_audio_ttfb = self._duration_in_ms_since(start_time)
logger.info(f"assistant_audio_ttfb {assistant_audio_ttfb}ms")
logger.info(f"trace-id: {trace_id}, assistant_audio_ttfb {assistant_audio_ttfb}ms")
if delta.get("tool_calls"):
logger.info(f"ignore tool call {delta}")
continue
if delta.get("role") == "user":
self._send_transcript(delta['content'], "user", True)
if not user_transcript_ttfb:
user_transcript_ttfb = self._duration_in_ms_since(start_time)
logger.info(f"user_transcript_ttfb {user_transcript_ttfb}ms")
logger.info(f"trace-id: {trace_id}, user_transcript_ttfb {user_transcript_ttfb}ms")

except httpx.TimeoutException:
logger.warning("http timeout")
Expand Down

0 comments on commit f449fb4

Please sign in to comment.