fix: make anthropic model provided by cherryin visible to agent (#10695)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
import { ApiModel, ApiModelsFilter, ApiModelsResponse } from '../../../renderer/src/types/apiModels'
|
||||
import { loggerService } from '../../services/LoggerService'
|
||||
import { getAvailableProviders, listAllAvailableModels, transformModelToOpenAI } from '../utils'
|
||||
@@ -8,6 +10,10 @@ const logger = loggerService.withContext('ModelsService')
|
||||
|
||||
export type ModelsFilter = ApiModelsFilter
|
||||
|
||||
const isAnthropicProvider = (provider: { type: string; anthropicApiHost?: string }) => {
|
||||
return provider.type === 'anthropic' || !isEmpty(provider.anthropicApiHost?.trim())
|
||||
}
|
||||
|
||||
export class ModelsService {
|
||||
async getModels(filter: ModelsFilter): Promise<ApiModelsResponse> {
|
||||
try {
|
||||
@@ -16,9 +22,7 @@ export class ModelsService {
|
||||
let providers = await getAvailableProviders()
|
||||
|
||||
if (filter.providerType === 'anthropic') {
|
||||
providers = providers.filter(
|
||||
(p) => p.type === 'anthropic' || (p.anthropicApiHost !== undefined && p.anthropicApiHost.trim() !== '')
|
||||
)
|
||||
providers = providers.filter(isAnthropicProvider)
|
||||
}
|
||||
|
||||
const models = await listAllAvailableModels(providers)
|
||||
@@ -41,6 +45,10 @@ export class ModelsService {
|
||||
continue
|
||||
}
|
||||
|
||||
if (filter.supportAnthropic && model.endpoint_type !== 'anthropic' && !isAnthropicProvider(provider)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const openAIModel = transformModelToOpenAI(model, provider)
|
||||
const fullModelId = openAIModel.id // This is already in format "provider:model_id"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CacheService } from '@main/services/CacheService'
|
||||
import { loggerService } from '@main/services/LoggerService'
|
||||
import { reduxService } from '@main/services/ReduxService'
|
||||
import { ApiModel, Model, Provider } from '@types'
|
||||
import { ApiModel, EndpointType, Model, Provider } from '@types'
|
||||
|
||||
const logger = loggerService.withContext('ApiServerUtils')
|
||||
|
||||
@@ -114,6 +114,7 @@ export async function validateModelId(model: string): Promise<{
|
||||
error?: ModelValidationError
|
||||
provider?: Provider
|
||||
modelId?: string
|
||||
modelEndpointType?: EndpointType
|
||||
}> {
|
||||
try {
|
||||
if (!model || typeof model !== 'string') {
|
||||
@@ -166,7 +167,8 @@ export async function validateModelId(model: string): Promise<{
|
||||
}
|
||||
|
||||
// Check if model exists in provider
|
||||
const modelExists = provider.models?.some((m) => m.id === modelId)
|
||||
const modelInProvider = provider.models?.find((m) => m.id === modelId)
|
||||
const modelExists = !!modelInProvider
|
||||
if (!modelExists) {
|
||||
const availableModels = provider.models?.map((m) => m.id).join(', ') || 'none'
|
||||
return {
|
||||
@@ -179,10 +181,13 @@ export async function validateModelId(model: string): Promise<{
|
||||
}
|
||||
}
|
||||
|
||||
const modelEndpointType = modelInProvider?.endpoint_type
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
provider,
|
||||
modelId
|
||||
modelId,
|
||||
modelEndpointType
|
||||
}
|
||||
} catch (error: any) {
|
||||
logger.error('Error validating model ID', { error, model })
|
||||
|
||||
Reference in New Issue
Block a user