mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 02:42:59 +00: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 })
 | |
|   }
 | |
| }
 | 
