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

Function NewModel

ai-provider/model-runtime/model.go:91–173  ·  view source on GitHub ↗
(data string, logo string)

Source from the content-addressed store, hash-verified

89}
90
91func NewModel(data string, logo string) (IModel, error) {
92 var cfg entity.AIModel
93 err := yaml.Unmarshal([]byte(data), &cfg)
94 if err != nil {
95 return nil, err
96 }
97 params := make(ParamValidator, 0, len(cfg.ParameterRules))
98 defaultConfig := make(map[string]interface{})
99 for _, p := range cfg.ParameterRules {
100 if (p.Default == nil || p.Default == "" || p.Default == 0 || p.Default == false) && !p.Required {
101 defaultConfig[p.Name] = nil
102 continue
103 }
104 t := p.Type
105 if t == "" {
106 t = ParameterTypeStr
107 }
108 switch t {
109 case ParameterTypeInt:
110 switch t := p.Default.(type) {
111 case int:
112 defaultConfig[p.Name] = t
113 case float64:
114 defaultConfig[p.Name] = int(t)
115 default:
116 defaultConfig[p.Name] = 0
117 }
118 case ParameterTypeStr:
119 switch t := p.Default.(type) {
120 case int:
121 defaultConfig[p.Name] = t
122 case float64:
123 defaultConfig[p.Name] = int(t)
124 case string:
125 defaultConfig[p.Name] = t
126 case bool:
127 defaultConfig[p.Name] = strconv.FormatBool(t)
128 default:
129 defaultConfig[p.Name] = ""
130 }
131 case ParameterTypeFloat:
132 switch t := p.Default.(type) {
133 case int:
134 defaultConfig[p.Name] = float64(t)
135 case float64:
136 defaultConfig[p.Name] = t
137 default:
138 defaultConfig[p.Name] = float64(0)
139 }
140 case ParameterTypeBool:
141 switch t := p.Default.(type) {
142 case bool:
143 defaultConfig[p.Name] = t
144 case string:
145 defaultConfig[p.Name] = t == "true"
146 default:
147 defaultConfig[p.Name] = false
148 }

Callers 1

NewProviderFunction · 0.85

Calls 1

NewConfigFunction · 0.85

Tested by

no test coverage detected