[PR #10147] [CLOSED] Fix OpenAI model retrieval for models with slashes #39031

Closed
opened 2026-04-22 23:40:37 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/10147
Author: @SplittyDev
Created: 4/6/2025
Status: Closed

Base: mainHead: fix/openai-api-model-retrieval


📝 Commits (3)

  • cce5609 Use raw path in OpenAI api
  • b56d728 Add test case for model retrieval with slashes
  • c50aa8f Merge branch 'main' into fix/openai-api-model-retrieval

📊 Changes

2 files changed (+30 additions, -6 deletions)

View changed files

📝 openai/openai_test.go (+29 -6)
📝 server/routes.go (+1 -0)

📄 Description

As described in #10139, there is a bug - or at the very least unintended behavior - in the current implementation of the model retrieval endpoint of the OpenAI-compatible API.

It's not possible to retrieve models with slashes in their name, because gin handles slashes as part of the route, even when escaped as %2F. This PR fixes that by setting UseRawPath = true, which correctly handles escaped slashes as part of path parameters.

I've also added a test-case to make sure this doesn't break again. As far as I can tell, there are no unintended consequences of using UseRawPath on the router, but I'm neither a Go developer, nor have I ever used Gin, so it would be great if someone could double-check that.


Here's what the Go docs say about url.RawPath:

Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/. A consequence is that it is impossible to tell which slashes in the Path were slashes in the raw URL and which were %2f. This distinction is rarely important, but when it is, the code should use the URL.EscapedPath method, which preserves the original encoding of Path.

The RawPath field is an optional field which is only set when the default encoding of Path is different from the escaped path. See the EscapedPath method for more details.

Gin seems to handle this correctly, only using RawPath if engine.UseRawPath is true and url.RawPath is set:

8763f33c65/gin.go (L652)

if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 {
    rPath = c.Request.URL.RawPath
}

Fixes #10139


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/10147 **Author:** [@SplittyDev](https://github.com/SplittyDev) **Created:** 4/6/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/openai-api-model-retrieval` --- ### 📝 Commits (3) - [`cce5609`](https://github.com/ollama/ollama/commit/cce5609dbdca974687b76e9df354270f2fdd2a7c) Use raw path in OpenAI api - [`b56d728`](https://github.com/ollama/ollama/commit/b56d728dacdf6c7c5a184d37604ece9af64a4dab) Add test case for model retrieval with slashes - [`c50aa8f`](https://github.com/ollama/ollama/commit/c50aa8fb33a0acd98a039d8958270ee66db562af) Merge branch 'main' into fix/openai-api-model-retrieval ### 📊 Changes **2 files changed** (+30 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `openai/openai_test.go` (+29 -6) 📝 `server/routes.go` (+1 -0) </details> ### 📄 Description As described in #10139, there is a bug - or at the very least unintended behavior - in the current implementation of the model retrieval endpoint of the OpenAI-compatible API. It's not possible to retrieve models with slashes in their name, because gin handles slashes as part of the route, even when escaped as `%2F`. This PR fixes that by setting `UseRawPath = true`, which correctly handles escaped slashes as part of path parameters. I've also added a test-case to make sure this doesn't break again. As far as I can tell, there are no unintended consequences of using `UseRawPath` on the router, but I'm neither a Go developer, nor have I ever used Gin, so it would be great if someone could double-check that. --- Here's what the Go docs say about `url.RawPath`: > Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/. A consequence is that it is impossible to tell which slashes in the Path were slashes in the raw URL and which were %2f. This distinction is rarely important, but when it is, the code should use the [URL.EscapedPath](https://pkg.go.dev/net/url#URL.EscapedPath) method, which preserves the original encoding of Path.<br> > The RawPath field is an optional field which is only set when the default encoding of Path is different from the escaped path. See the EscapedPath method for more details. Gin seems to handle this correctly, only using `RawPath` if `engine.UseRawPath` is `true` _and_ `url.RawPath` is set: > https://github.com/gin-gonic/gin/blob/8763f33c65f7df8be5b9fe7504ab7fcf20abb41d/gin.go#L652 > > ```go > if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 { > rPath = c.Request.URL.RawPath > } > ``` --- Fixes #10139 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-22 23:40:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#39031