Skip to content

feat(inference): add InferenceWebsocket#5406

Open
chenghao-mou wants to merge 2 commits intomainfrom
chenghao/feat/inference-ws
Open

feat(inference): add InferenceWebsocket#5406
chenghao-mou wants to merge 2 commits intomainfrom
chenghao/feat/inference-ws

Conversation

@chenghao-mou
Copy link
Copy Markdown
Member

A new websocket helper that:

  • provides a context manager for lifetime management
  • recv loop that yields valid payloads, handles close detection internally via mark_closing()

Design decisions:

  • It still leaves task orchestration and session creation to the caller
  • It does not handle retry or stream class-level abstraction (RecognizeStream and InterruptionStreamBase already handle them differently in _main_task)

Usage:

async with InferenceWebSocket(
      session=http_session,
      base_url="https://agent-gateway.livekit.cloud/v1",
      path="/stt?model=deepgram/nova-3",
      api_key=api_key,
      api_secret=api_secret,
      timeout=10.0,
  ) as iws:
      await iws.send(session_create_data)
      async def send_coro():
          ...
      
     async def recv_coro():
          async for raw_data in iws.recv(str):
              ...

      tasks = [
          asyncio.create_task(...),
          asyncio.create_task(...),
      ]
      try:
          await asyncio.gather(*tasks)
      finally:
          await aio.cancel_and_wait(*tasks)

@chenghao-mou chenghao-mou requested a review from a team April 10, 2026 03:55
devin-ai-integration[bot]

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant