Skip to content

ai-proxy中对openai兼容服务 不支持/v1/rerank 接口转发; #2168

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

Open
liseri opened this issue May 6, 2025 · 20 comments · May be fixed by #2205
Open

ai-proxy中对openai兼容服务 不支持/v1/rerank 接口转发; #2168

liseri opened this issue May 6, 2025 · 20 comments · May be fixed by #2205

Comments

@liseri
Copy link
Contributor

liseri commented May 6, 2025

Why do you need it?

openai兼容服务 支持openai兼容的常用接口,但唯独缺一个rerank接口

How could it be?

openai兼容服务支持/v1/rerank/* ai路由转发

Other related information

简单看了一下代码
rerank貌似只支持cohere

Image

@johnlanni
Copy link
Collaborator

cc @pepesi

@pepesi
Copy link
Contributor

pepesi commented May 7, 2025

@liseri openai 似乎没有提供reranker的服务。你有相关文档介绍吗?

@liseri
Copy link
Contributor Author

liseri commented May 7, 2025

@pepesi 还真是, openai 没有标准的rerank接口; 不过业界普遍使用/rerank; 兼容openai形式就是/v1/rerank;
TEI的rank接口见 https://huggingface.github.io/text-embeddings-inference/#/Text%20Embeddings%20Inference/rerank;
gpustack的兼容openai形式的rerank接口见, https://docs.gpustack.ai/latest/api-reference/

Image

现在的决策点就来到了,higress中的openai自定义配置中 ,要不要有rerank接口, 如果要有,是使用openai/v1/rerank呢还是使用cohere/v1/rerank呢, 感觉两者都不太合适, 但前者更合适;

@caolicaoli
Copy link

我说的呢,call了半天全是404,,,有解决方法么?

@johnlanni
Copy link
Collaborator

@liseri openai如果没有rerank接口,在openai这个provider下加这个不是很合适。

目前 ai-proxy 里对于不识别的api是直接透传的,404是因为model-router里没有默认配置这个路径。可以先手动配置下enableOnPathSuffix字段,加上rerank的路径,参考:

https://github.com/alibaba/higress/blob/main/plugins/wasm-cpp/extensions/model_router/README.md

@caolicaoli
Copy link

caolicaoli commented May 7, 2025

@johnlanni
这样的配置是否可行,当我瘦下来还是404?我配置的是全局的

apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
  annotations:
    higress.io/wasm-plugin-description: Implements the functionality of routing based
      on the `model` parameter in the LLM protocol.
    higress.io/wasm-plugin-icon: https://img.alicdn.com/imgextra/i1/O1CN018iKKih1iVx287RltL_!!6000000004419-2-tps-42-42.png
    higress.io/wasm-plugin-title: AI Model Router
  creationTimestamp: "2025-05-07T07:40:18Z"
  labels:
    higress.io/resource-definer: higress
    higress.io/wasm-plugin-built-in: "true"
    higress.io/wasm-plugin-category: ai
    higress.io/wasm-plugin-name: model-router
    higress.io/wasm-plugin-version: 1.0.0
  managedFields:
  - apiVersion: extensions.higress.io/v1alpha1
    fieldsType: FieldsV1
    manager: Kubernetes Java Client
    operation: Update
    time: "2025-05-07T07:40:18Z"
  name: model-router-1.0.0
  namespace: higress-system
spec:
  defaultConfig:
    addProviderHeader: x-higress-llm-provider
    enable: true
    enableOnPathSuffix:
    - '/completions'
    - '/embeddings'
    - '/images/generations'
    - '/audio/speech'
    - '/fine_tuning/jobs'
    - '/moderations'
    - '/rerank'
    modelToHeader: x-higress-llm-model
  defaultConfigDisable: false
  failStrategy: FAIL_OPEN
  phase: AUTHN
  priority: 900
  url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/model-router:1.0.0
status: {}

@liseri
Copy link
Contributor Author

liseri commented May 7, 2025

@liseri openai如果没有rerank接口,在openai这个provider下加这个不是很合适。

目前 ai-proxy 里对于不识别的api是直接透传的,404是因为model-router里没有默认配置这个路径。可以先手动配置下enableOnPathSuffix字段,加上rerank的路径,参考:

https://github.com/alibaba/higress/blob/main/plugins/wasm-cpp/extensions/model_router/README.md

请教下在哪里配置, wasmplugins.model-router.internal配置文件中? 这个文件中我看没有 配 enableOnPathSuffix字段呢

@johnlanni
Copy link
Collaborator

@liseri 是的,要改inner这个,增加 enableOnPathSuffix 配置字段,把所有路径后缀都加上

@caolicaoli
Copy link

caolicaoli commented May 8, 2025

@johnlanni 我配置之后没有自动生成wasmplugins.model-router.internal文件,现在只能搜到一个wasmplugins.model-router-1.0.0,这对么?

wasmplugins.__names__文件中内容:
higress-system/wasmplugins.ai-proxy.internal
higress-system/wasmplugins.ai-statistics-1.0.0
higress-system/wasmplugins.model-mapper-1.0.0
higress-system/wasmplugins.model-mapper.internal
higress-system/wasmplugins.model-router-1.0.0

@CH3CHO
Copy link
Collaborator

CH3CHO commented May 8, 2025

我配置之后没有自动生成wasmplugins.model-router.internal文件,现在只能搜到一个wasmplugins.model-router-1.0.0,这对么?

可以的。

@liseri
Copy link
Contributor Author

liseri commented May 8, 2025

@liseri 是的,要改inner这个,增加 enableOnPathSuffix 配置字段,把所有路径后缀都加上

我都加上了,如下图:

Image

docker-standalone模式重启整个Higress后(不只gateway),rerank路由还是404,可能是我对这个配置的理解有偏差,麻烦帮忙瞅一眼(路由配置细节 在下面截图中有体现):
嵌入调用成功的截图:

Image

rerank失败调用的截图:

Image

@CH3CHO
Copy link
Collaborator

CH3CHO commented May 8, 2025

这个 rewrite 我记得是要 ai-proxy 插件支持的请求才会做的。这里我们是不是可以考虑针对 OpenAI 这个类型的请求,如果发现 path 里有 v1 字样,就按照这个来做 rewrite? @johnlanni 怎么看?

@liseri
Copy link
Contributor Author

liseri commented May 8, 2025

这个 rewrite 我记得是要 ai-proxy 插件支持的请求才会做的。这里我们是不是可以考虑针对 OpenAI 这个类型的请求,如果发现 path 里有 v1 字样,就按照这个来做 rewrite? @johnlanni 怎么看?

个人觉得,内部写死反而搞复杂了,还不如放开让用户可修改(修改思维方式与普通路由rewrite保持一致),提供一个默认推荐值就好;

@CH3CHO
Copy link
Collaborator

CH3CHO commented May 8, 2025

个人觉得,内部写死反而搞复杂了,还不如放开让用户可修改(修改思维方式与普通路由rewrite保持一致),提供一个默认推荐值就好;

因为目前 ai-proxy 支持的就是 openai/v1 的通信协议,识别 /v1 是相对简单的,例如 http://example.com/my/context/path/v1/embedding 转发到后端会自动移除 /my/context/path/v1 这段前缀。

当然插件也可以支持配置一个前缀重写,这个问题不大。

@caolicaoli
Copy link

我发现代码里有rerank,
// TODO: 以下是一些非标准的API名称,需要进一步确认是否支持
ApiNameCohereV1Rerank ApiName = "cohere/v1/rerank"

是不是可以在ai-proxy中改配置的方式映射过去?
capabilities:
"cohere/v1/rerank": "/v1/rerank"

@CH3CHO
Copy link
Collaborator

CH3CHO commented May 8, 2025

ApiNameCohereV1Rerank ApiName = "cohere/v1/rerank"

这个名字不重要的,只是一个内部的的字符串常量,并不会用于请求匹配。

@CH3CHO
Copy link
Collaborator

CH3CHO commented May 8, 2025

是不是可以在ai-proxy中改配置的方式映射过去

这个里核心的问题就如前面 @johnlanni 所说,OpenAI 本身并没有提供 rerank 接口,直接加到 OpenAI 的 provider 里不是很合适。目前相对简单的做法就是加个 rewrite 了。

@liseri
Copy link
Contributor Author

liseri commented May 8, 2025

是不是可以在ai-proxy中改配置的方式映射过去

这个里核心的问题就如前面 @johnlanni 所说,OpenAI 本身并没有提供 rerank 接口,直接加到 OpenAI 的 provider 里不是很合适。目前相对简单的做法就是加个 rewrite 了。

也可以这么想, higress中的openai其实是: 官方openai+兼容性openai, 既然是兼容性 只要该是Openai的与openai一样就行

  1. 当没有配置自定义地址时 只严格按照官方openai的来
  2. 当配置了自定义地址时,走兼容性openai, 这时可以加入业界形成共识的兼容性接口如/v1/rerank等
    如下图:

Image

@johnlanni
Copy link
Collaborator

可以的,你可以提个PR @liseri

@liseri
Copy link
Contributor Author

liseri commented May 9, 2025

可以的,你可以提个PR @liseri

我提了一个PR #2205,但我手动进行测试没有成功
测试方法:
测试环境:higress-standalone docker-compose方式部署, 2.1.2

  1. 重新打包生成ai-proxy-my.wasm
  2. 以文件的形式(file:///opt/plugins/ai-proxy-my.wasm),修改higress-console中ai-proxy插件url
  3. 重启higress, 在gateway日志中观察到了 ai-proxy日志, rerank已经配置上了
2025-05-09T06:13:41.191151Z	debug	envoy wasm external/envoy/source/extensions/common/wasm/context.cc:1392	wasm log: [ai-proxy] [nil] [nil] ai-proxy: openai provider customDomain:172.17.132.30:10100, customPath:/v1, isDirectCustomPath:false, capabilities:map[openai/v1/audiospeech:/v1/audio/speech openai/v1/chatcompletions:/v1/chat/completions openai/v1/completions:/v1/completions openai/v1/embeddings:/v1/embeddings openai/v1/imagegeneration:/v1/images/generations openai/v1/models:/v1/models openai/v1/rerank:/v1/rerank]	thread=39
  1. 然后调用 rerank接口,还是404, 路径没有rewrite成功

Image

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 a pull request may close this issue.

5 participants