fix(ollama): accept :latest tag on model lookup (#11732)

/api/tags appends :latest to untagged names, but chat and the other
model endpoints looked the tagged name up as-is and 404'd.

Signed-off-by: lei_lei <96427312+leilei3167@users.noreply.github.com>
This commit is contained in:
lei_lei authored and GitHub committed 2026-08-26 08:57:36 +02:00
1 parent 5755898e57
commit f28e8b24e6
3 files changed
+34

No files matched your search

+14
View File
@@ -146,6 +146,20 @@ parameters:
Expect(resp.Details.Format).To(Equal("gguf"))
Expect(resp.Details.Families).ToNot(BeEmpty())
})
It("looks up the model when the Ollama :latest tag is included", func() {
writeConfig("chat", `
name: chat
backend: llama-cpp
template:
chat: "{{ .Input }}"
parameters:
model: Llama-3-8B-Q4_K_M.gguf
`)
resp := callShow("chat:latest")
Expect(resp.Details.Format).To(Equal("gguf"))
Expect(resp.Capabilities).To(ContainElement("completion"))
})
})
Describe("ListModelsEndpoint", func() {
+6
View File
@@ -141,6 +141,12 @@ func (re *RequestExtractor) SetModelAndConfig(initializer func() schema.LocalAIR
}
modelName := input.ModelName(nil)
// Ollama-compat /api/tags appends ":latest" to untagged names.
// Strip it for lookup so the listed name works on /api/chat,
// /v1/chat/completions, and the other model-bearing endpoints.
if strings.HasSuffix(modelName, ":latest") {
modelName = strings.TrimSuffix(modelName, ":latest")
}
cfg, err := re.modelConfigLoader.LoadModelConfigFileByNameDefaultOptions(modelName, re.applicationConfig)
if err != nil {
+14
View File
@@ -82,6 +82,13 @@ var _ = Describe("SetModelAndConfig middleware", func() {
Expect(resp.Error.Message).To(ContainSubstring("not found"))
Expect(resp.Error.Type).To(Equal("invalid_request_error"))
})
It("still 404s when :latest is appended to an unknown model", func() {
rec := postJSON(app, "/v1/chat/completions",
`{"model":"nonexistent-model:latest","messages":[{"role":"user","content":"hi"}]}`)
Expect(rec.Code).To(Equal(http.StatusNotFound))
})
})
Context("when the model exists as a config file", func() {
@@ -97,6 +104,13 @@ var _ = Describe("SetModelAndConfig middleware", func() {
Expect(rec.Code).To(Equal(http.StatusOK))
})
It("accepts the Ollama :latest tag that /api/tags appends", func() {
rec := postJSON(app, "/v1/chat/completions",
`{"model":"test-model:latest","messages":[{"role":"user","content":"hi"}]}`)
Expect(rec.Code).To(Equal(http.StatusOK))
})
})
Context("when the model exists as a pre-loaded config", func() {