feat(stage-ui): add Atlas Cloud provider definition (#2076)
--- Co-authored-by: binyangzhu000-sudo <224954946+binyangzhu000-sudo@users.noreply.github.com>
This commit is contained in:
co-authored by
binyangzhu000-sudo
parent
774aed92bb
commit
e5385e90da
@@ -0,0 +1,56 @@
|
||||
import { createOpenAI } from '@xsai-ext/providers/create'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { ProviderValidationCheck } from '../../types'
|
||||
import { createOpenAICompatibleValidators } from '../../validators'
|
||||
import { defineProvider } from '../registry'
|
||||
|
||||
export const ATLASCLOUD_DEFAULT_BASE_URL = 'https://api.atlascloud.ai/v1'
|
||||
|
||||
const atlasCloudConfigSchema = z.object({
|
||||
apiKey: z
|
||||
.string('API Key'),
|
||||
baseUrl: z
|
||||
.string('Base URL')
|
||||
.optional()
|
||||
.default(ATLASCLOUD_DEFAULT_BASE_URL),
|
||||
})
|
||||
|
||||
type AtlasCloudConfig = z.input<typeof atlasCloudConfigSchema>
|
||||
|
||||
export const providerAtlasCloud = defineProvider<AtlasCloudConfig>({
|
||||
id: 'atlascloud',
|
||||
order: 5,
|
||||
name: 'Atlas Cloud',
|
||||
nameLocalize: () => 'Atlas Cloud',
|
||||
description: 'api.atlascloud.ai',
|
||||
descriptionLocalize: () => 'api.atlascloud.ai',
|
||||
tasks: ['chat'],
|
||||
icon: 'i-lobe-icons:openai',
|
||||
|
||||
createProviderConfig: ({ t }) => atlasCloudConfigSchema.extend({
|
||||
apiKey: atlasCloudConfigSchema.shape.apiKey.meta({
|
||||
labelLocalized: t('settings.pages.providers.catalog.edit.config.common.fields.field.api-key.label'),
|
||||
descriptionLocalized: t('settings.pages.providers.catalog.edit.config.common.fields.field.api-key.description'),
|
||||
placeholderLocalized: t('settings.pages.providers.catalog.edit.config.common.fields.field.api-key.placeholder'),
|
||||
type: 'password',
|
||||
}),
|
||||
baseUrl: atlasCloudConfigSchema.shape.baseUrl.meta({
|
||||
labelLocalized: t('settings.pages.providers.catalog.edit.config.common.fields.field.base-url.label'),
|
||||
descriptionLocalized: t('settings.pages.providers.catalog.edit.config.common.fields.field.base-url.description'),
|
||||
placeholderLocalized: t('settings.pages.providers.catalog.edit.config.common.fields.field.base-url.placeholder'),
|
||||
}),
|
||||
}),
|
||||
createProvider(config) {
|
||||
return createOpenAI(config.apiKey, config.baseUrl)
|
||||
},
|
||||
|
||||
validationRequiredWhen(config) {
|
||||
return !!config.apiKey?.trim()
|
||||
},
|
||||
validators: {
|
||||
...createOpenAICompatibleValidators({
|
||||
checks: [ProviderValidationCheck.Connectivity, ProviderValidationCheck.ModelList, ProviderValidationCheck.ChatCompletions],
|
||||
}),
|
||||
},
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import './aihubmix'
|
||||
import './lm-studio'
|
||||
import './azure-openai'
|
||||
import './openai-compatible'
|
||||
import './atlascloud'
|
||||
import './volcengine-coding-plan'
|
||||
import './byteplus'
|
||||
import './byteplus-coding-plan'
|
||||
|
||||
@@ -41,6 +41,7 @@ const providerSourceMetadataById = {
|
||||
'anthropic': paidCloud,
|
||||
'app-local-audio-speech': freeLocal,
|
||||
'app-local-audio-transcription': freeLocal,
|
||||
'atlascloud': paidCloud,
|
||||
'azure-ai-foundry': paidCloud,
|
||||
'azure-openai': paidCloud,
|
||||
'browser-local-audio-speech': freeLocal,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { ATLASCLOUD_DEFAULT_BASE_URL, providerAtlasCloud } from '../libs/providers/providers/atlascloud'
|
||||
import { providerOpenAICompatible } from '../libs/providers/providers/openai-compatible'
|
||||
import { inferenceServiceProvidersService } from './inference-service-providers'
|
||||
|
||||
@@ -23,6 +24,27 @@ describe('services inference-service-providers', () => {
|
||||
expect(provider.validationBypassed).toBe(false)
|
||||
})
|
||||
|
||||
/**
|
||||
* @example
|
||||
* const provider = inferenceServiceProvidersService.buildLocal('atlascloud', { apiKey: '...' })
|
||||
*/
|
||||
it('lists Atlas Cloud as a built-in OpenAI-compatible provider', () => {
|
||||
const definitions = inferenceServiceProvidersService.listDefinitions()
|
||||
const definition = definitions.find(definition => definition.id === providerAtlasCloud.id)
|
||||
const schema = providerAtlasCloud.createProviderConfig({ t: ((key: string) => key) as any })
|
||||
|
||||
expect(definition?.name).toBe('Atlas Cloud')
|
||||
expect(schema.parse({ apiKey: 'test-key' })).toEqual({
|
||||
apiKey: 'test-key',
|
||||
baseUrl: ATLASCLOUD_DEFAULT_BASE_URL,
|
||||
})
|
||||
expect(inferenceServiceProvidersService.buildLocal(providerAtlasCloud.id, { apiKey: 'test-key' })).toEqual(expect.objectContaining({
|
||||
definitionId: providerAtlasCloud.id,
|
||||
name: 'Atlas Cloud',
|
||||
config: { apiKey: 'test-key' },
|
||||
}))
|
||||
})
|
||||
|
||||
/**
|
||||
* @example
|
||||
* expect(() => inferenceServiceProvidersService.buildLocal('missing')).toThrow()
|
||||
|
||||
Reference in New Issue
Block a user