| 163 | } |
| 164 | |
| 165 | func (i *imlLocalModel) pullHook(fn ...func() error) func(msg ai_provider_local.PullMessage) error { |
| 166 | return func(msg ai_provider_local.PullMessage) error { |
| 167 | return i.transaction.Transaction(context.Background(), func(ctx context.Context) error { |
| 168 | |
| 169 | state := ai_local_dto.DeployStateFinish.Int() |
| 170 | modelState := ai_local_dto.LocalModelStateNormal.Int() |
| 171 | if msg.Status == "error" { |
| 172 | state = ai_local_dto.DeployStateDownloadError.Int() |
| 173 | modelState = ai_local_dto.LocalModelStateDeployingError.Int() |
| 174 | } |
| 175 | err := i.localModelService.Save(ctx, msg.Model, &ai_local.EditLocalModel{State: &modelState}) |
| 176 | if err != nil { |
| 177 | return err |
| 178 | } |
| 179 | info, err := i.localModelStateService.Get(ctx, msg.Model) |
| 180 | if err != nil { |
| 181 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 182 | return err |
| 183 | } |
| 184 | |
| 185 | err = i.localModelStateService.Create(ctx, &ai_local.CreateLocalModelInstallState{ |
| 186 | Id: msg.Model, |
| 187 | Complete: msg.Completed, |
| 188 | Total: msg.Total, |
| 189 | State: state, |
| 190 | Msg: msg.Msg, |
| 191 | }) |
| 192 | if err != nil { |
| 193 | return err |
| 194 | } |
| 195 | info, err = i.localModelStateService.Get(ctx, msg.Model) |
| 196 | if err != nil { |
| 197 | return err |
| 198 | } |
| 199 | |
| 200 | } else { |
| 201 | if info.Complete < msg.Completed { |
| 202 | info.Complete = msg.Completed |
| 203 | |
| 204 | } |
| 205 | if info.Total < msg.Total { |
| 206 | info.Total = msg.Total |
| 207 | } |
| 208 | if msg.Msg != "" { |
| 209 | info.Msg = msg.Msg |
| 210 | } |
| 211 | err = i.localModelStateService.Save(ctx, msg.Model, &ai_local.EditLocalModelInstallState{State: &state, Complete: &info.Complete, Total: &info.Total, Msg: &info.Msg}) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | serviceState := 0 |
| 218 | if msg.Status == "error" { |
| 219 | state = 2 |
| 220 | } |
| 221 | list, err := i.localModelCacheService.List(ctx, msg.Model, ai_local.CacheTypeService) |
| 222 | if err != nil { |