(ctx context.Context, teamID string, input *service_dto.CreateService, appId string)
| 350 | }) |
| 351 | } |
| 352 | func (i *imlInitController) createAIService(ctx context.Context, teamID string, input *service_dto.CreateService, appId string) error { |
| 353 | |
| 354 | providerId := "fakegpt" |
| 355 | err := i.providerModule.UpdateProviderConfig(ctx, providerId, &ai_dto.UpdateConfig{ |
| 356 | Config: "{\n \"apikey\": \"xxx\" \n}", |
| 357 | }) |
| 358 | if err != nil { |
| 359 | return fmt.Errorf("update %s config error: %v", providerId, err) |
| 360 | } |
| 361 | input.Provider = &providerId |
| 362 | if input.Id == "" { |
| 363 | input.Id = uuid.New().String() |
| 364 | } |
| 365 | providerInfo, err := i.providerModule.Provider(ctx, *input.Provider) |
| 366 | if err != nil { |
| 367 | return err |
| 368 | } |
| 369 | input.Model = &providerInfo.DefaultLLM |
| 370 | |
| 371 | if input.Prefix == "" { |
| 372 | if len(input.Id) < 9 { |
| 373 | input.Prefix = input.Id |
| 374 | } else { |
| 375 | input.Prefix = input.Id[:8] |
| 376 | } |
| 377 | } |
| 378 | pv, err := i.providerModule.Provider(ctx, *input.Provider) |
| 379 | if err != nil { |
| 380 | return err |
| 381 | } |
| 382 | p, has := model_runtime.GetProvider(*input.Provider) |
| 383 | if !has { |
| 384 | return fmt.Errorf("provider not found") |
| 385 | } |
| 386 | m, has := p.GetModel(pv.DefaultLLM) |
| 387 | if !has { |
| 388 | return fmt.Errorf("model %s not found", pv.DefaultLLM) |
| 389 | } |
| 390 | |
| 391 | var info *service_dto.Service |
| 392 | err = i.transaction.Transaction(ctx, func(txCtx context.Context) error { |
| 393 | var err error |
| 394 | info, err = i.serviceModule.Create(ctx, teamID, input) |
| 395 | if err != nil { |
| 396 | return err |
| 397 | } |
| 398 | path := fmt.Sprintf("/%s/chat/completions", strings.Trim(input.Prefix, "/")) |
| 399 | timeout := 300000 |
| 400 | retry := 0 |
| 401 | aiPrompt := &ai_api_dto.AiPrompt{ |
| 402 | //Variables: []*ai_api_dto.AiPromptVariable{ |
| 403 | // { |
| 404 | // Key: "source_lang", |
| 405 | // Description: "", |
| 406 | // Require: true, |
| 407 | // }, |
| 408 | // { |
| 409 | // Key: "target_lang", |
no test coverage detected