Skip to content

Commit edbca63

Browse files
committed
Simplify API key setting for llama_stack
Deduplicate the API key Sprintf call by hoisting the field name (api_key vs api_token) into a variable and performing a single assignment after the provider-type branch.
1 parent b3aa334 commit edbca63

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

internal/controller/llama_stack_config.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,16 @@ func buildLlamaStackInferenceProviders(_ *common_helper.Helper, _ context.Contex
128128
// Determine the appropriate Llama Stack provider type:
129129
// - OpenAI uses remote::openai
130130
// - vLLM uses remote::vllm
131+
var apiKeyField string
131132
if provider.Type == "openai" {
132133
providerConfig["provider_type"] = "remote::openai"
133-
// Set API key from environment variable
134-
// Llama Stack will substitute ${env.VAR_NAME} with the actual env var value
135-
config["api_key"] = fmt.Sprintf("${env.%s%s}", envVarName, EnvVarSuffixAPIKey)
136-
134+
apiKeyField = "api_key"
137135
} else {
138136
providerConfig["provider_type"] = "remote::vllm"
139-
// Set API token from environment variable for vLLM
140-
// Llama Stack will substitute ${env.VAR_NAME} with the actual env var value
141-
config["api_token"] = fmt.Sprintf("${env.%s%s}", envVarName, EnvVarSuffixAPIKey)
137+
apiKeyField = "api_token"
142138
}
139+
// Llama Stack will substitute ${env.VAR_NAME} with the actual env var value
140+
config[apiKeyField] = fmt.Sprintf("${env.%s%s}", envVarName, EnvVarSuffixAPIKey)
143141

144142
// Add custom URL if specified
145143
if provider.URL != "" {

0 commit comments

Comments
 (0)