Skip to content

allow configuration of OPENAI_API_BASE, and use gpt-4o-mini by default; fix command line example; upgrade code to support upgrade openai library - #281

Open
davideuler wants to merge 22 commits into
nidhaloff:masterfrom
davideuler:master
Open

allow configuration of OPENAI_API_BASE, and use gpt-4o-mini by default; fix command line example; upgrade code to support upgrade openai library#281
davideuler wants to merge 22 commits into
nidhaloff:masterfrom
davideuler:master

Conversation

@davideuler

Copy link
Copy Markdown

1.allow configuration of OPENAI_API_BASE, and use gpt-4o-mini by default;
2.fix command line example;
3.upgrade code to support upgrade openai library

davideuler and others added 22 commits February 3, 2025 09:02
…as optional layer; allow --no-original option to remove original content in pdf, just save the translated content
…state has no key 75180WIDGET_ID-735786182b942ec4a4aca0d5638237df-None. Did you forget to initialize it?
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… retries

- chatgpt: reuse OpenAI client across calls; add system prompt constraining
  output; new translate_batch packs blocks with a delimiter into one request
  and falls back to per-item on mismatch
- openai_compatible: classify errors as retriable vs fatal (RateLimit,
  APIConnection/Timeout, JSONDecode, 5xx are retriable; auth/4xx are not);
  exponential backoff; surface TranslationFailed instead of silently
  returning original text; replace deprecated logging.warn
- translation_cache: new SQLite-backed block-level cache keyed by
  (translator, source, target, model, sha256(text))
- app: translate_blocks consults block cache first, batches misses in one
  API call, writes results back; per-page warning lists failed blocks;
  page-level PDF cache kept as a secondary layer

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- pdf_translator/core.py: extract COLOR_MAP, get_blocks,
  write_translated_block/page shared by app and CLI; OCG-layer
  params support all three rendering modes (no-OCG, keep-original,
  hide-original)
- chatgpt.py: _clean_llm_output strips preambles (Sure/Here is the
  translation/Certainly etc.) iteratively up to 5 layers and removes
  surrounding quote pairs / triple-backticks from LLM responses
- app.py: get_cache_key uses full SHA-256 (64 hex) instead of two
  truncated MD5[:8] segments; remove dead WHITE/rgb_color locals
- translator_cli.py: delegate to pdf_translator.write_translated_page,
  remove duplicate COLOR_MAP; drop from 161 to 116 lines
- pyproject.toml: raise python constraint to ^3.10 to match
  streamlit 1.58 and openai 2.x minimum requirements

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant