Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👨‍💻 Update 2.0.0 #28

Merged
merged 43 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d976ed1
refactor: Simplify TranslatedObject class and remove license header
DavideGalilei Dec 3, 2024
fbdafeb
refactor: Improve type hints and add docstrings to exceptions and tra…
DavideGalilei Dec 3, 2024
910cdca
refactor: Simplify base translator module by removing license header
DavideGalilei Dec 3, 2024
c1f2a54
refactor: Convert TranslatedObject to dataclass with improved type sa…
DavideGalilei Dec 3, 2024
4c8d65e
refactor: Improve proxy handling and add type hints in translator cla…
DavideGalilei Dec 3, 2024
7375acd
fix: Resolve mypy type hint errors in gpytranslate library
DavideGalilei Dec 3, 2024
ea857df
refactor: Fix type hints and variable references in gpytranslate
DavideGalilei Dec 3, 2024
116bb14
refactor: Update type hints to use typing.Callable for headers parameter
DavideGalilei Dec 3, 2024
9144e4d
style: Format code with consistent trailing commas and quotes
DavideGalilei Dec 3, 2024
6ec5714
fix: Resolve mypy type checking errors in gpytranslate library
DavideGalilei Dec 3, 2024
286aede
refactor: Fix undefined variable names in translation methods
DavideGalilei Dec 3, 2024
5552b97
fix: Resolve mypy type checking errors in gpytranslate module
DavideGalilei Dec 3, 2024
75a7f9b
refactor: Fix undefined variable names in async and sync translators
DavideGalilei Dec 3, 2024
30f04e4
refactor: Simplify imports and user agent header generation
DavideGalilei Dec 3, 2024
b0d4e92
refactor: Add type annotations for generic types in types module
DavideGalilei Dec 3, 2024
8d9498c
refactor: Simplify method signatures and remove unnecessary whitespace
DavideGalilei Dec 3, 2024
fce45b1
refactor: Add type annotations for generic types in base translator
DavideGalilei Dec 3, 2024
0778a34
refactor: Remove license headers from multiple files
DavideGalilei Dec 3, 2024
88ed2a8
feat: Add return type annotations to test and example functions
DavideGalilei Dec 3, 2024
0857a45
refactor: Rename client to http_client and remove redundant import
DavideGalilei Dec 3, 2024
425ad9e
refactor: Add type annotations and type variables to improve type che…
DavideGalilei Dec 3, 2024
625e447
feat: Add typing_extensions import for TypedDict compatibility
DavideGalilei Dec 3, 2024
87e22f6
refactor: Add type annotations to resolve mypy type checking errors
DavideGalilei Dec 3, 2024
ea0d381
refactor: Add type annotations to improve type checking in gpytranslate
DavideGalilei Dec 3, 2024
3622bce
refactor: Add type annotations and fix type checking issues
DavideGalilei Dec 3, 2024
660b6ec
refactor: Add type annotations for Mapping and List in gpytranslate a…
DavideGalilei Dec 3, 2024
15b448a
refactor: Add type annotations to functions in gpytranslate and sync_…
DavideGalilei Dec 3, 2024
2afc6e2
refactor: Add type annotations and improve httpx client configuration
DavideGalilei Dec 3, 2024
997bb60
feat: Add Tuple import to resolve undefined name errors
DavideGalilei Dec 3, 2024
b7dbaab
refactor: Remove TranslatorOptions TypedDict and simplify client options
DavideGalilei Dec 3, 2024
f97f27a
style: Add type annotations for **extra kwargs in translation methods
DavideGalilei Dec 3, 2024
3dca281
fix: Add type annotation for **extra in tts() method
DavideGalilei Dec 3, 2024
99918f2
build: Migrate from hatchling to poetry and update project configuration
DavideGalilei Dec 3, 2024
fd9e231
feat: Add pytest configuration options to pyproject.toml
DavideGalilei Dec 3, 2024
151eb39
docs: Add docstrings and improve code documentation
DavideGalilei Dec 3, 2024
c8ccff8
docs: Add docstrings to test functions for improved code documentation
DavideGalilei Dec 3, 2024
b524038
style: Format code with improved readability and consistent style
DavideGalilei Dec 3, 2024
4f780ed
refactor: Improve code quality with better docstrings, error messages…
DavideGalilei Dec 3, 2024
440305d
refactor: Remove unused imports and clean up type definitions
DavideGalilei Dec 3, 2024
ae12c90
refactor: Improve code quality with docstrings, type hints, and valid…
DavideGalilei Dec 3, 2024
2533ee0
refactor: Fix TTS method signature and documentation in Translator class
DavideGalilei Dec 3, 2024
d9471e0
docs: Add badges, language codes, error handling, and contributing gu…
DavideGalilei Dec 3, 2024
ea14253
👨‍💻 Update 2.0.0
DavideGalilei Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Improve code quality with docstrings, type hints, and valid…
…ation
  • Loading branch information
DavideGalilei committed Dec 3, 2024
commit ae12c90eefb55fc738baaea6707e92a0bb2d92f0
28 changes: 28 additions & 0 deletions gpytranslate/gpytranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ def __init__(
headers: Optional[Union[Dict[str, str], Callable[[], Dict[str, str]]]] = None,
**options: Any,
) -> None:
"""Initialize the translator.

Args:
proxies: Optional proxy configuration dictionary
url: Translation API endpoint URL
tts_url: Text-to-speech API endpoint URL
headers: Custom headers or header generator function
**options: Additional options passed to httpx.AsyncClient
"""
self.url = url
self.tts_url = tts_url
self.proxies = proxies
Expand Down Expand Up @@ -204,6 +213,25 @@ async def tts(
text: Union[str, List[str], Dict[Any, str], Mapping[K, str]],
file: Union[AsyncBufferedIOBase, io.BytesIO],
targetlang: str = "en",
**kwargs: Any,
) -> Union[AsyncBufferedIOBase, io.BytesIO]:
"""Generate text-to-speech audio.

Args:
text: Text to convert to speech
file: Output file or buffer
targetlang: Target language code
**kwargs: Additional TTS parameters

Returns:
The output file/buffer with audio data

Raises:
TranslationError: If TTS generation fails
ValueError: If targetlang is invalid
"""
if not isinstance(targetlang, str) or len(targetlang) != 2:
raise ValueError("targetlang must be a 2-letter language code")
client: str = "at",
idx: int = 0,
prev: str = "input",
Expand Down
14 changes: 14 additions & 0 deletions gpytranslate/types/base_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ def check(
client: str,
dt: str,
) -> Union[TranslatedObject, Dict[K, TranslatedObject], List[TranslatedObject]]:
"""Check and validate translation API response.

Args:
text: Original input text
raw: Raw API response data
client: API client identifier
dt: Response data type

Returns:
Parsed translation result(s)

Raises:
TranslationError: If response validation fails
"""
"""Check and parse API response based on input type.

Args:
Expand Down