(ctx context.Context, modelRegistry modelRegistry)
| 238 | } |
| 239 | |
| 240 | func (h *Host) RegisterModels(ctx context.Context, modelRegistry modelRegistry) { |
| 241 | if h == nil || modelRegistry == nil { |
| 242 | return |
| 243 | } |
| 244 | |
| 245 | snap := h.Snapshot() |
| 246 | records := h.activeRecordsFromSnapshot(snap) |
| 247 | registrations := make([]modelClientRegistration, 0) |
| 248 | nextClients := make(map[string]struct{}) |
| 249 | nextProviders := make(map[string]string) |
| 250 | nextModelRegistrations := make(map[string]pluginModelRegistration) |
| 251 | for _, record := range records { |
| 252 | modelProvider := record.plugin.Capabilities.ModelProvider |
| 253 | registrar := record.plugin.Capabilities.ModelRegistrar |
| 254 | if modelProvider == nil && registrar == nil { |
| 255 | continue |
| 256 | } |
| 257 | if !executorScopeAllowsStaticModels(record.plugin.Capabilities) { |
| 258 | continue |
| 259 | } |
| 260 | var resp pluginapi.ModelRegistrationResponse |
| 261 | var errRegisterModels error |
| 262 | if modelProvider != nil { |
| 263 | modelResp, errStaticModels := h.callModelProviderStaticModels(ctx, record, modelProvider) |
| 264 | errRegisterModels = errStaticModels |
| 265 | resp = pluginapi.ModelRegistrationResponse{ |
| 266 | Provider: modelResp.Provider, |
| 267 | Models: modelResp.Models, |
| 268 | } |
| 269 | } else { |
| 270 | resp, errRegisterModels = h.callModelRegistrar(ctx, record, registrar) |
| 271 | } |
| 272 | if errRegisterModels != nil { |
| 273 | log.Warnf("pluginhost: model registrar %s failed: %v", record.id, errRegisterModels) |
| 274 | continue |
| 275 | } |
| 276 | |
| 277 | provider := strings.ToLower(strings.TrimSpace(resp.Provider)) |
| 278 | if provider == "" || len(resp.Models) == 0 { |
| 279 | continue |
| 280 | } |
| 281 | |
| 282 | models := make([]*registry.ModelInfo, 0, len(resp.Models)) |
| 283 | for _, item := range resp.Models { |
| 284 | model := pluginModelInfoToRegistryModelInfo(item) |
| 285 | if model == nil || strings.TrimSpace(model.ID) == "" { |
| 286 | continue |
| 287 | } |
| 288 | model.ID = strings.TrimSpace(model.ID) |
| 289 | models = append(models, model) |
| 290 | } |
| 291 | if len(models) == 0 { |
| 292 | continue |
| 293 | } |
| 294 | |
| 295 | nextModelRegistrations[record.id] = pluginModelRegistration{ |
| 296 | pluginID: record.id, |
| 297 | provider: provider, |
nothing calls this directly
no test coverage detected