Remove Latest at API Level

This commit is contained in:
Roy Han 2024-06-12 14:43:17 -07:00
parent be2c5fd71a
commit 12209bd021
5 changed files with 15 additions and 12 deletions

View File

@ -293,7 +293,6 @@ type ProcessResponse struct {
// ListModelResponse is a single model description in [ListResponse].
type ListModelResponse struct {
Name string `json:"name"`
Model string `json:"model"`
ModifiedAt time.Time `json:"modified_at"`
Size int64 `json:"size"`
Digest string `json:"digest"`
@ -302,7 +301,6 @@ type ListModelResponse struct {
// ProcessModelResponse is a single model description in [ProcessResponse].
type ProcessModelResponse struct {
Name string `json:"name"`
Model string `json:"model"`
Size int64 `json:"size"`
Digest string `json:"digest"`

View File

@ -493,7 +493,7 @@ func ListHandler(cmd *cobra.Command, args []string) error {
for _, m := range models.Models {
if len(args) == 0 || strings.HasPrefix(m.Name, args[0]) {
data = append(data, []string{m.Name[:len(m.Name)-7], m.Digest[:12], format.HumanBytes(m.Size), format.HumanTime(m.ModifiedAt, "Never")})
data = append(data, []string{m.Name[:len(m.Name)], m.Digest[:12], format.HumanBytes(m.Size), format.HumanTime(m.ModifiedAt, "Never")})
}
}
@ -525,7 +525,7 @@ func ListRunningHandler(cmd *cobra.Command, args []string) error {
var data [][]string
for _, m := range models.Models {
if len(args) == 0 || strings.HasPrefix(m.Name, args[0]) {
if len(args) == 0 || strings.HasPrefix(m.Model, args[0]) {
var procStr string
switch {
case m.SizeVRAM == 0:
@ -539,7 +539,7 @@ func ListRunningHandler(cmd *cobra.Command, args []string) error {
cpuPercent := math.Round(float64(sizeCPU) / float64(m.Size) * 100)
procStr = fmt.Sprintf("%d%%/%d%% CPU/GPU", int(cpuPercent), int(100-cpuPercent))
}
data = append(data, []string{m.Name, m.Digest[:12], format.HumanBytes(m.Size), procStr, format.HumanTime(m.ExpiresAt, "Never")})
data = append(data, []string{m.Model, m.Digest[:12], format.HumanBytes(m.Size), procStr, format.HumanTime(m.ExpiresAt, "Never")})
}
}

View File

@ -747,8 +747,7 @@ func (s *Server) ListModelsHandler(c *gin.Context) {
// tag should never be masked
models = append(models, api.ListModelResponse{
Model: n.DisplayShortest(),
Name: n.DisplayShortest(),
Name: trimLatest(n.DisplayShortest()),
Size: m.Size(),
Digest: m.digest,
ModifiedAt: m.fi.ModTime(),
@ -1156,8 +1155,7 @@ func (s *Server) ProcessHandler(c *gin.Context) {
}
mr := api.ProcessModelResponse{
Model: model.ShortName,
Name: model.ShortName,
Model: trimLatest(model.ShortName),
Size: int64(v.estimatedTotal),
SizeVRAM: int64(v.estimatedVRAM),
Digest: model.Digest,
@ -1178,6 +1176,13 @@ func (s *Server) ProcessHandler(c *gin.Context) {
c.JSON(http.StatusOK, api.ProcessResponse{Models: models})
}
func trimLatest(s string) string {
if strings.HasSuffix(s, ":latest") {
return s[:len(s)-7]
}
return s
}
// ChatPrompt builds up a prompt from a series of messages for the currently `loaded` model
func chatPrompt(ctx context.Context, runner *runnerRef, template string, messages []api.Message, numCtx int) (string, error) {
encode := func(s string) ([]int, error) {

View File

@ -16,12 +16,12 @@ func TestList(t *testing.T) {
expectNames := []string{
"mistral:7b-instruct-q4_0",
"zephyr:7b-beta-q5_K_M",
"apple/OpenELM:latest",
"apple/OpenELM",
"boreas:2b-code-v1.5-q6_K",
"notus:7b-v1-IQ2_S",
// TODO: host:port currently fails on windows (#4107)
// "localhost:5000/library/eurus:700b-v0.5-iq3_XXS",
"mynamespace/apeliotes:latest",
"mynamespace/apeliotes",
"myhost/mynamespace/lips:code",
}

View File

@ -123,7 +123,7 @@ func Test_Routes(t *testing.T) {
require.NoError(t, err)
assert.Len(t, modelList.Models, 1)
assert.Equal(t, "test-model:latest", modelList.Models[0].Name)
assert.Equal(t, "test-model", modelList.Models[0].Name)
},
},
{