lab
toolkitx.lab
Experimental and laboratory features for ToolkitX.
This subpackage contains experimental tools, research scripts, and other features that are still in the testing or refinement phase.
Classes
Translator
A translator implementation using py-transgpt with disk-based caching. Supports Baidu and Tencent translation engines.
Source code in toolkitx/lab/translator.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
Functions
__init__(engine, cache_path, api_id=None, api_key=None, target_lang='en', source_lang='auto')
Initialize the Translator.
:param engine: The translation engine to use ('baidu' or 'tencent'). :param cache_path: Path to the directory for storing the translation cache. :param api_id: API ID for the translation service. If None, attempts to load from ENV. For Tencent, this is SecretId. :param api_key: API Key for the translation service. If None, attempts to load from ENV. For Tencent, this is SecretKey. :param target_lang: Default target language for translations. :param source_lang: Default source language for translations. :raises ValueError: If the engine is not supported or API credentials are not found.
Source code in toolkitx/lab/translator.py
clear_cache()
close_cache()
translate(text, target_lang=None, source_lang=None)
Translate text using the configured engine and cache.
:param text: The text to translate. :param target_lang: The target language code. Defaults to instance's default_target_lang. :param source_lang: The source language code. Defaults to instance's default_source_lang. :return: The translated text.