MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / RegisterModels

Method RegisterModels

internal/pluginhost/adapters.go:240–314  ·  view source on GitHub ↗
(ctx context.Context, modelRegistry modelRegistry)

Source from the content-addressed store, hash-verified

238}
239
240func (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,

Callers

nothing calls this directly

Calls 8

SnapshotMethod · 0.95
callModelRegistrarMethod · 0.95
commitModelClientsMethod · 0.95
cloneRegistryModelsFunction · 0.85

Tested by

no test coverage detected