MCPcopy
hub / github.com/mudler/LocalAI / resolveAPIKey

Function resolveAPIKey

backend/go/cloud-proxy/proxy.go:122–138  ·  view source on GitHub ↗

resolveAPIKey mirrors config.ProxyConfig.ResolveAPIKey. Duplicated (a few lines) rather than importing core/config from a backend binary — keeps backends independent of core's package layout. Mutual-exclusion is enforced upstream in core/config.Validate.

(envName, filePath string)

Source from the content-addressed store, hash-verified

120// binary — keeps backends independent of core's package layout.
121// Mutual-exclusion is enforced upstream in core/config.Validate.
122func resolveAPIKey(envName, filePath string) (string, error) {
123 if envName != "" {
124 v := os.Getenv(envName)
125 if v == "" {
126 return "", fmt.Errorf("cloud-proxy: api_key_env %q is unset", envName)
127 }
128 return v, nil
129 }
130 if filePath != "" {
131 b, err := os.ReadFile(filePath)
132 if err != nil {
133 return "", fmt.Errorf("cloud-proxy: read api_key_file %q: %w", filePath, err)
134 }
135 return strings.TrimSpace(string(b)), nil
136 }
137 return "", nil
138}
139
140// PredictRich is the non-streaming translate path. Returns a fully-
141// populated *pb.Reply: content, tool-call deltas (ChatDeltas), and

Callers 1

LoadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected