Skip to content
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

feat: migrate baidu provider to v2 api #1527

Merged
merged 2 commits into from
Nov 27, 2024
Merged

Conversation

cr7258
Copy link
Collaborator

@cr7258 cr7258 commented Nov 20, 2024

Ⅰ. Describe what this PR did

迁移 baidu api 至 v2 版本,完全兼容 openai 协议格式,处理请求的逻辑更简单。
另外 v2 版本的 bearer token (apiToken) 其实还是有过期时间的,最长时间是 24 小时。 https://cloud.baidu.com/doc/IAM/s/Mm2x80phi
为了处理 apiToken 的刷新问题,新增 TickFuncHandler 接口,provider 如果有定时任务的需求(例如定时刷新 token)可以选择实现该接口。
用户应该在 baiduAccessKeyAndSecret 以 <access-key>:<access-secret> 的格式填写 access key 和 access secret,每隔 1 小时会用这个凭证去刷新 apiToken。

Ⅱ. Does this pull request fix one issue?

fixes #1504

Ⅲ. Why don't you add test cases (unit test/integration test)?

以下是完整的配置示例:

apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
  name: baidu-v2
  namespace: higress-system
spec:
  matchRules:
  - config:
      provider:
        type: baidu
        baiduAccessKeyAndSecret:
          - "<access-key>:<access-secret>"
        baiduApiTokenServiceName: baidubce.dns
        modelMapping:
          "*": "ernie-3.5-8k"
    service:
    - baidu.dns
  url: oci://cr7258/ai-proxy-baidu-v2:21
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
     higress.io/destination: |
      100% baidu.dns
  labels:
    higress.io/resource-definer: higress
  name: test-ai
  namespace: higress-system
spec:
  ingressClassName: higress
  rules:
  - host: test-ai.com
    http:
      paths:
      - backend:
          resource:
            apiGroup: networking.higress.io
            kind: McpBridge
            name: default
        path: /
        pathType: Prefix
---
apiVersion: networking.higress.io/v1
kind: McpBridge
metadata:
  name: default
  namespace: higress-system
spec:
  registries:
  - domain: api.groq.com
    name: groq
    port: 443
    type: dns
    protocol: https
    sni: api.groq.com
  - domain: qianfan.baidubce.com
    name: baidu
    port: 443
    type: dns
    protocol: https
    sni: qianfan.baidubce.com
  - domain: iam.bj.baidubce.com
    name: baidubce
    port: 443
    type: dns
    protocol: https
    sni: iam.bj.baidubce.com

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.51%. Comparing base (ef31e09) to head (d1f534d).
Report is 208 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1527      +/-   ##
==========================================
+ Coverage   35.91%   43.51%   +7.60%     
==========================================
  Files          69       76       +7     
  Lines       11576    12323     +747     
==========================================
+ Hits         4157     5362    +1205     
+ Misses       7104     6625     -479     
- Partials      315      336      +21     

see 69 files with indirect coverage changes

@CH3CHO
Copy link
Collaborator

CH3CHO commented Nov 20, 2024

粗看了一下,这个改动似乎对用户不透明啊。

@cr7258
Copy link
Collaborator Author

cr7258 commented Nov 21, 2024

@CH3CHO 对用户来说是对这个改动基本无感的,迁移到 baidu v2 API 是为了简化内部 baidu provider 的处理逻辑。
另外一个比较主要的改动是定时刷新 apiToken,不管是 v1 和 v2 API 的 token 都是有过期时间的,这个问题不管迁不迁移到 v2 都需要修复。

Copy link
Collaborator

@johnlanni johnlanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johnlanni johnlanni merged commit ee2dd76 into alibaba:main Nov 27, 2024
13 checks passed
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.

AI 代理 Wasm 插件对接百度文心一言切换到 v2 API
4 participants