mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
refactor(native): use endpoint binding for WebSocket dispatch
This commit is contained in:
parent
f9a1fd42af
commit
cfcaefd09b
2 changed files with 3 additions and 44 deletions
|
|
@ -14,16 +14,16 @@ from litellm.rust_bridge.protocols import (
|
|||
RustResponsesWebSocketConnection,
|
||||
)
|
||||
from litellm.rust_bridge.runtime import (
|
||||
AsyncEndpointDispatch,
|
||||
BridgeErrorContext,
|
||||
EndpointBinding,
|
||||
async_none,
|
||||
identity,
|
||||
)
|
||||
from litellm.rust_bridge.timeouts import timeout_to_seconds
|
||||
|
||||
_RESPONSES_WEBSOCKET: Final[AsyncEndpointDispatch[RustResponsesWebSocketConnection]] = AsyncEndpointDispatch.native(
|
||||
_RESPONSES_WEBSOCKET: Final[EndpointBinding[RustResponsesWebSocketConnection]] = EndpointBinding.native(
|
||||
route="responses_websocket",
|
||||
asynchronous=lambda native: native.ResponsesWebSocketConnection,
|
||||
select=lambda native: native.ResponsesWebSocketConnection,
|
||||
enabled=rust_enabled,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -449,47 +449,6 @@ class EndpointDispatch(Generic[SyncBindingT, AsyncBindingT]):
|
|||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class AsyncEndpointDispatch(Generic[AsyncBindingT]):
|
||||
asynchronous: EndpointBinding[AsyncBindingT]
|
||||
|
||||
@staticmethod
|
||||
def native(
|
||||
*,
|
||||
route: str,
|
||||
asynchronous: Callable[[NativeModule], SelectedAsyncT],
|
||||
enabled: RustEnablement,
|
||||
) -> AsyncEndpointDispatch[SelectedAsyncT]:
|
||||
return AsyncEndpointDispatch(
|
||||
asynchronous=EndpointBinding.native(route=route, select=asynchronous, enabled=enabled)
|
||||
)
|
||||
|
||||
def override(self, value: AsyncBindingT | None) -> None:
|
||||
self.asynchronous.override(value)
|
||||
|
||||
def reset(self) -> None:
|
||||
self.asynchronous.reset()
|
||||
|
||||
async def ainvoke(
|
||||
self,
|
||||
*,
|
||||
prepare: Callable[[], RequestT],
|
||||
call: Callable[[AsyncBindingT, RequestT], Awaitable[NativeT]],
|
||||
fallback: Callable[[], Awaitable[ResultT]],
|
||||
adapt: Callable[[NativeT], ResultT],
|
||||
error_context: BridgeErrorContext,
|
||||
eligible: bool = True,
|
||||
) -> ResultT:
|
||||
return await self.asynchronous.ainvoke(
|
||||
prepare=prepare,
|
||||
call=call,
|
||||
fallback=fallback,
|
||||
adapt=adapt,
|
||||
error_context=error_context,
|
||||
eligible=eligible,
|
||||
)
|
||||
|
||||
|
||||
def _error_message(error: BaseException) -> str:
|
||||
reason: Final[object] = error.args[0] if error.args else str(error)
|
||||
return reason if isinstance(reason, str) else str(reason)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue