fix: make anthropic model provided by cherryin visible to agent (#10695)

This commit is contained in:
defi-failure
2025-10-14 20:59:07 +08:00
committed by GitHub
parent 004d6d8201
commit 7b3b73d390
6 changed files with 37 additions and 13 deletions
+11 -3
View File
@@ -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"
+8 -3
View File
@@ -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 })