RemiFabre
commited on
Commit
·
a87fc68
1
Parent(s):
b30c470
Fixed format_timestamp() function
Browse files
src/reachy_mini_conversation_demo/openai_realtime.py
CHANGED
|
@@ -228,14 +228,12 @@ class OpenaiRealtimeHandler(AsyncStreamHandler):
|
|
| 228 |
self.connection = None
|
| 229 |
|
| 230 |
def format_timestamp(self):
|
| 231 |
-
"""Format current timestamp with date, time and elapsed seconds."""
|
| 232 |
-
|
| 233 |
-
elapsed_seconds =
|
| 234 |
-
dt = datetime.
|
| 235 |
return f"[{dt.strftime('%Y-%m-%d %H:%M:%S')} | +{elapsed_seconds:.1f}s]"
|
| 236 |
|
| 237 |
-
|
| 238 |
-
|
| 239 |
async def send_idle_signal(self, idle_duration) -> None:
|
| 240 |
"""Send an idle signal to the openai server."""
|
| 241 |
logger.debug("Sending idle signal")
|
|
|
|
| 228 |
self.connection = None
|
| 229 |
|
| 230 |
def format_timestamp(self):
|
| 231 |
+
"""Format current timestamp with date, time, and elapsed seconds."""
|
| 232 |
+
loop_time = asyncio.get_event_loop().time() # monotonic
|
| 233 |
+
elapsed_seconds = loop_time - self.start_time
|
| 234 |
+
dt = datetime.now() # wall-clock
|
| 235 |
return f"[{dt.strftime('%Y-%m-%d %H:%M:%S')} | +{elapsed_seconds:.1f}s]"
|
| 236 |
|
|
|
|
|
|
|
| 237 |
async def send_idle_signal(self, idle_duration) -> None:
|
| 238 |
"""Send an idle signal to the openai server."""
|
| 239 |
logger.debug("Sending idle signal")
|
tests/test_openai_realtime.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
from unittest.mock import MagicMock
|
| 4 |
+
|
| 5 |
+
from reachy_mini_conversation_demo.openai_realtime import OpenaiRealtimeHandler
|
| 6 |
+
from reachy_mini_conversation_demo.tools import ToolDependencies
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _build_handler(loop):
|
| 10 |
+
asyncio.set_event_loop(loop)
|
| 11 |
+
deps = ToolDependencies(reachy_mini=MagicMock(), movement_manager=MagicMock())
|
| 12 |
+
return OpenaiRealtimeHandler(deps)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_format_timestamp_uses_wall_clock():
|
| 16 |
+
loop = asyncio.new_event_loop()
|
| 17 |
+
try:
|
| 18 |
+
print("Testing format_timestamp...")
|
| 19 |
+
handler = _build_handler(loop)
|
| 20 |
+
formatted = handler.format_timestamp()
|
| 21 |
+
print(f"Formatted timestamp: {formatted}")
|
| 22 |
+
finally:
|
| 23 |
+
asyncio.set_event_loop(None)
|
| 24 |
+
loop.close()
|
| 25 |
+
|
| 26 |
+
# Extract year from "[YYYY-MM-DD ...]"
|
| 27 |
+
year = int(formatted[1:5])
|
| 28 |
+
assert year == datetime.utcnow().year
|