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
Conversation
…t; fix command line example
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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