(ctx context.Context, input *ai_dto.NewProvider)
| 201 | } |
| 202 | |
| 203 | func (i *imlProviderModule) AddProvider(ctx context.Context, input *ai_dto.NewProvider) (*ai_dto.SimpleProvider, error) { |
| 204 | _, has := model_runtime.GetProvider(strings.ToLower(input.Name)) |
| 205 | if has { |
| 206 | return nil, fmt.Errorf("provider `%s` duplicate", input.Name) |
| 207 | } |
| 208 | // uuid = name |
| 209 | if has := i.providerService.CheckUuidDuplicate(ctx, input.Name); has { |
| 210 | return nil, fmt.Errorf("provider `%s` duplicate", input.Name) |
| 211 | } |
| 212 | config, defaultLLM := "{\"base_url\": \"\", \"api_key\": \"\"}", "" |
| 213 | if err := i.providerService.Create(ctx, &ai.CreateProvider{ |
| 214 | Id: input.Name, |
| 215 | Name: input.Name, |
| 216 | DefaultLLM: defaultLLM, |
| 217 | Config: config, |
| 218 | Type: 1, |
| 219 | }); err != nil { |
| 220 | return nil, err |
| 221 | } |
| 222 | // register provider |
| 223 | iProvider, _ := model_runtime.NewCustomizeProvider(input.Name, input.Name, []model_runtime.IModel{}, "", "") |
| 224 | model_runtime.Register(input.Name, iProvider) |
| 225 | return &ai_dto.SimpleProvider{ |
| 226 | Id: input.Name, |
| 227 | Name: input.Name, |
| 228 | DefaultConfig: config, |
| 229 | Logo: iProvider.Logo(), |
| 230 | }, nil |
| 231 | } |
| 232 | |
| 233 | func (i *imlProviderModule) SimpleProvider(ctx context.Context, id string) (*ai_dto.SimpleProvider, error) { |
| 234 | p, has := model_runtime.GetProvider(id) |
nothing calls this directly
no test coverage detected