fix: filter unsupported models
This commit is contained in:
parent
a973c5fb89
commit
9d311a7261
@ -94,10 +94,12 @@ import WenxinModelLogoDark from '@renderer/assets/images/models/wenxin_dark.png'
|
||||
import YiModelLogo from '@renderer/assets/images/models/yi.png'
|
||||
import YiModelLogoDark from '@renderer/assets/images/models/yi_dark.png'
|
||||
import { Model } from '@renderer/types'
|
||||
import OpenAI from 'openai'
|
||||
|
||||
const TEXT_TO_IMAGE_REGEX = /flux|diffusion|stabilityai|sd-turbo|dall|cogview/i
|
||||
const VISION_REGEX = /llava|moondream|minicpm|gemini-1.5|claude-3|vision|glm-4v|gpt-4|qwen-vl/i
|
||||
const EMBEDDING_REGEX = /embedding/i
|
||||
const EMBEDDING_REGEX = /embed|rerank/i
|
||||
const NOT_SUPPORTED_REGEX = /embed|tts|rerank|whisper|speech/i
|
||||
|
||||
export function getModelLogo(modelId: string) {
|
||||
const isLight = true
|
||||
@ -665,3 +667,7 @@ export function isEmbeddingModel(model: Model): boolean {
|
||||
export function isVisionModel(model: Model): boolean {
|
||||
return VISION_REGEX.test(model.id)
|
||||
}
|
||||
|
||||
export function isSupportedModel(model: OpenAI.Models.Model): boolean {
|
||||
return !NOT_SUPPORTED_REGEX.test(model.id)
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { isLocalAi } from '@renderer/config/env'
|
||||
import { isVisionModel } from '@renderer/config/models'
|
||||
import { isSupportedModel, isVisionModel } from '@renderer/config/models'
|
||||
import { getAssistantSettings, getDefaultModel, getTopNamingModel } from '@renderer/services/assistant'
|
||||
import { EVENT_NAMES } from '@renderer/services/event'
|
||||
import { filterContextMessages } from '@renderer/services/messages'
|
||||
@ -263,18 +263,29 @@ export default class OpenAIProvider extends BaseProvider {
|
||||
|
||||
public async models(): Promise<OpenAI.Models.Model[]> {
|
||||
try {
|
||||
const query: Record<string, any> = {}
|
||||
|
||||
if (this.provider.id === 'silicon') {
|
||||
query.type = 'text'
|
||||
}
|
||||
|
||||
const response = await this.sdk.models.list({ query })
|
||||
|
||||
if (this.provider.id === 'github') {
|
||||
// @ts-ignore key is not typed
|
||||
return response.body.map((model) => ({
|
||||
return response.body
|
||||
.map((model) => ({
|
||||
id: model.name,
|
||||
description: model.summary,
|
||||
object: 'model',
|
||||
owned_by: model.publisher
|
||||
}))
|
||||
.filter(isSupportedModel)
|
||||
}
|
||||
|
||||
const response = await this.sdk.models.list()
|
||||
return response.data
|
||||
const models = response?.data || []
|
||||
|
||||
return models.filter(isSupportedModel)
|
||||
} catch (error) {
|
||||
return []
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user