-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement WebSocket support (#156)
- Add WebSocket support for audio speech, transcriptions, and chat interactions - Introduce asynchronous WebSocket clients for real-time communication - Expand event handling for various WebSocket events - Enhance error handling and logging for WebSocket connections
- Loading branch information
Showing
22 changed files
with
2,560 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ dist/ | |
.env_private | ||
scripts/ | ||
.cache/ | ||
output.wav |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from cozepy import Auth | ||
from cozepy.request import Requester | ||
from cozepy.util import http_base_url_to_ws, remove_url_trailing_slash | ||
|
||
from .audio import AsyncWebsocketsAudioClient, WebsocketsAudioClient | ||
from .chat import AsyncWebsocketsChatBuildClient, WebsocketsChatBuildClient | ||
|
||
|
||
class WebsocketsClient(object): | ||
def __init__(self, base_url: str, auth: Auth, requester: Requester): | ||
self._base_url = http_base_url_to_ws(remove_url_trailing_slash(base_url)) | ||
self._auth = auth | ||
self._requester = requester | ||
|
||
@property | ||
def audio(self) -> WebsocketsAudioClient: | ||
return WebsocketsAudioClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) | ||
|
||
@property | ||
def chat(self) -> WebsocketsChatBuildClient: | ||
return WebsocketsChatBuildClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) | ||
|
||
|
||
class AsyncWebsocketsClient(object): | ||
def __init__(self, base_url: str, auth: Auth, requester: Requester): | ||
self._base_url = http_base_url_to_ws(remove_url_trailing_slash(base_url)) | ||
self._auth = auth | ||
self._requester = requester | ||
|
||
@property | ||
def audio(self) -> AsyncWebsocketsAudioClient: | ||
return AsyncWebsocketsAudioClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) | ||
|
||
@property | ||
def chat(self) -> AsyncWebsocketsChatBuildClient: | ||
return AsyncWebsocketsChatBuildClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from cozepy.auth import Auth | ||
from cozepy.request import Requester | ||
|
||
from .speech import AsyncWebsocketsAudioSpeechBuildClient, WebsocketsAudioSpeechBuildClient | ||
from .transcriptions import AsyncWebsocketsAudioTranscriptionsBuildClient, WebsocketsAudioTranscriptionsBuildClient | ||
|
||
|
||
class WebsocketsAudioClient(object): | ||
def __init__(self, base_url: str, auth: Auth, requester: Requester): | ||
self._base_url = base_url | ||
self._auth = auth | ||
self._requester = requester | ||
|
||
@property | ||
def transcriptions(self) -> "WebsocketsAudioTranscriptionsBuildClient": | ||
return WebsocketsAudioTranscriptionsBuildClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) | ||
|
||
@property | ||
def speech(self) -> "WebsocketsAudioSpeechBuildClient": | ||
return WebsocketsAudioSpeechBuildClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) | ||
|
||
|
||
class AsyncWebsocketsAudioClient(object): | ||
def __init__(self, base_url: str, auth: Auth, requester: Requester): | ||
self._base_url = base_url | ||
self._auth = auth | ||
self._requester = requester | ||
|
||
@property | ||
def transcriptions(self) -> "AsyncWebsocketsAudioTranscriptionsBuildClient": | ||
return AsyncWebsocketsAudioTranscriptionsBuildClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) | ||
|
||
@property | ||
def speech(self) -> "AsyncWebsocketsAudioSpeechBuildClient": | ||
return AsyncWebsocketsAudioSpeechBuildClient( | ||
base_url=self._base_url, | ||
auth=self._auth, | ||
requester=self._requester, | ||
) |
Oops, something went wrong.