mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 12:07:34 +00:00
chore: use empty SecretStr values as default
Better than using SecretStr | None so we centralize the null handling. Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
parent
c4cb6aa8d9
commit
4af141292f
51 changed files with 103 additions and 93 deletions
|
@ -9,8 +9,8 @@ from pydantic import BaseModel, Field, SecretStr
|
|||
|
||||
|
||||
class BraintrustScoringConfig(BaseModel):
|
||||
openai_api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
openai_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The OpenAI API Key",
|
||||
)
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ class S3FilesImplConfig(BaseModel):
|
|||
bucket_name: str = Field(description="S3 bucket name to store files")
|
||||
region: str = Field(default="us-east-1", description="AWS region where the bucket is located")
|
||||
aws_access_key_id: str | None = Field(default=None, description="AWS access key ID (optional if using IAM roles)")
|
||||
aws_secret_access_key: SecretStr | None = Field(
|
||||
default=None, description="AWS secret access key (optional if using IAM roles)"
|
||||
aws_secret_access_key: SecretStr = Field(
|
||||
default=SecretStr(""), description="AWS secret access key (optional if using IAM roles)"
|
||||
)
|
||||
endpoint_url: str | None = Field(default=None, description="Custom S3 endpoint URL (for MinIO, LocalStack, etc.)")
|
||||
auto_create_bucket: bool = Field(
|
||||
|
|
|
@ -12,16 +12,16 @@ from llama_stack.schema_utils import json_schema_type
|
|||
|
||||
|
||||
class AnthropicProviderDataValidator(BaseModel):
|
||||
anthropic_api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
anthropic_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for Anthropic models",
|
||||
)
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class AnthropicConfig(BaseModel):
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for Anthropic models",
|
||||
)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class AzureInferenceAdapter(OpenAIMixin, LiteLLMOpenAIMixin):
|
|||
LiteLLMOpenAIMixin.__init__(
|
||||
self,
|
||||
litellm_provider_name="azure",
|
||||
api_key_from_config=config.api_key.get_secret_value(),
|
||||
api_key_from_config=config.api_key,
|
||||
provider_data_api_key_field="azure_api_key",
|
||||
openai_compat_api_base=str(config.api_base),
|
||||
)
|
||||
|
|
|
@ -21,7 +21,11 @@ class CerebrasImplConfig(BaseModel):
|
|||
description="Base URL for the Cerebras API",
|
||||
)
|
||||
api_key: SecretStr = Field(
|
||||
<<<<<<< HEAD
|
||||
default=SecretStr(os.environ.get("CEREBRAS_API_KEY")),
|
||||
=======
|
||||
default=SecretStr(os.environ.get("CEREBRAS_API_KEY", "")),
|
||||
>>>>>>> a48f2009 (chore: use empty SecretStr values as default)
|
||||
description="Cerebras API Key",
|
||||
)
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ class FireworksImplConfig(RemoteInferenceProviderConfig):
|
|||
default="https://api.fireworks.ai/inference/v1",
|
||||
description="The URL for the Fireworks server",
|
||||
)
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The Fireworks.ai API Key",
|
||||
)
|
||||
|
||||
|
|
|
@ -12,16 +12,16 @@ from llama_stack.schema_utils import json_schema_type
|
|||
|
||||
|
||||
class GeminiProviderDataValidator(BaseModel):
|
||||
gemini_api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
gemini_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for Gemini models",
|
||||
)
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class GeminiConfig(BaseModel):
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for Gemini models",
|
||||
)
|
||||
|
||||
|
|
|
@ -12,17 +12,17 @@ from llama_stack.schema_utils import json_schema_type
|
|||
|
||||
|
||||
class GroqProviderDataValidator(BaseModel):
|
||||
groq_api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
groq_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for Groq models",
|
||||
)
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class GroqConfig(BaseModel):
|
||||
api_key: SecretStr | None = Field(
|
||||
api_key: SecretStr = Field(
|
||||
# The Groq client library loads the GROQ_API_KEY environment variable by default
|
||||
default=None,
|
||||
default=SecretStr(""),
|
||||
description="The Groq API key",
|
||||
)
|
||||
|
||||
|
|
|
@ -12,16 +12,16 @@ from llama_stack.schema_utils import json_schema_type
|
|||
|
||||
|
||||
class LlamaProviderDataValidator(BaseModel):
|
||||
llama_api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
llama_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for api.llama models",
|
||||
)
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class LlamaCompatConfig(BaseModel):
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The Llama API key",
|
||||
)
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ class NVIDIAConfig(BaseModel):
|
|||
default_factory=lambda: os.getenv("NVIDIA_BASE_URL", "https://integrate.api.nvidia.com"),
|
||||
description="A base url for accessing the NVIDIA NIM",
|
||||
)
|
||||
api_key: SecretStr | None = Field(
|
||||
default_factory=lambda: SecretStr(os.getenv("NVIDIA_API_KEY")),
|
||||
api_key: SecretStr = Field(
|
||||
default_factory=lambda: SecretStr(os.getenv("NVIDIA_API_KEY", "")),
|
||||
description="The NVIDIA API key, only needed of using the hosted service",
|
||||
)
|
||||
timeout: int = Field(
|
||||
|
|
|
@ -12,16 +12,16 @@ from llama_stack.schema_utils import json_schema_type
|
|||
|
||||
|
||||
class OpenAIProviderDataValidator(BaseModel):
|
||||
openai_api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
openai_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for OpenAI models",
|
||||
)
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class OpenAIConfig(BaseModel):
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API key for OpenAI models",
|
||||
)
|
||||
base_url: str = Field(
|
||||
|
|
|
@ -18,8 +18,8 @@ class PassthroughImplConfig(BaseModel):
|
|||
description="The URL for the passthrough endpoint",
|
||||
)
|
||||
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API Key for the passthrouth endpoint",
|
||||
)
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ class RunpodImplConfig(BaseModel):
|
|||
default=None,
|
||||
description="The URL for the Runpod model serving endpoint",
|
||||
)
|
||||
api_token: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_token: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The API token",
|
||||
)
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ from llama_stack.schema_utils import json_schema_type
|
|||
|
||||
|
||||
class SambaNovaProviderDataValidator(BaseModel):
|
||||
sambanova_api_key: str | None = Field(
|
||||
default=None,
|
||||
sambanova_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="Sambanova Cloud API key",
|
||||
)
|
||||
|
||||
|
@ -24,8 +24,8 @@ class SambaNovaImplConfig(BaseModel):
|
|||
default="https://api.sambanova.ai/v1",
|
||||
description="The URL for the SambaNova AI server",
|
||||
)
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The SambaNova cloud API Key",
|
||||
)
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ class TogetherImplConfig(RemoteInferenceProviderConfig):
|
|||
default="https://api.together.xyz/v1",
|
||||
description="The URL for the Together AI server",
|
||||
)
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The Together AI API Key",
|
||||
)
|
||||
|
||||
|
|
|
@ -24,12 +24,12 @@ class VertexAIInferenceAdapter(OpenAIMixin, LiteLLMOpenAIMixin):
|
|||
LiteLLMOpenAIMixin.__init__(
|
||||
self,
|
||||
litellm_provider_name="vertex_ai",
|
||||
api_key_from_config=None, # Vertex AI uses ADC, not API keys
|
||||
api_key_from_config=SecretStr(""), # Vertex AI uses ADC, not API keys
|
||||
provider_data_api_key_field="vertex_project", # Use project for validation
|
||||
)
|
||||
self.config = config
|
||||
|
||||
def get_api_key(self) -> str:
|
||||
def get_api_key(self) -> SecretStr:
|
||||
"""
|
||||
Get an access token for Vertex AI using Application Default Credentials.
|
||||
|
||||
|
@ -40,7 +40,7 @@ class VertexAIInferenceAdapter(OpenAIMixin, LiteLLMOpenAIMixin):
|
|||
# Get default credentials - will read from GOOGLE_APPLICATION_CREDENTIALS
|
||||
credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"])
|
||||
credentials.refresh(google.auth.transport.requests.Request())
|
||||
return str(credentials.token)
|
||||
return SecretStr(credentials.token)
|
||||
except Exception:
|
||||
# If we can't get credentials, return empty string to let LiteLLM handle it
|
||||
# This allows the LiteLLM mixin to work with ADC directly
|
||||
|
|
|
@ -4,13 +4,16 @@
|
|||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field, SecretStr
|
||||
|
||||
from .config import VLLMInferenceAdapterConfig
|
||||
|
||||
|
||||
class VLLMProviderDataValidator(BaseModel):
|
||||
vllm_api_token: str | None = None
|
||||
vllm_api_token: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="API token for vLLM models",
|
||||
)
|
||||
|
||||
|
||||
async def get_adapter_impl(config: VLLMInferenceAdapterConfig, _deps):
|
||||
|
|
|
@ -21,8 +21,8 @@ class VLLMInferenceAdapterConfig(BaseModel):
|
|||
default=4096,
|
||||
description="Maximum number of tokens to generate.",
|
||||
)
|
||||
api_token: SecretStr | None = Field(
|
||||
default=SecretStr("fake"),
|
||||
api_token: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The API token",
|
||||
)
|
||||
tls_verify: bool | str = Field(
|
||||
|
|
|
@ -294,7 +294,7 @@ class VLLMInferenceAdapter(OpenAIMixin, LiteLLMOpenAIMixin, Inference, ModelsPro
|
|||
self,
|
||||
model_entries=build_hf_repo_model_entries(),
|
||||
litellm_provider_name="vllm",
|
||||
api_key_from_config=config.api_token.get_secret_value(),
|
||||
api_key_from_config=config.api_token,
|
||||
provider_data_api_key_field="vllm_api_token",
|
||||
openai_compat_api_base=config.url,
|
||||
)
|
||||
|
|
|
@ -24,8 +24,8 @@ class WatsonXConfig(BaseModel):
|
|||
default_factory=lambda: os.getenv("WATSONX_BASE_URL", "https://us-south.ml.cloud.ibm.com"),
|
||||
description="A base url for accessing the watsonx.ai",
|
||||
)
|
||||
api_key: SecretStr | None = Field(
|
||||
default_factory=lambda: os.getenv("WATSONX_API_KEY"),
|
||||
api_key: SecretStr = Field(
|
||||
default_factory=lambda: SecretStr(os.getenv("WATSONX_API_KEY", "")),
|
||||
description="The watsonx API key",
|
||||
)
|
||||
project_id: str | None = Field(
|
||||
|
|
|
@ -12,8 +12,8 @@ from llama_stack.schema_utils import json_schema_type
|
|||
|
||||
|
||||
class SambaNovaProviderDataValidator(BaseModel):
|
||||
sambanova_api_key: str | None = Field(
|
||||
default=None,
|
||||
sambanova_api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="Sambanova Cloud API key",
|
||||
)
|
||||
|
||||
|
@ -24,8 +24,8 @@ class SambaNovaSafetyConfig(BaseModel):
|
|||
default="https://api.sambanova.ai/v1",
|
||||
description="The URL for the SambaNova AI server",
|
||||
)
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The SambaNova cloud API Key",
|
||||
)
|
||||
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, SecretStr
|
||||
from pydantic import BaseModel, Field, SecretStr
|
||||
|
||||
|
||||
class BingSearchToolConfig(BaseModel):
|
||||
"""Configuration for Bing Search Tool Runtime"""
|
||||
|
||||
api_key: SecretStr | None = None
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The Bing API key",
|
||||
)
|
||||
top_k: int = 3
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -10,8 +10,8 @@ from pydantic import BaseModel, Field, SecretStr
|
|||
|
||||
|
||||
class BraveSearchToolConfig(BaseModel):
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The Brave Search API Key",
|
||||
)
|
||||
max_results: int = Field(
|
||||
|
|
|
@ -10,8 +10,8 @@ from pydantic import BaseModel, Field, SecretStr
|
|||
|
||||
|
||||
class TavilySearchToolConfig(BaseModel):
|
||||
api_key: SecretStr | None = Field(
|
||||
default=None,
|
||||
api_key: SecretStr = Field(
|
||||
default=SecretStr(""),
|
||||
description="The Tavily Search API Key",
|
||||
)
|
||||
max_results: int = Field(
|
||||
|
|
|
@ -21,7 +21,7 @@ class PGVectorVectorIOConfig(BaseModel):
|
|||
port: int | None = Field(default=5432)
|
||||
db: str | None = Field(default="postgres")
|
||||
user: str | None = Field(default="postgres")
|
||||
password: SecretStr | None = Field(default="mysecretpassword")
|
||||
password: SecretStr = Field(default=SecretStr("mysecretpassword"))
|
||||
kvstore: KVStoreConfig | None = Field(description="Config for KV store backend (SQLite only for now)", default=None)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -14,12 +14,12 @@ class BedrockBaseConfig(BaseModel):
|
|||
default_factory=lambda: os.getenv("AWS_ACCESS_KEY_ID"),
|
||||
description="The AWS access key to use. Default use environment variable: AWS_ACCESS_KEY_ID",
|
||||
)
|
||||
aws_secret_access_key: SecretStr | None = Field(
|
||||
default_factory=lambda: SecretStr(val) if (val := os.getenv("AWS_SECRET_ACCESS_KEY")) else None,
|
||||
aws_secret_access_key: SecretStr = Field(
|
||||
default_factory=lambda: SecretStr(os.getenv("AWS_SECRET_ACCESS_KEY", "")),
|
||||
description="The AWS secret access key to use. Default use environment variable: AWS_SECRET_ACCESS_KEY",
|
||||
)
|
||||
aws_session_token: SecretStr | None = Field(
|
||||
default_factory=lambda: SecretStr(val) if (val := os.getenv("AWS_SESSION_TOKEN")) else None,
|
||||
aws_session_token: SecretStr = Field(
|
||||
default_factory=lambda: SecretStr(os.getenv("AWS_SESSION_TOKEN", "")),
|
||||
description="The AWS session token to use. Default use environment variable: AWS_SESSION_TOKEN",
|
||||
)
|
||||
region_name: str | None = Field(
|
||||
|
|
|
@ -69,7 +69,7 @@ class LiteLLMOpenAIMixin(
|
|||
def __init__(
|
||||
self,
|
||||
litellm_provider_name: str,
|
||||
api_key_from_config: SecretStr | None,
|
||||
api_key_from_config: SecretStr,
|
||||
provider_data_api_key_field: str,
|
||||
model_entries: list[ProviderModelEntry] | None = None,
|
||||
openai_compat_api_base: str | None = None,
|
||||
|
|
|
@ -74,7 +74,7 @@ class PostgresKVStoreConfig(CommonConfig):
|
|||
port: int = 5432
|
||||
db: str = "llamastack"
|
||||
user: str
|
||||
password: SecretStr | None = None
|
||||
password: SecretStr = SecretStr("")
|
||||
ssl_mode: str | None = None
|
||||
ca_cert_path: str | None = None
|
||||
table_name: str = "llamastack_kvstore"
|
||||
|
@ -118,7 +118,7 @@ class MongoDBKVStoreConfig(CommonConfig):
|
|||
port: int = 27017
|
||||
db: str = "llamastack"
|
||||
user: str | None = None
|
||||
password: SecretStr | None = None
|
||||
password: SecretStr = SecretStr("")
|
||||
collection_name: str = "llamastack_kvstore"
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -63,11 +63,11 @@ class PostgresSqlStoreConfig(SqlAlchemySqlStoreConfig):
|
|||
port: int = 5432
|
||||
db: str = "llamastack"
|
||||
user: str
|
||||
password: SecretStr | None = None
|
||||
password: SecretStr = SecretStr("")
|
||||
|
||||
@property
|
||||
def engine_str(self) -> str:
|
||||
return f"postgresql+asyncpg://{self.user}:{self.password.get_secret_value() if self.password else ''}@{self.host}:{self.port}/{self.db}"
|
||||
return f"postgresql+asyncpg://{self.user}:{self.password.get_secret_value()}@{self.host}:{self.port}/{self.db}"
|
||||
|
||||
@classmethod
|
||||
def pip_packages(cls) -> list[str]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue