Skip to content

Commit

Permalink
feat: calc ttfb
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Oct 23, 2024
1 parent 1a91ba5 commit bfc6de2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions agents/ten_packages/extension/minimax_v2v_python/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ def _complete_with_history(self, ts: datetime, buff: bytearray) -> Iterator[byte
logger.info(f"start request, data len {len(buff)}")
# response = requests.post(url, headers=headers, json=payload, stream=True, timeout=5)
# logger.info(f"Get response, trace-id: {response.headers.get('Trace-Id')}, cost_time {self._duration_in_ms_since(start_time)}ms")
user_transcript_ttfb = None
assistant_transcript_ttfb = None
assistant_audio_ttfb = None
self.transcript = ""
i = 0
with httpx.Client(timeout=httpx.Timeout(5)) as client:
Expand Down Expand Up @@ -285,18 +288,27 @@ def _complete_with_history(self, ts: datetime, buff: bytearray) -> Iterator[byte
self.transcript += content
logger.info(f"[sse] data chunck-{i} get assistant transcript {content}")
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")
if delta.get("audio_content") and delta["audio_content"] != "":
logger.info(f"[sse] data chunck-{i} get audio_content")
base64_str = delta["audio_content"]
# with open(f"minimax_v2v_data_{i}.txt", "a") as f:
# f.write(base64_str)
buff = base64.b64decode(base64_str)
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")
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")

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

0 comments on commit bfc6de2

Please sign in to comment.