validateChannel 通用的渠道校验函数
(channel *model.Channel, isAdd bool)
| 352 | |
| 353 | // validateChannel 通用的渠道校验函数 |
| 354 | func validateChannel(channel *model.Channel, isAdd bool) error { |
| 355 | // 校验 channel settings |
| 356 | if err := channel.ValidateSettings(); err != nil { |
| 357 | return fmt.Errorf("渠道额外设置[channel setting] 格式错误:%s", err.Error()) |
| 358 | } |
| 359 | |
| 360 | // 如果是添加操作,检查 channel 和 key 是否为空 |
| 361 | if isAdd { |
| 362 | if channel == nil || channel.Key == "" { |
| 363 | return fmt.Errorf("channel cannot be empty") |
| 364 | } |
| 365 | |
| 366 | // 检查模型名称长度是否超过 255 |
| 367 | for _, m := range channel.GetModels() { |
| 368 | if len(m) > 255 { |
| 369 | return fmt.Errorf("模型名称过长: %s", m) |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // VertexAI 特殊校验 |
| 375 | if channel.Type == constant.ChannelTypeVertexAi { |
| 376 | if channel.Other == "" { |
| 377 | return fmt.Errorf("部署地区不能为空") |
| 378 | } |
| 379 | |
| 380 | regionMap, err := common.StrToMap(channel.Other) |
| 381 | if err != nil { |
| 382 | return fmt.Errorf("部署地区必须是标准的Json格式,例如{\"default\": \"us-central1\", \"region2\": \"us-east1\"}") |
| 383 | } |
| 384 | |
| 385 | if regionMap["default"] == nil { |
| 386 | return fmt.Errorf("部署地区必须包含default字段") |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | return nil |
| 391 | } |
| 392 | |
| 393 | type AddChannelRequest struct { |
| 394 | Mode string `json:"mode"` |
no test coverage detected