浏览代码

Remove Latest at API Level

Roy Han 10 月之前
父节点
当前提交
12209bd021
共有 5 个文件被更改,包括 15 次插入12 次删除
  1. 0 2
      api/types.go
  2. 3 3
      cmd/cmd.go
  3. 9 4
      server/routes.go
  4. 2 2
      server/routes_list_test.go
  5. 1 1
      server/routes_test.go

+ 0 - 2
api/types.go

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

+ 3 - 3
cmd/cmd.go

@@ -493,7 +493,7 @@ func ListHandler(cmd *cobra.Command, args []string) error {
 
 
 	for _, m := range models.Models {
 	for _, m := range models.Models {
 		if len(args) == 0 || strings.HasPrefix(m.Name, args[0]) {
 		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
 	var data [][]string
 
 
 	for _, m := range models.Models {
 	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
 			var procStr string
 			switch {
 			switch {
 			case m.SizeVRAM == 0:
 			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)
 				cpuPercent := math.Round(float64(sizeCPU) / float64(m.Size) * 100)
 				procStr = fmt.Sprintf("%d%%/%d%% CPU/GPU", int(cpuPercent), int(100-cpuPercent))
 				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")})
 		}
 		}
 	}
 	}
 
 

+ 9 - 4
server/routes.go

@@ -747,8 +747,7 @@ func (s *Server) ListModelsHandler(c *gin.Context) {
 
 
 		// tag should never be masked
 		// tag should never be masked
 		models = append(models, api.ListModelResponse{
 		models = append(models, api.ListModelResponse{
-			Model:      n.DisplayShortest(),
-			Name:       n.DisplayShortest(),
+			Name:       trimLatest(n.DisplayShortest()),
 			Size:       m.Size(),
 			Size:       m.Size(),
 			Digest:     m.digest,
 			Digest:     m.digest,
 			ModifiedAt: m.fi.ModTime(),
 			ModifiedAt: m.fi.ModTime(),
@@ -1156,8 +1155,7 @@ func (s *Server) ProcessHandler(c *gin.Context) {
 		}
 		}
 
 
 		mr := api.ProcessModelResponse{
 		mr := api.ProcessModelResponse{
-			Model:     model.ShortName,
-			Name:      model.ShortName,
+			Model:     trimLatest(model.ShortName),
 			Size:      int64(v.estimatedTotal),
 			Size:      int64(v.estimatedTotal),
 			SizeVRAM:  int64(v.estimatedVRAM),
 			SizeVRAM:  int64(v.estimatedVRAM),
 			Digest:    model.Digest,
 			Digest:    model.Digest,
@@ -1178,6 +1176,13 @@ func (s *Server) ProcessHandler(c *gin.Context) {
 	c.JSON(http.StatusOK, api.ProcessResponse{Models: models})
 	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
 // 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) {
 func chatPrompt(ctx context.Context, runner *runnerRef, template string, messages []api.Message, numCtx int) (string, error) {
 	encode := func(s string) ([]int, error) {
 	encode := func(s string) ([]int, error) {

+ 2 - 2
server/routes_list_test.go

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

+ 1 - 1
server/routes_test.go

@@ -123,7 +123,7 @@ func Test_Routes(t *testing.T) {
 				require.NoError(t, err)
 				require.NoError(t, err)
 
 
 				assert.Len(t, modelList.Models, 1)
 				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)
 			},
 			},
 		},
 		},
 		{
 		{