Fix show parameters (#2017)
This commit is contained in:
parent
05d53de7a1
commit
eef50accb4
2 changed files with 41 additions and 20 deletions
|
@ -15,7 +15,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -668,27 +667,12 @@ func GetModelInfo(req api.ShowRequest) (*api.ShowResponse, error) {
|
||||||
cs := 30
|
cs := 30
|
||||||
for k, v := range model.Options {
|
for k, v := range model.Options {
|
||||||
switch val := v.(type) {
|
switch val := v.(type) {
|
||||||
case string:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, val))
|
|
||||||
case int:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, strconv.Itoa(val)))
|
|
||||||
case float64:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, strconv.FormatFloat(val, 'f', 0, 64)))
|
|
||||||
case bool:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, strconv.FormatBool(val)))
|
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
for _, nv := range val {
|
for _, nv := range val {
|
||||||
switch nval := nv.(type) {
|
params = append(params, fmt.Sprintf("%-*s %#v", cs, k, nv))
|
||||||
case string:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, nval))
|
|
||||||
case int:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, strconv.Itoa(nval)))
|
|
||||||
case float64:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, strconv.FormatFloat(nval, 'f', 0, 64)))
|
|
||||||
case bool:
|
|
||||||
params = append(params, fmt.Sprintf("%-*s %s", cs, k, strconv.FormatBool(nval)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
params = append(params, fmt.Sprintf("%-*s %#v", cs, k, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.Parameters = strings.Join(params, "\n")
|
resp.Parameters = strings.Join(params, "\n")
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ func Test_Routes(t *testing.T) {
|
||||||
createTestModel := func(t *testing.T, name string) {
|
createTestModel := func(t *testing.T, name string) {
|
||||||
fname := createTestFile(t, "ollama-model")
|
fname := createTestFile(t, "ollama-model")
|
||||||
|
|
||||||
modelfile := strings.NewReader(fmt.Sprintf("FROM %s", fname))
|
modelfile := strings.NewReader(fmt.Sprintf("FROM %s\nPARAMETER seed 42\nPARAMETER top_p 0.9\nPARAMETER stop foo\nPARAMETER stop bar", fname))
|
||||||
commands, err := parser.Parse(modelfile)
|
commands, err := parser.Parse(modelfile)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
fn := func(resp api.ProgressResponse) {
|
fn := func(resp api.ProgressResponse) {
|
||||||
|
@ -167,6 +168,42 @@ func Test_Routes(t *testing.T) {
|
||||||
assert.Equal(t, "beefsteak:latest", model.ShortName)
|
assert.Equal(t, "beefsteak:latest", model.ShortName)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "Show Model Handler",
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/show",
|
||||||
|
Setup: func(t *testing.T, req *http.Request) {
|
||||||
|
createTestModel(t, "show-model")
|
||||||
|
showReq := api.ShowRequest{Model: "show-model"}
|
||||||
|
jsonData, err := json.Marshal(showReq)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
req.Body = io.NopCloser(bytes.NewReader(jsonData))
|
||||||
|
},
|
||||||
|
Expected: func(t *testing.T, resp *http.Response) {
|
||||||
|
contentType := resp.Header.Get("Content-Type")
|
||||||
|
assert.Equal(t, contentType, "application/json; charset=utf-8")
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
var showResp api.ShowResponse
|
||||||
|
err = json.Unmarshal(body, &showResp)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
var params []string
|
||||||
|
paramsSplit := strings.Split(showResp.Parameters, "\n")
|
||||||
|
for _, p := range paramsSplit {
|
||||||
|
params = append(params, strings.Join(strings.Fields(p), " "))
|
||||||
|
}
|
||||||
|
sort.Strings(params)
|
||||||
|
expectedParams := []string{
|
||||||
|
"seed 42",
|
||||||
|
"stop \"bar\"",
|
||||||
|
"stop \"foo\"",
|
||||||
|
"top_p 0.9",
|
||||||
|
}
|
||||||
|
assert.Equal(t, expectedParams, params)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := setupServer(t)
|
s, err := setupServer(t)
|
||||||
|
|
Loading…
Reference in a new issue