Repository navigation
feat(channel): add Baichuan type + fix max_tokens & Azure AI Foundry /openai/v1 #6597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
c386058
a4c4068
30c696c
3f69290
2921aa9
eacc213
c2f5968
1f0c83e
a777034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,176 @@ | ||||||||||||||||||||||||||||
| name: Publish Docker image to GHCR | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # 基于官方 docker-image-branch.yml 改造: | ||||||||||||||||||||||||||||
| # - 登录从 Docker Hub 改为 GitHub Container Registry (GITHUB_TOKEN 自动认证) | ||||||||||||||||||||||||||||
| # - 镜像名从 calciumion/new-api 改为 ghcr.io/${{ github.repository }} | ||||||||||||||||||||||||||||
| # - 触发:推送到 main 分支自动构建(也支持手动 workflow_dispatch) | ||||||||||||||||||||||||||||
| # - 去掉 cosign 签名(fork 自用不需要) | ||||||||||||||||||||||||||||
| # 多架构构建逻辑(单架构 build + manifest 合并)与官方一致。 | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||
| branches: [main] | ||||||||||||||||||||||||||||
| workflow_dispatch: | ||||||||||||||||||||||||||||
| inputs: | ||||||||||||||||||||||||||||
| branch: | ||||||||||||||||||||||||||||
| description: "Branch name to build (默认 main)" | ||||||||||||||||||||||||||||
| required: false | ||||||||||||||||||||||||||||
| default: main | ||||||||||||||||||||||||||||
| type: string | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||
| REGISTRY: ghcr.io | ||||||||||||||||||||||||||||
| IMAGE_NAME: ${{ github.repository }} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||
| prepare: | ||||||||||||||||||||||||||||
| name: Prepare Docker tags | ||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||
| outputs: | ||||||||||||||||||||||||||||
| branch: ${{ steps.version.outputs.branch }} | ||||||||||||||||||||||||||||
| sha: ${{ steps.version.outputs.sha }} | ||||||||||||||||||||||||||||
| tag_prefix: ${{ steps.version.outputs.tag_prefix }} | ||||||||||||||||||||||||||||
| version: ${{ steps.version.outputs.version }} | ||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||
| - name: Check out branch | ||||||||||||||||||||||||||||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||
| fetch-depth: 1 | ||||||||||||||||||||||||||||
| ref: ${{ inputs.branch || github.ref }} | ||||||||||||||||||||||||||||
|
Comment on lines
+37
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Disable persisted checkout credentials.
🧰 Tools🪛 zizmor (1.28.0)[warning] 37-41: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) 📍 Affects 1 file
🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Resolve Docker tags | ||||||||||||||||||||||||||||
| id: version | ||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||
| BRANCH_NAME: ${{ inputs.branch || github.ref_name }} | ||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||
| TAG_PREFIX=$(printf '%s' "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9_.-]+/-/g; s/^[.-]+//; s/[.-]+$//') | ||||||||||||||||||||||||||||
| TAG_PREFIX=${TAG_PREFIX:0:105} | ||||||||||||||||||||||||||||
| TAG_PREFIX=$(printf '%s' "$TAG_PREFIX" | sed -E 's/[.-]+$//') | ||||||||||||||||||||||||||||
| if [ -z "$TAG_PREFIX" ]; then | ||||||||||||||||||||||||||||
| echo "::error::Branch '$BRANCH_NAME' cannot be converted to a valid Docker tag prefix" | ||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| SHA=$(git rev-parse HEAD) | ||||||||||||||||||||||||||||
| SHORT_SHA=$(git rev-parse --short HEAD) | ||||||||||||||||||||||||||||
| VERSION="${TAG_PREFIX}-$(date +'%Y%m%d')-${SHORT_SHA}" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||
| echo "sha=$SHA" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||
| echo "tag_prefix=$TAG_PREFIX" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||
| echo "Prepared Docker tags for $BRANCH_NAME at $SHORT_SHA" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| build_single_arch: | ||||||||||||||||||||||||||||
| name: Build & push (${{ matrix.arch }}) [native] | ||||||||||||||||||||||||||||
| needs: [prepare] | ||||||||||||||||||||||||||||
| strategy: | ||||||||||||||||||||||||||||
| fail-fast: false | ||||||||||||||||||||||||||||
| matrix: | ||||||||||||||||||||||||||||
| include: | ||||||||||||||||||||||||||||
| - arch: amd64 | ||||||||||||||||||||||||||||
| platform: linux/amd64 | ||||||||||||||||||||||||||||
| runner: ubuntu-latest | ||||||||||||||||||||||||||||
| - arch: arm64 | ||||||||||||||||||||||||||||
| platform: linux/arm64 | ||||||||||||||||||||||||||||
| runner: ubuntu-24.04-arm | ||||||||||||||||||||||||||||
| runs-on: ${{ matrix.runner }} | ||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||
| packages: write | ||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||
| - name: Check out branch | ||||||||||||||||||||||||||||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||
| fetch-depth: 1 | ||||||||||||||||||||||||||||
| ref: ${{ needs.prepare.outputs.sha }} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Write VERSION | ||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||
| echo "${{ needs.prepare.outputs.version }}" > VERSION | ||||||||||||||||||||||||||||
| echo "Publishing version: ${{ needs.prepare.outputs.version }} for ${{ matrix.arch }}" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Set up Docker Buildx | ||||||||||||||||||||||||||||
| uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Log in to GHCR | ||||||||||||||||||||||||||||
| uses: docker/login-action@c99871dec2022cc055c062a10cc1a1310835ceb4 # v4.3.0 | ||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||
| registry: ${{ env.REGISTRY }} | ||||||||||||||||||||||||||||
| username: ${{ github.actor }} | ||||||||||||||||||||||||||||
| password: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Extract metadata (labels) | ||||||||||||||||||||||||||||
| id: meta | ||||||||||||||||||||||||||||
| uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 | ||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Build & push single-arch | ||||||||||||||||||||||||||||
| id: build | ||||||||||||||||||||||||||||
| uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 | ||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||
| context: . | ||||||||||||||||||||||||||||
| platforms: ${{ matrix.platform }} | ||||||||||||||||||||||||||||
| push: true | ||||||||||||||||||||||||||||
| tags: | | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }}-${{ matrix.arch }} | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.version }}-${{ matrix.arch }} | ||||||||||||||||||||||||||||
| labels: ${{ steps.meta.outputs.labels }} | ||||||||||||||||||||||||||||
| cache-from: type=gha | ||||||||||||||||||||||||||||
| cache-to: type=gha,mode=max | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Output digest | ||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||
| echo "### Docker Image Digest (${{ matrix.arch }})" >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }}-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.version }}-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo "${{ steps.build.outputs.digest }}" >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| create_manifests: | ||||||||||||||||||||||||||||
| name: Create multi-arch manifests (GHCR) | ||||||||||||||||||||||||||||
| needs: [prepare, build_single_arch] | ||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||
| packages: write | ||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||
| - name: Log in to GHCR | ||||||||||||||||||||||||||||
| uses: docker/login-action@c99871dec2022cc055c062a10cc1a1310835ceb4 # v4.3.0 | ||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||
| registry: ${{ env.REGISTRY }} | ||||||||||||||||||||||||||||
| username: ${{ github.actor }} | ||||||||||||||||||||||||||||
| password: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Create & push manifest (GHCR - branch) | ||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||
| docker buildx imagetools create \ | ||||||||||||||||||||||||||||
| -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }} \ | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }}-amd64 \ | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }}-arm64 | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Create & push manifest (GHCR - versioned) | ||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||
| docker buildx imagetools create \ | ||||||||||||||||||||||||||||
| -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.version }} \ | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.version }}-amd64 \ | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.version }}-arm64 | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Create & push manifest (latest) | ||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||
| docker buildx imagetools create \ | ||||||||||||||||||||||||||||
| -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }}-amd64 \ | ||||||||||||||||||||||||||||
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }}-arm64 | ||||||||||||||||||||||||||||
|
Comment on lines
+162
to
+167
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Publish A manual run can select a non-main branch. This step still overwrites Add a condition that permits this manifest only when Proposed fix - name: Create & push manifest (latest)
+ if: needs.prepare.outputs.branch == 'main'
run: |📝 Committable suggestion
Suggested change
🧰 Tools🪛 zizmor (1.28.0)[warning] 165-165: code injection via template expansion (template-injection): may expand into attacker-controllable code (template-injection) [warning] 166-166: code injection via template expansion (template-injection): may expand into attacker-controllable code (template-injection) [info] 166-166: code injection via template expansion (template-injection): may expand into attacker-controllable code (template-injection) [warning] 167-167: code injection via template expansion (template-injection): may expand into attacker-controllable code (template-injection) [info] 167-167: code injection via template expansion (template-injection): may expand into attacker-controllable code (template-injection) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - name: Output manifest digest | ||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||
| echo "### Multi-arch Manifest Digests" >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.tag_prefix }} >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo "---" >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| echo '```' >> $GITHUB_STEP_SUMMARY | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,6 +348,7 @@ var streamSupportedChannels = map[int]bool{ | |
| constant.ChannelTypeSub2API: true, | ||
| constant.ChannelTypeNewAPI: true, | ||
| constant.ChannelTypeTencent: true, | ||
| constant.ChannelTypeBaichuan: true, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Expect the StreamOptions clearing logic to honor SupportStreamOptions
# or explicitly allow ChannelTypeBaichuan.
rg -n -C 8 \
'request\.StreamOptions = nil|SupportStreamOptions|ChannelTypeBaichuan' \
--glob '*.go' .Repository: QuantumNous/new-api Length of output: 15042 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '== relay_info init/StreamOptions section ==\n'
sed -n '200,245p' relay/common/relay_info.go
printf '\n== streamSupportedChannels section ==\n'
sed -n '330,355p' relay/common/relay_info.go
printf '\n== relay adaptor routing around ChannelTypeBaichuan ==\n'
sed -n '110,150p' relay/relay_adaptor.go
printf '\n== relevant OpenAI adaptor snippets ==\n'
sed -n '60,95p' relay/channel/openai/adaptor.go
sed -n '244,252p' relay/channel/openai/adaptor.go
printf '\n== channel adapter ConvertStreamOpenAIRequest references ==\n'
rg -n -C 5 'ConvertStreamOpenAIRequest|ConvertOpenAIRequest|SupportStreamOptions|StreamOptions' relay/channel --glob '*.go'Repository: QuantumNous/new-api Length of output: 50375 Preserve
Suggested fix in the OpenAI adaptor- if info.ChannelType != constant.ChannelTypeOpenAI && info.ChannelType != constant.ChannelTypeAzure {
+ if !info.SupportStreamOptions &&
+ info.ChannelType != constant.ChannelTypeOpenAI &&
+ info.ChannelType != constant.ChannelTypeAzure {
request.StreamOptions = nil
}🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| } | ||
|
|
||
| func GenRelayInfoWs(c *gin.Context, ws *websocket.Conn) *RelayInfo { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Serialize publications of mutable tags.
Two
mainruns can complete out of order. The older run can then overwrite the newermainandlatestmanifests.Add a workflow-level concurrency group that uses the resolved build branch.
Proposed fix
on: push: branches: [main] workflow_dispatch: inputs: branch: description: "Branch name to build (默认 main)" required: false default: main type: string +concurrency: + group: ghcr-${{ github.repository }}-${{ inputs.branch || github.ref_name }} + cancel-in-progress: true + env:📝 Committable suggestion
🤖 Prompt for AI Agents