add show info command and fix the modelfile
This commit is contained in:
parent
2909dce894
commit
22e93efa41
4 changed files with 59 additions and 17 deletions
|
@ -149,6 +149,11 @@ type DeleteRequest struct {
|
||||||
|
|
||||||
type ShowRequest struct {
|
type ShowRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Model string `json:"model"`
|
||||||
|
System string `json:"system"`
|
||||||
|
Template string `json:"template"`
|
||||||
|
|
||||||
|
Options map[string]interface{} `json:"options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShowResponse struct {
|
type ShowResponse struct {
|
||||||
|
|
|
@ -149,7 +149,7 @@ func RunHandler(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
// check if the model exists on the server
|
// check if the model exists on the server
|
||||||
_, err = client.Show(cmd.Context(), &api.ShowRequest{Name: name})
|
_, err = client.Show(cmd.Context(), &api.ShowRequest{Model: name})
|
||||||
var statusError api.StatusError
|
var statusError api.StatusError
|
||||||
switch {
|
switch {
|
||||||
case errors.As(err, &statusError) && statusError.StatusCode == http.StatusNotFound:
|
case errors.As(err, &statusError) && statusError.StatusCode == http.StatusNotFound:
|
||||||
|
@ -322,7 +322,7 @@ func ShowHandler(cmd *cobra.Command, args []string) error {
|
||||||
return errors.New("one of '--license', '--modelfile', '--parameters', '--system', or '--template' must be specified")
|
return errors.New("one of '--license', '--modelfile', '--parameters', '--system', or '--template' must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
req := api.ShowRequest{Name: args[0]}
|
req := api.ShowRequest{Model: args[0]}
|
||||||
resp, err := client.Show(cmd.Context(), &req)
|
resp, err := client.Show(cmd.Context(), &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -34,7 +34,7 @@ func modelIsMultiModal(cmd *cobra.Command, name string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
req := api.ShowRequest{Name: name}
|
req := api.ShowRequest{Model: name}
|
||||||
resp, err := client.Show(cmd.Context(), &req)
|
resp, err := client.Show(cmd.Context(), &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
@ -101,6 +101,7 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error {
|
||||||
|
|
||||||
usageShow := func() {
|
usageShow := func() {
|
||||||
fmt.Fprintln(os.Stderr, "Available Commands:")
|
fmt.Fprintln(os.Stderr, "Available Commands:")
|
||||||
|
fmt.Fprintln(os.Stderr, " /show info Show details for this model")
|
||||||
fmt.Fprintln(os.Stderr, " /show license Show model license")
|
fmt.Fprintln(os.Stderr, " /show license Show model license")
|
||||||
fmt.Fprintln(os.Stderr, " /show modelfile Show Modelfile for this model")
|
fmt.Fprintln(os.Stderr, " /show modelfile Show Modelfile for this model")
|
||||||
fmt.Fprintln(os.Stderr, " /show parameters Show parameters for this model")
|
fmt.Fprintln(os.Stderr, " /show parameters Show parameters for this model")
|
||||||
|
@ -291,13 +292,29 @@ func generateInteractive(cmd *cobra.Command, opts generateOptions) error {
|
||||||
fmt.Println("error: couldn't connect to ollama server")
|
fmt.Println("error: couldn't connect to ollama server")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
resp, err := client.Show(cmd.Context(), &api.ShowRequest{Name: opts.Model})
|
req := &api.ShowRequest{
|
||||||
|
Model: opts.Model,
|
||||||
|
System: opts.System,
|
||||||
|
Template: opts.Template,
|
||||||
|
Options: opts.Options,
|
||||||
|
}
|
||||||
|
resp, err := client.Show(cmd.Context(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error: couldn't get model")
|
fmt.Println("error: couldn't get model")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch args[1] {
|
switch args[1] {
|
||||||
|
case "info":
|
||||||
|
fmt.Println("Model details:")
|
||||||
|
if len(resp.Details.Families) > 0 {
|
||||||
|
fmt.Printf("Family %s\n", strings.Join(resp.Details.Families, ", "))
|
||||||
|
} else if resp.Details.Family != "" {
|
||||||
|
fmt.Printf("Family %s\n", resp.Details.Family)
|
||||||
|
}
|
||||||
|
fmt.Printf("Parameter Size %s\n", resp.Details.ParameterSize)
|
||||||
|
fmt.Printf("Quantization Level %s\n", resp.Details.QuantizationLevel)
|
||||||
|
fmt.Println("")
|
||||||
case "license":
|
case "license":
|
||||||
if resp.License == "" {
|
if resp.License == "" {
|
||||||
fmt.Print("No license was specified for this model.\n\n")
|
fmt.Print("No license was specified for this model.\n\n")
|
||||||
|
|
|
@ -610,12 +610,18 @@ func ShowModelHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Name == "" {
|
switch {
|
||||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"})
|
case req.Model == "" && req.Name == "":
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"})
|
||||||
return
|
return
|
||||||
|
case req.Model != "" && req.Name != "":
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "both model and name are set"})
|
||||||
|
return
|
||||||
|
case req.Model == "" && req.Name != "":
|
||||||
|
req.Model = req.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := GetModelInfo(req.Name)
|
resp, err := GetModelInfo(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Name)})
|
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Name)})
|
||||||
|
@ -628,8 +634,8 @@ func ShowModelHandler(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetModelInfo(name string) (*api.ShowResponse, error) {
|
func GetModelInfo(req api.ShowRequest) (*api.ShowResponse, error) {
|
||||||
model, err := GetModel(name)
|
model, err := GetModel(req.Model)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -642,6 +648,14 @@ func GetModelInfo(name string) (*api.ShowResponse, error) {
|
||||||
QuantizationLevel: model.Config.FileType,
|
QuantizationLevel: model.Config.FileType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.System != "" {
|
||||||
|
model.System = req.System
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Template != "" {
|
||||||
|
model.Template = req.Template
|
||||||
|
}
|
||||||
|
|
||||||
resp := &api.ShowResponse{
|
resp := &api.ShowResponse{
|
||||||
License: strings.Join(model.License, "\n"),
|
License: strings.Join(model.License, "\n"),
|
||||||
System: model.System,
|
System: model.System,
|
||||||
|
@ -649,13 +663,6 @@ func GetModelInfo(name string) (*api.ShowResponse, error) {
|
||||||
Details: modelDetails,
|
Details: modelDetails,
|
||||||
}
|
}
|
||||||
|
|
||||||
mf, err := ShowModelfile(model)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Modelfile = mf
|
|
||||||
|
|
||||||
var params []string
|
var params []string
|
||||||
cs := 30
|
cs := 30
|
||||||
for k, v := range model.Options {
|
for k, v := range model.Options {
|
||||||
|
@ -685,6 +692,19 @@ func GetModelInfo(name string) (*api.ShowResponse, error) {
|
||||||
}
|
}
|
||||||
resp.Parameters = strings.Join(params, "\n")
|
resp.Parameters = strings.Join(params, "\n")
|
||||||
|
|
||||||
|
for k, v := range req.Options {
|
||||||
|
if _, ok := req.Options[k]; ok {
|
||||||
|
model.Options[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mf, err := ShowModelfile(model)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Modelfile = mf
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue