mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-17 08:26:54 +08:00
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { ValidatedStatus } from '../key-validator/declarations'
|
|
import { ProviderEnum } from './declarations'
|
|
import { validateModelProvider } from '@/service/common'
|
|
|
|
export const ConfigurableProviders = [ProviderEnum.azure_openai, ProviderEnum.replicate, ProviderEnum.huggingface_hub, ProviderEnum.xinference, ProviderEnum.openllm, ProviderEnum.localai]
|
|
|
|
export const validateModelProviderFn = async (providerName: ProviderEnum, v: any) => {
|
|
let body, url
|
|
|
|
if (ConfigurableProviders.includes(providerName)) {
|
|
const { model_name, model_type, ...config } = v
|
|
body = {
|
|
model_name,
|
|
model_type,
|
|
config,
|
|
}
|
|
url = `/workspaces/current/model-providers/${providerName}/models/validate`
|
|
}
|
|
else {
|
|
body = {
|
|
config: v,
|
|
}
|
|
url = `/workspaces/current/model-providers/${providerName}/validate`
|
|
}
|
|
try {
|
|
const res = await validateModelProvider({ url, body })
|
|
if (res.result === 'success')
|
|
return Promise.resolve({ status: ValidatedStatus.Success })
|
|
else
|
|
return Promise.resolve({ status: ValidatedStatus.Error, message: res.error })
|
|
}
|
|
catch (e: any) {
|
|
return Promise.resolve({ status: ValidatedStatus.Error, message: e.message })
|
|
}
|
|
}
|