Skip to content

Commit 34088db

Browse files
authored
API/CLI context enhancements (ollama#11331)
* API: expose context size of loaded models * CLI: add context UX This adds a column in the ps output to show the models context size.
1 parent 43107b1 commit 34088db

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

api/types.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,14 @@ type ListModelResponse struct {
468468

469469
// ProcessModelResponse is a single model description in [ProcessResponse].
470470
type ProcessModelResponse struct {
471-
Name string `json:"name"`
472-
Model string `json:"model"`
473-
Size int64 `json:"size"`
474-
Digest string `json:"digest"`
475-
Details ModelDetails `json:"details,omitempty"`
476-
ExpiresAt time.Time `json:"expires_at"`
477-
SizeVRAM int64 `json:"size_vram"`
471+
Name string `json:"name"`
472+
Model string `json:"model"`
473+
Size int64 `json:"size"`
474+
Digest string `json:"digest"`
475+
Details ModelDetails `json:"details,omitempty"`
476+
ExpiresAt time.Time `json:"expires_at"`
477+
SizeVRAM int64 `json:"size_vram"`
478+
ContextLength int `json:"context_length"`
478479
}
479480

480481
type TokenResponse struct {

cmd/cmd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,13 @@ func ListRunningHandler(cmd *cobra.Command, args []string) error {
583583
} else {
584584
until = format.HumanTime(m.ExpiresAt, "Never")
585585
}
586-
data = append(data, []string{m.Name, m.Digest[:12], format.HumanBytes(m.Size), procStr, until})
586+
ctxStr := strconv.Itoa(m.ContextLength)
587+
data = append(data, []string{m.Name, m.Digest[:12], format.HumanBytes(m.Size), procStr, ctxStr, until})
587588
}
588589
}
589590

590591
table := tablewriter.NewWriter(os.Stdout)
591-
table.SetHeader([]string{"NAME", "ID", "SIZE", "PROCESSOR", "UNTIL"})
592+
table.SetHeader([]string{"NAME", "ID", "SIZE", "PROCESSOR", "CONTEXT", "UNTIL"})
592593
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
593594
table.SetAlignment(tablewriter.ALIGN_LEFT)
594595
table.SetHeaderLine(false)

server/routes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,9 @@ func (s *Server) PsHandler(c *gin.Context) {
14041404
Details: modelDetails,
14051405
ExpiresAt: v.expiresAt,
14061406
}
1407+
if v.Options != nil {
1408+
mr.ContextLength = v.Options.NumCtx / v.numParallel
1409+
}
14071410
// The scheduler waits to set expiresAt, so if a model is loading it's
14081411
// possible that it will be set to the unix epoch. For those cases, just
14091412
// calculate the time w/ the sessionDuration instead.

0 commit comments

Comments
 (0)