Skip to main content

fireplay-translation

公司内部可复用的 Python 翻译路由包。调用方只依赖 Translator 接口;默认实现以 qwen-mt-flash 为主模型,仅在主模型返回 429/RPM 限流时使用 qwen3.8-flash,并短暂熔断主模型,避免限流期间反复发送必然失败的请求。

安装与使用

从公司包仓安装构建后的 wheel,或在源码仓内执行:

uv build
pip install dist/fireplay_translation-0.1.0-py3-none-any.whl
import os

from fireplay_translation import QwenConfig, create_qwen_translator

translator = create_qwen_translator(
    QwenConfig(
        api_key=os.environ["DASHSCOPE_API_KEY"],
        # 推荐换成与 API Key 同地域的 Model Studio 工作空间地址。
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    )
)

result = translator.translate(
    "Hello, world",
    source_language="auto",
    target_language="zh-CN",
)
print(result.text)
print(result.model, result.fallback_used)

路由语义

  • qwen-mt-flash 正常、超时、鉴权错误或服务异常时,错误原样返回,不静默换模型。
  • 只有 429 限流会触发 qwen3.8-flash,因此调用方能区分容量问题和配置/服务故障。
  • 收到 429 后按 max(Retry-After, rate_limit_cooldown_seconds) 暂停主路由,默认 60 秒。
  • Qwen3.8 回退请求关闭 thinking,并要求只返回译文。
  • TranslationResult.fallback_used、model 和 token 字段可用于监控成本与回退率。

扩展其他模型或厂商

实现一个带 model 属性和 translate(TranslationRequest) 方法的 TranslationBackend,再注入 Translator 即可;业务项目无需了解供应商协议:

from fireplay_translation import Translator

translator = Translator(
    MyPrimaryBackend(...),
    rate_limit_fallback=MyFallbackBackend(...),
)

发布前建议依次执行:

uv run pytest
uv build

发布到公司包仓后,业务项目按普通版本依赖安装:

uv add fireplay-translation

Metadata

Release files for fireplay-translation 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fireplay-translation 0.1.0
File Size Uploaded Provenance
fireplay_translation-0.1.0.tar.gz 32.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fireplay-translation 0.1.0
File Interpreter ABI Platform
fireplay_translation-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.7 kB

Release files / fireplay_translation-0.1.0.tar.gz

Download URL fireplay_translation-0.1.0.tar.gz
Size 32.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3394f30ee32343a308abea9088c53f13f0947cd8bbad9533a90fda7165473615
BLAKE2b-256 checksum
How to use checksums
0c19afb7fb17e8539027c16032cda65a1736af618da88c4463850617b23ec6ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / fireplay_translation-0.1.0-py3-none-any.whl

Download URL fireplay_translation-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2044e9d1094501223cf018880c44f820717a67c47760234cb1ceca0a68c3b848
BLAKE2b-256 checksum
How to use checksums
2a39d764580a2f8e08ef3f9d071439fe65084f9adb2461a6ab1e6cb5a7332096
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for fireplay-translation 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page