fix: add support for OpenRouter embeddings in listModels method (#11774)

* feat: add support for OpenRouter embeddings in listModels method

* fix: broken url

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: format

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
SuYao 2025-12-09 10:29:35 +08:00 committed by GitHub
parent bc00c11a00
commit 73fc74d875
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -100,6 +100,17 @@ export abstract class OpenAIBaseClient<
override async listModels(): Promise<OpenAI.Models.Model[]> {
try {
const sdk = await this.getSdkInstance()
if (this.provider.id === 'openrouter') {
// https://openrouter.ai/docs/api/api-reference/embeddings/list-embeddings-models
const embedBaseUrl = 'https://openrouter.ai/api/v1/embeddings'
const embedSdk = sdk.withOptions({ baseURL: embedBaseUrl })
const modelPromise = sdk.models.list()
const embedModelPromise = embedSdk.models.list()
const [modelResponse, embedModelResponse] = await Promise.all([modelPromise, embedModelPromise])
const models = [...modelResponse.data, ...embedModelResponse.data]
const uniqueModels = Array.from(new Map(models.map((model) => [model.id, model])).values())
return uniqueModels.filter(isSupportedModel)
}
if (this.provider.id === 'github') {
// GitHub Models 其 models 和 chat completions 两个接口的 baseUrl 不一样
const baseUrl = 'https://models.github.ai/catalog/'