Skip to content

Commit

Permalink
Refactor methods to use positional-only and keyword args
Browse files Browse the repository at this point in the history
- Updated `create_api_endpoint`, `get_languages`, `get_task_status`, and
  `get_dubbed_run_info` to use positional-only parameters.
- Changed `get_all_voices` and other methods to use keyword-only
  parameters for optional arguments
- Ensured better clarity and parameter handling.
  • Loading branch information
cr2007 committed Jun 29, 2024
1 parent 783a675 commit 72dd23d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cambai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def __init__(self, *, api_key: Optional[str] = None) -> None:
self.session.headers = {"x-api-key": api_key}


def create_api_endpoint(self, endpoint: str) -> str:
def create_api_endpoint(self, /, endpoint: str) -> str:
"""
Constructs a full API endpoint URL by appending the provided endpoint to the base URL.
Expand All @@ -308,7 +308,7 @@ def create_api_endpoint(self, endpoint: str) -> str:


def get_languages(
self, language_type: Literal["source", "target"], write_to_file: bool = False
self, /, language_type: Literal["source", "target"], write_to_file: bool = False
) -> list[LanguageOptionsDict]:
"""
Retrieves a list of languages from the API endpoint based on the type specified.
Expand Down Expand Up @@ -434,7 +434,7 @@ def create_custom_voice(


def get_all_voices(
self, write_to_file: bool = False
self, *, write_to_file: bool = False
) -> list[Optional[VoicesListDict]]:
"""
This method sends a GET request to the API endpoint to retrieve all voices.
Expand Down Expand Up @@ -533,7 +533,7 @@ def start_dubbing(


def get_task_status(
self, task: Literal["tts", "dubbing", "transcription", "translation"], task_id: str
self, /, task: Literal["tts", "dubbing", "transcription", "translation"], task_id: str
) -> TaskStatus:
"""
Retrieves the status of a specific task.
Expand Down Expand Up @@ -586,7 +586,7 @@ def get_task_status(
return response.json()


def get_dubbed_run_info(self, run_id: int) -> DubbedRunInfo:
def get_dubbed_run_info(self, /, run_id: int) -> DubbedRunInfo:
"""
Retrieves the dubbed run information for a specific run ID.
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def create_transcription(


def get_transcription_result(
self, *, run_id: int, save_to_file: bool = False
self, /, run_id: int, *, save_to_file: bool = False
) -> list[TranscriptionResult]:
"""
Retrieves the transcription result for a given run ID and optionally saves it to a file.
Expand Down Expand Up @@ -1066,9 +1066,10 @@ def get_transcription_result(

def transcribe(
self,
*,
/,
audio_file: str,
language: int,
*,
save_to_file: bool = False,
polling_interval: float = 2,
debug: bool = False,
Expand Down Expand Up @@ -1161,11 +1162,12 @@ def transcribe(

def create_translation(
self,
*,
/,
source_language: int,
target_language: int,
text: str,
age: int,
*,
formality: Optional[int] = None,
gender: Optional[Gender] = None,
) -> TaskInfo:
Expand Down

0 comments on commit 72dd23d

Please sign in to comment.