diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index f8beac13a..a3c06689c 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -57,7 +57,7 @@ jobs: is_release: ${{ steps.check-version.outputs.tag }} version: ${{ steps.check-version.outputs.tag && steps.get-release-version.outputs.version || steps.get-dev-version.outputs.version }} steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: true fetch-depth: 2 @@ -107,7 +107,7 @@ jobs: run: "uv build" - name: Store the distribution packages - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7 with: name: python-package-distributions path: dist/ @@ -127,7 +127,7 @@ jobs: id-token: write steps: - name: Download all the dists - uses: actions/download-artifact@v8 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: name: python-package-distributions path: dist/ @@ -149,7 +149,7 @@ jobs: id-token: write steps: - name: Download all the dists - uses: actions/download-artifact@v8 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: name: python-package-distributions path: dist/ @@ -191,7 +191,7 @@ jobs: echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Setup uv with Python 3.12 uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2 @@ -209,7 +209,7 @@ jobs: - name: Docker meta id: meta - uses: docker/metadata-action@v6 + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6 with: images: | ${{ env.DOCKERHUB_REPO }} @@ -220,25 +220,25 @@ jobs: type=raw,value=latest,enable=${{ needs.build.outputs.is_release != '' }} - name: Login to Docker.io - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4 with: registry: docker.io username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4 - name: Build and push by digest id: build - uses: docker/build-push-action@v6 + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 with: platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} @@ -253,7 +253,7 @@ jobs: touch "${{ runner.temp }}/digests/${digest#sha256:}" - name: Upload digest - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7 with: name: digests-${{ env.PLATFORM_PAIR }} path: ${{ runner.temp }}/digests/* @@ -281,18 +281,18 @@ jobs: echo "GHCR_REPO_LOWER=$(echo ${{ env.GHCR_REPO }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - name: Download digests - uses: actions/download-artifact@v8 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: path: ${{ runner.temp }}/digests pattern: digests-* merge-multiple: true - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4 - name: Docker meta id: meta - uses: docker/metadata-action@v6 + uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6 with: images: | ${{ env.DOCKERHUB_REPO }} @@ -303,14 +303,14 @@ jobs: type=raw,value=latest,enable=${{ needs.build.outputs.is_release != '' && 'true' || 'false' }} - name: Login to Docker.io - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4 with: registry: docker.io username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GHCR - uses: docker/login-action@v4 + uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4 with: registry: ghcr.io username: ${{ github.repository_owner }} @@ -337,7 +337,7 @@ jobs: if: needs.check-repository.outputs.is_main_repo == 'true' && needs.check-repository.outputs.is_doc_only != 'true' steps: - name: checkout babeldoc metadata - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: repository: funstory-ai/BabelDOC path: babeldoctemp1234567 @@ -345,12 +345,12 @@ jobs: sparse-checkout: babeldoc/assets/embedding_assets_metadata.py - name: Cached Assets id: cache-assets - uses: actions/cache@v5 + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 with: path: ~/.cache/babeldoc key: test-1-babeldoc-assets-${{ hashFiles('babeldoctemp1234567/babeldoc/assets/embedding_assets_metadata.py') }} - name: 检出代码 - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Setup uv with Python ${{ env.WIN_EXE_PYTHON_VERSION }} uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2 @@ -369,7 +369,7 @@ jobs: -GenerateOfflineAssets - name: Upload build with offline assets artifact - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7 with: name: win64-exe-with-assets path: ./build @@ -386,10 +386,10 @@ jobs: timeout-minutes: 20 steps: - name: 检出代码 - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Download build artifact - uses: actions/download-artifact@v8 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: name: win64-exe-with-assets path: ./build @@ -424,7 +424,7 @@ jobs: ./build/pdf2zh.exe ./test/file/translate.cli.plain.text.pdf -o ./test/file/offline_result - name: Upload test results - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7 with: name: test-results path: ./test/file/ @@ -453,7 +453,7 @@ jobs: outputs: tag_name: ${{ steps.release-drafter.outputs.tag_name }} steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: true fetch-depth: 2 @@ -477,10 +477,10 @@ jobs: needs.release-draft.result == 'success' steps: - name: 检出代码 - uses: actions/checkout@v6 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Download build artifact - uses: actions/download-artifact@v8 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: name: win64-exe-with-assets path: ./build diff --git a/README.md b/README.md index 05fd7bbd0..94e4e2969 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ English | [简体中文](docs/README_zh-CN.md) | [繁體中文](docs/README_zh-T

-Byaidu%2FPDFMathTranslate | Trendshift +PDFMathTranslate%2FPDFMathTranslate | Trendshift diff --git a/pdf2zh/translator.py b/pdf2zh/translator.py index 0b09ef273..f5daa2db8 100644 --- a/pdf2zh/translator.py +++ b/pdf2zh/translator.py @@ -439,17 +439,19 @@ def __init__( ) self.options = { "temperature": 0, # 随机采样可能会打断公式标记 - "stop": stop_tokens, - "max_tokens": max_tokens if max_tokens > 0 else None, } + if stop_tokens: + self.options["stop"] = stop_tokens + if max_tokens > 0: + self.options["max_tokens"] = max_tokens self.client = openai.OpenAI( base_url=base_url or self.envs["OPENAI_BASE_URL"], api_key=api_key or self.envs["OPENAI_API_KEY"], ) self.prompttext = prompt self.add_cache_impact_parameters("temperature", self.options["temperature"]) - self.add_cache_impact_parameters("stop", self.options["stop"]) - self.add_cache_impact_parameters("max_tokens", self.options["max_tokens"]) + self.add_cache_impact_parameters("stop", self.options.get("stop")) + self.add_cache_impact_parameters("max_tokens", self.options.get("max_tokens")) self.add_cache_impact_parameters("prompt", self.prompt("", self.prompttext)) think_filter_regex = r"^.+?\n*(|\n)*()\n*" self.add_cache_impact_parameters("think_filter_regex", think_filter_regex)