| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import time |
| 5 | from typing import Literal |
| 6 | |
| 7 | from pydantic import Field |
| 8 | |
| 9 | from vllm.entrypoints.serve.engine.protocol import OpenAIBaseModel, UsageInfo |
| 10 | from vllm.utils import random_uuid |
| 11 | |
| 12 | # Client -> Server Events |
| 13 | |
| 14 | |
| 15 | class InputAudioBufferAppend(OpenAIBaseModel): |
| 16 | """Append audio chunk to buffer.""" |
| 17 | |
| 18 | type: Literal["input_audio_buffer.append"] = "input_audio_buffer.append" |
| 19 | audio: str # base64-encoded PCM16 @ 16kHz |
| 20 | |
| 21 | |
| 22 | class InputAudioBufferCommit(OpenAIBaseModel): |
| 23 | """Process accumulated audio buffer.""" |
| 24 | |
| 25 | type: Literal["input_audio_buffer.commit"] = "input_audio_buffer.commit" |
| 26 | final: bool = False |
| 27 | |
| 28 | |
| 29 | # Server -> Client Events |
| 30 | class SessionUpdate(OpenAIBaseModel): |
| 31 | """Configure session parameters.""" |
| 32 | |
| 33 | type: Literal["session.update"] = "session.update" |
| 34 | model: str | None = None |
| 35 | |
| 36 | |
| 37 | class SessionCreated(OpenAIBaseModel): |
| 38 | """Connection established notification.""" |
| 39 | |
| 40 | type: Literal["session.created"] = "session.created" |
| 41 | id: str = Field(default_factory=lambda: f"sess-{random_uuid()}") |
| 42 | created: int = Field(default_factory=lambda: int(time.time())) |
| 43 | |
| 44 | |
| 45 | class TranscriptionDelta(OpenAIBaseModel): |
| 46 | """Incremental transcription text.""" |
| 47 | |
| 48 | type: Literal["transcription.delta"] = "transcription.delta" |
| 49 | delta: str # Incremental text |
| 50 | |
| 51 | |
| 52 | class TranscriptionDone(OpenAIBaseModel): |
| 53 | """Final transcription with usage stats.""" |
| 54 | |
| 55 | type: Literal["transcription.done"] = "transcription.done" |
| 56 | text: str # Complete transcription |
| 57 | usage: UsageInfo | None = None |
| 58 | |
| 59 | |
| 60 | class ErrorEvent(OpenAIBaseModel): |
| 61 | """Error notification.""" |
| 62 | |
| 63 | type: Literal["error"] = "error" |
| 64 | error: str |
| 65 | code: str | None = None |