API Show Extended
This commit is contained in:
parent
4bf1da4944
commit
ccd624ca44
@ -239,6 +239,7 @@ type ShowResponse struct {
|
||||
System string `json:"system,omitempty"`
|
||||
Details ModelDetails `json:"details,omitempty"`
|
||||
Messages []Message `json:"messages,omitempty"`
|
||||
ModelInfo string `json:"model_info,omitempty"`
|
||||
}
|
||||
|
||||
// CopyRequest is the request passed to [Client.Copy].
|
||||
|
@ -720,9 +720,59 @@ func GetModelInfo(req api.ShowRequest) (*api.ShowResponse, error) {
|
||||
fmt.Fprint(&sb, model.String())
|
||||
resp.Modelfile = sb.String()
|
||||
|
||||
ggmlData, err := getGGMLData(model)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.ModelInfo = string(ggmlData)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func getGGMLData(model *Model) ([]byte, error) {
|
||||
f, err := os.Open(model.ModelPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ggml, _, err := llm.DecodeGGML(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
kv := ggml.KV()
|
||||
var keys []string
|
||||
for k := range kv {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
kvMap := make(map[string]any)
|
||||
|
||||
for _, k := range keys {
|
||||
val := kv[k]
|
||||
|
||||
switch v := val.(type) {
|
||||
case []interface{}:
|
||||
if len(v) > 5 {
|
||||
kvMap[k] = []string{}
|
||||
continue
|
||||
}
|
||||
}
|
||||
kvMap[k] = val
|
||||
}
|
||||
|
||||
ggmlMap := make(map[string]any)
|
||||
ggmlMap["kv"] = kvMap
|
||||
ggmlMap["tensors"] = ggml.Tensors()
|
||||
|
||||
ggmlJson, err := json.Marshal(ggmlMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ggmlJson, nil
|
||||
}
|
||||
|
||||
func (s *Server) ListModelsHandler(c *gin.Context) {
|
||||
ms, err := Manifests()
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user