MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / addModel

Method addModel

ai-provider/model-runtime/provider.go:279–309  ·  view source on GitHub ↗
(m IModel, isDefault bool)

Source from the content-addressed store, hash-verified

277}
278
279func (r *ModelRegistry) addModel(m IModel, isDefault bool) {
280 _, exist := r.models.Get(m.ID())
281 r.models.Set(m.ID(), m)
282
283 // get lock
284 shard := r.getShard(m.ID())
285 shard.Lock()
286 defer shard.Unlock()
287
288 if exist {
289 if node, exist := r.reverseMap[m.ID()]; exist {
290 node.model = m
291 }
292 } else {
293 node := &modelNode{
294 model: m,
295 typeKey: m.ModelType(),
296 }
297 if head := r.typeIndex[m.ModelType()]; head != nil {
298 node.next = head
299 head.prev = node
300 }
301 r.typeIndex[m.ModelType()] = node
302 r.reverseMap[m.ID()] = node
303 }
304
305 // default model
306 if isDefault {
307 r.defaultModels.Set(m.ModelType(), m)
308 }
309}
310
311func (r *ModelRegistry) removeModel(id string) {
312 r.models.Del(id)

Callers 2

SetDefaultModelMethod · 0.80
SetModelMethod · 0.80

Calls 5

getShardMethod · 0.95
GetMethod · 0.65
IDMethod · 0.65
SetMethod · 0.65
ModelTypeMethod · 0.65

Tested by

no test coverage detected