Skip to content

[ai-proxy] 文生图接口 Fallback 后无法正确 mapping 到目标模型 #2338

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

Closed
daixijun opened this issue May 28, 2025 · 2 comments · Fixed by #2341
Closed

[ai-proxy] 文生图接口 Fallback 后无法正确 mapping 到目标模型 #2338

daixijun opened this issue May 28, 2025 · 2 comments · Fixed by #2341
Labels
help wanted Extra attention is needed level/easy

Comments

@daixijun
Copy link
Contributor

我有个场景,当 openai 服务异常时会回退到 gemini

对话接口是可以正常 fallback 并 mapping 到目标 model

Image

但是生图接口还是把原 model 传给了 fallback 后的 gemini

Image

EnvoyFilter 如下

---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  labels:
    higress.io/internal: "true"
    higress.io/resource-definer: higress
  name: ai-route-openai-fallback.internal
  namespace: higress-system
spec:
  configPatches:
  - applyTo: HTTP_ROUTE
    match:
      context: GATEWAY
      routeConfiguration:
        vhost:
          route:
            name: ai-route-openai.internal
    patch:
      operation: MERGE
      value:
        typed_per_filter_config:
          envoy.filters.http.custom_response:
            '@type': type.googleapis.com/udpa.type.v1.TypedStruct
            type_url: type.googleapis.com/envoy.extensions.filters.http.custom_response.v3.CustomResponse
            value:
              custom_response_matcher:
                matcher_list:
                  matchers:
                  - on_match:
                      action:
                        name: action
                        typed_config:
                          '@type': type.googleapis.com/udpa.type.v1.TypedStruct
                          type_url: type.googleapis.com/envoy.extensions.http.custom_response.redirect_policy.v3.RedirectPolicy
                          value:
                            keep_original_response_code: false
                            max_internal_redirects: 10
                            only_redirect_upstream_code: false
                            request_headers_to_add:
                            - append: false
                              header:
                                key: x-higress-fallback-from
                                value: ai-route-openai.internal
                            response_headers_to_add:
                            - append: false
                              header:
                                key: x-higress-fallback-from
                                value: ai-route-openai.internal
                            use_original_request_body: true
                            use_original_request_uri: true
                    predicate:
                      or_matcher:
                        predicate:
                        - single_predicate:
                            input:
                              name: 4xx_response
                              typed_config:
                                '@type': type.googleapis.com/envoy.type.matcher.v3.HttpResponseStatusCodeClassMatchInput
                            value_match:
                              exact: 4xx
                        - single_predicate:
                            input:
                              name: 5xx_response
                              typed_config:
                                '@type': type.googleapis.com/envoy.type.matcher.v3.HttpResponseStatusCodeClassMatchInput
                            value_match:
                              exact: 5xx

AI Proxy 插件配置

---
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
  annotations:
    higress.io/wasm-plugin-title: AI Proxy
    higress.io/wasm-plugin-icon: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png
    higress.io/wasm-plugin-description: Provide unified OpenAI API compatible interface to call different AI service providers.
  labels:
    higress.io/resource-definer: higress
    higress.io/wasm-plugin-built-in: "true"
    higress.io/wasm-plugin-category: ai
    higress.io/wasm-plugin-name: ai-proxy
    higress.io/wasm-plugin-version: 1.0.0
  name: ai-proxy.internal
  namespace: higress-system
spec:
  defaultConfig:
    providers:
    - id: gemini
      type: openai
      apiTokens:
      - "APIKEY"
      openaiCustomUrl: generativelanguage.googleapis.com/v1beta/openai/
      modelMapping:
        gpt-image-1: imagen-3.0-generate-002
        chatgpt*: gemini-2.5-flash-preview-05-20
        gpt*: gemini-2.5-flash-preview-05-20
        dall*: imagen-3.0-generate-002
        o*: gemini-2.5-pro-preview-05-06
@johnlanni
Copy link
Collaborator

johnlanni commented May 29, 2025

应该不止fallback时model mapping不生效吧,没有fallback时 mapping应该也不生效?


It should be more than just the model mapping when fallingback is not effective, but the mapping should not take effect when fallingback is not available?

@johnlanni
Copy link
Collaborator

johnlanni commented May 29, 2025

if apiName != ApiNameChatCompletion {
// We don't need to process the request body for other APIs.
return types.ActionContinue, nil
}
return m.config.handleRequestBody(m, m.contextCache, ctx, apiName, body)

目前接口类型非completions时,没有读取请求body,可以增加下文生图的接口类型


if apiName != ApiNameChatCompletion {
// We don't need to process the request body for other APIs.
return types.ActionContinue, nil
}
return m.config.handleRequestBody(m, m.contextCache, ctx, apiName, body)

When the interface type is not completes, the request body is not read. You can add the interface type of the following raw graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed level/easy
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants