Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Jan 9, 2025
2 parents 3260e8a + a3042be commit 880f579
Show file tree
Hide file tree
Showing 13 changed files with 1,046 additions and 277 deletions.
32 changes: 16 additions & 16 deletions cozepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .audio.rooms import CreateRoomResp
from .audio.speech import AudioFormat
from .audio.transcriptions import CreateTranslationResp
from .audio.transcriptions import CreateTranscriptionsResp
from .audio.voices import Voice
from .auth import (
AsyncDeviceOAuthApp,
Expand Down Expand Up @@ -92,27 +92,27 @@
from .templates import TemplateDuplicateResp, TemplateEntityType
from .version import VERSION
from .websockets.audio.speech import (
AsyncWebsocketsAudioSpeechCreateClient,
AsyncWebsocketsAudioSpeechClient,
AsyncWebsocketsAudioSpeechEventHandler,
InputTextBufferAppendEvent,
InputTextBufferCommitEvent,
InputTextBufferCommittedEvent,
InputTextBufferCompletedEvent,
InputTextBufferCompleteEvent,
SpeechAudioCompletedEvent,
SpeechAudioUpdateEvent,
SpeechUpdateEvent,
)
from .websockets.audio.transcriptions import (
AsyncWebsocketsAudioTranscriptionsCreateClient,
AsyncWebsocketsAudioTranscriptionsClient,
AsyncWebsocketsAudioTranscriptionsEventHandler,
InputAudioBufferAppendEvent,
InputAudioBufferCommitEvent,
InputAudioBufferCommittedEvent,
InputAudioBufferCompletedEvent,
InputAudioBufferCompleteEvent,
TranscriptionsMessageCompletedEvent,
TranscriptionsMessageUpdateEvent,
TranscriptionsUpdateEvent,
)
from .websockets.chat import (
AsyncWebsocketsChatCreateClient,
AsyncWebsocketsChatClient,
AsyncWebsocketsChatEventHandler,
ConversationAudioDeltaEvent,
ConversationChatCompletedEvent,
Expand Down Expand Up @@ -143,7 +143,7 @@
"Voice",
"AudioFormat",
# audio.transcriptions
"CreateTranslationResp",
"CreateTranscriptionsResp",
# auth
"AsyncDeviceOAuthApp",
"AsyncJWTOAuthApp",
Expand Down Expand Up @@ -217,29 +217,29 @@
"WebsocketsEvent",
# websockets.audio.speech
"InputTextBufferAppendEvent",
"InputTextBufferCommitEvent",
"InputTextBufferCompleteEvent",
"SpeechUpdateEvent",
"InputTextBufferCommittedEvent",
"InputTextBufferCompletedEvent",
"SpeechAudioUpdateEvent",
"SpeechAudioCompletedEvent",
"AsyncWebsocketsAudioSpeechEventHandler",
"AsyncWebsocketsAudioSpeechCreateClient",
"AsyncWebsocketsAudioSpeechClient",
# websockets.audio.transcriptions
"InputAudioBufferAppendEvent",
"InputAudioBufferCommitEvent",
"InputAudioBufferCompleteEvent",
"TranscriptionsUpdateEvent",
"InputAudioBufferCommittedEvent",
"InputAudioBufferCompletedEvent",
"TranscriptionsMessageUpdateEvent",
"TranscriptionsMessageCompletedEvent",
"AsyncWebsocketsAudioTranscriptionsEventHandler",
"AsyncWebsocketsAudioTranscriptionsCreateClient",
"AsyncWebsocketsAudioTranscriptionsClient",
# websockets.chat
"ConversationChatCreatedEvent",
"ConversationMessageDeltaEvent",
"ConversationAudioDeltaEvent",
"ConversationChatCompletedEvent",
"AsyncWebsocketsChatEventHandler",
"AsyncWebsocketsChatCreateClient",
"AsyncWebsocketsChatClient",
# workflows.runs
"WorkflowRunResult",
"WorkflowEventType",
Expand Down
18 changes: 9 additions & 9 deletions cozepy/audio/transcriptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cozepy.util import remove_url_trailing_slash


class CreateTranslationResp(CozeModel):
class CreateTranscriptionsResp(CozeModel):
# The text of translation
text: str

Expand All @@ -23,18 +23,18 @@ def create(
*,
file: FileTypes,
**kwargs,
) -> CreateTranslationResp:
) -> CreateTranscriptionsResp:
"""
create translation
create transcriptions
:param file: The file to be translated.
:return: create translation result
:return: create transcriptions result
"""
url = f"{self._base_url}/v1/audio/transcriptions"
headers: Optional[dict] = kwargs.get("headers")
files = {"file": _try_fix_file(file)}
return self._requester.request(
"post", url, stream=False, cast=CreateTranslationResp, headers=headers, files=files
"post", url, stream=False, cast=CreateTranscriptionsResp, headers=headers, files=files
)


Expand All @@ -53,16 +53,16 @@ async def create(
*,
file: FileTypes,
**kwargs,
) -> CreateTranslationResp:
) -> CreateTranscriptionsResp:
"""
create translation
create transcriptions
:param file: The file to be translated.
:return: create translation result
:return: create transcriptions result
"""
url = f"{self._base_url}/v1/audio/transcriptions"
files = {"file": _try_fix_file(file)}
headers: Optional[dict] = kwargs.get("headers")
return await self._requester.arequest(
"post", url, stream=False, cast=CreateTranslationResp, headers=headers, files=files
"post", url, stream=False, cast=CreateTranscriptionsResp, headers=headers, files=files
)
31 changes: 27 additions & 4 deletions cozepy/websockets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@
from cozepy.request import Requester
from cozepy.util import http_base_url_to_ws, remove_url_trailing_slash

from .audio import AsyncWebsocketsAudioClient
from .chat import AsyncWebsocketsChatClient
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):
Expand All @@ -21,8 +44,8 @@ def audio(self) -> AsyncWebsocketsAudioClient:
)

@property
def chat(self) -> AsyncWebsocketsChatClient:
return AsyncWebsocketsChatClient(
def chat(self) -> AsyncWebsocketsChatBuildClient:
return AsyncWebsocketsChatBuildClient(
base_url=self._base_url,
auth=self._auth,
requester=self._requester,
Expand Down
35 changes: 29 additions & 6 deletions cozepy/websockets/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
from cozepy.auth import Auth
from cozepy.request import Requester

from .speech import AsyncWebsocketsAudioSpeechClient
from .transcriptions import AsyncWebsocketsAudioTranscriptionsClient
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):
Expand All @@ -12,16 +35,16 @@ def __init__(self, base_url: str, auth: Auth, requester: Requester):
self._requester = requester

@property
def transcriptions(self) -> "AsyncWebsocketsAudioTranscriptionsClient":
return AsyncWebsocketsAudioTranscriptionsClient(
def transcriptions(self) -> "AsyncWebsocketsAudioTranscriptionsBuildClient":
return AsyncWebsocketsAudioTranscriptionsBuildClient(
base_url=self._base_url,
auth=self._auth,
requester=self._requester,
)

@property
def speech(self) -> "AsyncWebsocketsAudioSpeechClient":
return AsyncWebsocketsAudioSpeechClient(
def speech(self) -> "AsyncWebsocketsAudioSpeechBuildClient":
return AsyncWebsocketsAudioSpeechBuildClient(
base_url=self._base_url,
auth=self._auth,
requester=self._requester,
Expand Down
Loading

0 comments on commit 880f579

Please sign in to comment.