mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 22:52:08 +08:00
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:
parent
bc00c11a00
commit
73fc74d875
@ -100,6 +100,17 @@ export abstract class OpenAIBaseClient<
|
|||||||
override async listModels(): Promise<OpenAI.Models.Model[]> {
|
override async listModels(): Promise<OpenAI.Models.Model[]> {
|
||||||
try {
|
try {
|
||||||
const sdk = await this.getSdkInstance()
|
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') {
|
if (this.provider.id === 'github') {
|
||||||
// GitHub Models 其 models 和 chat completions 两个接口的 baseUrl 不一样
|
// GitHub Models 其 models 和 chat completions 两个接口的 baseUrl 不一样
|
||||||
const baseUrl = 'https://models.github.ai/catalog/'
|
const baseUrl = 'https://models.github.ai/catalog/'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user