()
| 75 | } |
| 76 | |
| 77 | func (i *imlProviderModule) OnInit() { |
| 78 | register.Handle(func(v server.Server) { |
| 79 | ctx := context.Background() |
| 80 | |
| 81 | list, err := i.providerService.List(ctx) |
| 82 | if err != nil { |
| 83 | return |
| 84 | } |
| 85 | // register provider |
| 86 | for _, p := range list { |
| 87 | // get customize models |
| 88 | models, _ := i.providerModelService.Search(ctx, "", map[string]interface{}{"provider": p.Id}, "update_at desc") |
| 89 | iModels := make([]model_runtime.IModel, 0, len(models)) |
| 90 | if models != nil { |
| 91 | for _, model := range models { |
| 92 | // parse access_config & model_parameters |
| 93 | iModel, _ := model_runtime.NewCustomizeModel(model.Id, model.Name, model_runtime.GetCustomizeLogo(), model.AccessConfiguration, model.ModelParameters) |
| 94 | iModels = append(iModels, iModel) |
| 95 | } |
| 96 | } |
| 97 | // default provider |
| 98 | if p.Type == 0 { |
| 99 | runtimeProvider, _ := model_runtime.GetProvider(p.Id) |
| 100 | for _, tmpIModel := range iModels { |
| 101 | tmpIModel.SetLogo(runtimeProvider.Logo()) |
| 102 | if p.DefaultLLM == tmpIModel.ID() { |
| 103 | runtimeProvider.SetDefaultModel(model_runtime.ModelTypeLLM, tmpIModel) |
| 104 | } |
| 105 | runtimeProvider.SetModel(tmpIModel.ID(), tmpIModel) |
| 106 | } |
| 107 | } else { |
| 108 | provider, _ := model_runtime.NewCustomizeProvider(p.Id, p.Name, iModels, p.DefaultLLM, p.Config) |
| 109 | if provider != nil { |
| 110 | model_runtime.Register(p.Id, provider) |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 115 | for _, l := range list { |
| 116 | if l.Priority < 1 { |
| 117 | continue |
| 118 | } |
| 119 | has, err := i.aiBalanceService.Exist(ctx, l.Id, l.DefaultLLM) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | if has { |
| 124 | continue |
| 125 | } |
| 126 | |
| 127 | p, has := model_runtime.GetProvider(l.Id) |
| 128 | if !has { |
| 129 | continue |
| 130 | } |
| 131 | err = i.aiBalanceService.Create(ctx, &ai_balance.Create{ |
| 132 | Id: uuid.NewString(), |
| 133 | Priority: l.Priority, |
| 134 | Provider: l.Id, |
nothing calls this directly
no test coverage detected