From 8294676150dde3dd3d316644b86e42b07204ff9c Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Fri, 14 Mar 2025 18:33:07 -0700 Subject: [PATCH] server/internal/client/ollama: set User-Agent for registry client (#9775) This sets the agent header in DefaultRegistry to include the version of the client, OS, and architecture in the previous format, with a minor twist. Note: The version is obtained from the build info, instead of the version in version.Version, which should not longer be necessary, but we can remove in a future commit. Using the build info is more accurate and also provides extra build information if the build is not tagged, and if it is "dirty". Previously, the version was just "0.0.0" with no other helpful information. The ollama.com registry and others handle this swimmingly. --- server/internal/client/ollama/registry.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/internal/client/ollama/registry.go b/server/internal/client/ollama/registry.go index cf05f79ae..d1d01ba46 100644 --- a/server/internal/client/ollama/registry.go +++ b/server/internal/client/ollama/registry.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" "runtime" + "runtime/debug" "slices" "strconv" "strings" @@ -259,6 +260,7 @@ func DefaultRegistry() (*Registry, error) { } var rc Registry + rc.UserAgent = UserAgent() rc.Key, err = ssh.ParseRawPrivateKey(keyPEM) if err != nil { return nil, err @@ -274,6 +276,16 @@ func DefaultRegistry() (*Registry, error) { return &rc, nil } +func UserAgent() string { + buildinfo, _ := debug.ReadBuildInfo() + return fmt.Sprintf("ollama/%s (%s %s) Go/%s", + buildinfo.Main.Version, + runtime.GOARCH, + runtime.GOOS, + runtime.Version(), + ) +} + func (r *Registry) maxStreams() int { return cmp.Or(r.MaxStreams, runtime.GOMAXPROCS(0)) }