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 YiModelLogo from '@renderer/assets/images/models/yi.png'
|
||||||
import YiModelLogoDark from '@renderer/assets/images/models/yi_dark.png'
|
import YiModelLogoDark from '@renderer/assets/images/models/yi_dark.png'
|
||||||
import { Model } from '@renderer/types'
|
import { Model } from '@renderer/types'
|
||||||
|
import OpenAI from 'openai'
|
||||||
|
|
||||||
const TEXT_TO_IMAGE_REGEX = /flux|diffusion|stabilityai|sd-turbo|dall|cogview/i
|
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 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) {
|
export function getModelLogo(modelId: string) {
|
||||||
const isLight = true
|
const isLight = true
|
||||||
@ -665,3 +667,7 @@ export function isEmbeddingModel(model: Model): boolean {
|
|||||||
export function isVisionModel(model: Model): boolean {
|
export function isVisionModel(model: Model): boolean {
|
||||||
return VISION_REGEX.test(model.id)
|
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 { 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 { getAssistantSettings, getDefaultModel, getTopNamingModel } from '@renderer/services/assistant'
|
||||||
import { EVENT_NAMES } from '@renderer/services/event'
|
import { EVENT_NAMES } from '@renderer/services/event'
|
||||||
import { filterContextMessages } from '@renderer/services/messages'
|
import { filterContextMessages } from '@renderer/services/messages'
|
||||||
@ -263,18 +263,29 @@ export default class OpenAIProvider extends BaseProvider {
|
|||||||
|
|
||||||
public async models(): Promise<OpenAI.Models.Model[]> {
|
public async models(): Promise<OpenAI.Models.Model[]> {
|
||||||
try {
|
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') {
|
if (this.provider.id === 'github') {
|
||||||
// @ts-ignore key is not typed
|
// @ts-ignore key is not typed
|
||||||
return response.body.map((model) => ({
|
return response.body
|
||||||
|
.map((model) => ({
|
||||||
id: model.name,
|
id: model.name,
|
||||||
description: model.summary,
|
description: model.summary,
|
||||||
object: 'model',
|
object: 'model',
|
||||||
owned_by: model.publisher
|
owned_by: model.publisher
|
||||||
}))
|
}))
|
||||||
|
.filter(isSupportedModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.sdk.models.list()
|
const models = response?.data || []
|
||||||
return response.data
|
|
||||||
|
return models.filter(isSupportedModel)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user