This commit is contained in:
frob 2025-10-07 13:55:05 +03:00 committed by GitHub
commit 7e489aae3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View File

@ -835,7 +835,7 @@ func DefaultOptions() Options {
NumBatch: 512,
NumGPU: -1, // -1 here indicates that NumGPU should be set dynamically
NumThread: 0, // let the runtime decide
UseMMap: nil,
UseMMap: envconfig.UseMMap(),
},
}
}

View File

@ -167,6 +167,21 @@ func Bool(k string) func() bool {
}
}
func BoolPtr(k string) func() *bool {
return func() *bool {
if s := Var(k); s != "" {
b, err := strconv.ParseBool(s)
if err != nil {
return nil
}
return &b
}
return nil
}
}
// LogLevel returns the log level for the application.
// Values are 0 or false INFO (Default), 1 or true DEBUG, 2 TRACE
func LogLevel() slog.Level {
@ -203,6 +218,8 @@ var (
ContextLength = Uint("OLLAMA_CONTEXT_LENGTH", 4096)
// Auth enables authentication between the Ollama client and server
UseAuth = Bool("OLLAMA_AUTH")
// Set default value for UseMMap
UseMMap = BoolPtr("OLLAMA_USE_MMAP")
)
func String(s string) func() string {
@ -289,6 +306,7 @@ func AsMap() map[string]EnvVar {
"OLLAMA_CONTEXT_LENGTH": {"OLLAMA_CONTEXT_LENGTH", ContextLength(), "Context length to use unless otherwise specified (default: 4096)"},
"OLLAMA_NEW_ENGINE": {"OLLAMA_NEW_ENGINE", NewEngine(), "Enable the new Ollama engine"},
"OLLAMA_REMOTES": {"OLLAMA_REMOTES", Remotes(), "Allowed hosts for remote models (default \"ollama.com\")"},
"OLLAMA_USE_MMAP": {"OLLAMA_USE_MMAP", UseMMap(), "Set default value for use_mmap"},
// Informational
"HTTP_PROXY": {"HTTP_PROXY", String("HTTP_PROXY")(), "HTTP proxy"},
@ -318,7 +336,15 @@ func AsMap() map[string]EnvVar {
func Values() map[string]string {
vals := make(map[string]string)
for k, v := range AsMap() {
vals[k] = fmt.Sprintf("%v", v.Value)
value := v.Value
if p, ok := value.(*bool); ok {
if p == nil {
value = ""
} else {
value = *p
}
}
vals[k] = fmt.Sprintf("%v", value)
}
return vals
}