Adding Cancellation requests to websockets#7
Open
jay2jp wants to merge 5 commits intocartesia-ai:mainfrom
Open
Adding Cancellation requests to websockets#7jay2jp wants to merge 5 commits intocartesia-ai:mainfrom
jay2jp wants to merge 5 commits intocartesia-ai:mainfrom
Conversation
…docs in a sense that they are different types of requests
kbrgl
reviewed
Oct 30, 2024
Member
There was a problem hiding this comment.
Hey @jay2jp! Thanks for your contribution! Your PR looks good. Can you add the cancel function to the TTSContext as well as the Async equivalents (AsyncWebsocket, AsyncTTSContext)?
It would look something like this:
def cancel(self): # Add this method to the _TTSContext class.
"""Cancel the context. This will close the context and stop any ongoing audio generation."""
self._websocket.cancel(self._context_id)The PR will also have to pass CI checks before it can be merged.
| self.connect() | ||
|
|
||
| if context_id is None: | ||
| #context_id = str(uuid.uuid4()) |
|
|
||
| request_body = _construct_tts_request_cancel(context_id=context_id) | ||
| self.websocket.send(json.dumps(request_body)) | ||
| return True No newline at end of file |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebSocket Cancellation Implementation
Added cancellation functionality to the WebSocket implementation, following the Cartesia API documentation.
Changes
Added new
cancelmethod to_WebSocketclass that implements the cancellation API described in:https://docs.cartesia.ai/api-reference/tts/working-with-web-sockets/contexts#cancelling-requests
Created separate request handling for cancellation to maintain API clarity:
_construct_tts_request_cancelfunction to handle cancel requestssendmethod to preserve required parameters (model_id,transcript,output_format)Implementation Notes
_WebSocketclass as it's our primary websocket implementation_TTSContextclass due to limited experience with that component_WebSocketclass and are working as expectedDocumentation
i have added lines towards the end of the read me showing how this works