utils.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { ValidatedStatus } from '../key-validator/declarations'
  2. import { ProviderEnum } from './declarations'
  3. import { validateModelProvider } from '@/service/common'
  4. export const ConfigurableProviders = [ProviderEnum.azure_openai, ProviderEnum.replicate, ProviderEnum.huggingface_hub, ProviderEnum.xinference, ProviderEnum.openllm]
  5. export const validateModelProviderFn = async (providerName: ProviderEnum, v: any) => {
  6. let body, url
  7. if (ConfigurableProviders.includes(providerName)) {
  8. const { model_name, model_type, ...config } = v
  9. body = {
  10. model_name,
  11. model_type,
  12. config,
  13. }
  14. url = `/workspaces/current/model-providers/${providerName}/models/validate`
  15. }
  16. else {
  17. body = {
  18. config: v,
  19. }
  20. url = `/workspaces/current/model-providers/${providerName}/validate`
  21. }
  22. try {
  23. const res = await validateModelProvider({ url, body })
  24. if (res.result === 'success')
  25. return Promise.resolve({ status: ValidatedStatus.Success })
  26. else
  27. return Promise.resolve({ status: ValidatedStatus.Error, message: res.error })
  28. }
  29. catch (e: any) {
  30. return Promise.resolve({ status: ValidatedStatus.Error, message: e.message })
  31. }
  32. }