AI: Improve model configuration and documentation #5123 #5232 #5322

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-11-24 14:41:13 +01:00
parent 46b3a126f0
commit a02162846b
18 changed files with 614 additions and 84 deletions

View File

@@ -12,9 +12,11 @@ import (
// Authentication header names.
const (
Auth = "Authorization" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
XAuthToken = "X-Auth-Token" //nolint:gosec // header name, not a secret
XSessionID = "X-Session-ID"
Auth = "Authorization" // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
XAuthToken = "X-Auth-Token" //nolint:gosec // header name, not a secret
XSessionID = "X-Session-ID"
OpenAIOrg = "OpenAI-Organization"
OpenAIProject = "OpenAI-Project"
)
// Authentication header values.
@@ -74,6 +76,22 @@ func SetAuthorization(r *http.Request, authToken string) {
}
}
// SetOpenAIOrg adds the organization header expected by the OpenAI API if a
// non-empty value is provided.
func SetOpenAIOrg(r *http.Request, org string) {
if org = strings.TrimSpace(org); org != "" {
r.Header.Add(OpenAIOrg, org)
}
}
// SetOpenAIProject adds the project header expected by the OpenAI API if a
// non-empty value is provided.
func SetOpenAIProject(r *http.Request, project string) {
if project = strings.TrimSpace(project); project != "" {
r.Header.Add(OpenAIProject, project)
}
}
// BasicAuth checks the basic authorization header for credentials and returns them if found.
//
// Note that OAuth 2.0 defines basic authentication differently than RFC 7617, however, this

View File

@@ -64,6 +64,25 @@ func TestAuth(t *testing.T) {
})
}
func TestOpenAIHeaders(t *testing.T) {
t.Run("SetOrg", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/", nil)
SetOpenAIOrg(r, " org-123 ")
assert.Equal(t, "org-123", r.Header.Get(OpenAIOrg))
SetOpenAIOrg(r, "")
assert.Equal(t, "org-123", r.Header.Get(OpenAIOrg))
})
t.Run("SetProject", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/", nil)
SetOpenAIProject(r, "proj-abc")
assert.Equal(t, "proj-abc", r.Header.Get(OpenAIProject))
SetOpenAIProject(r, " ")
assert.Equal(t, "proj-abc", r.Header.Get(OpenAIProject))
})
}
func TestAuthToken(t *testing.T) {
t.Run("None", func(t *testing.T) {
gin.SetMode(gin.TestMode)