feat: load config class when doing variable substitution

When using bash style substitution env variable in distribution
template, we are processing the string and convert it to the type
associated with the provider's config class. This allows us to return
the proper type. This is crucial for api key since they are not strings
anymore but SecretStr. If the key is unset we will get an empty string
which will result in a Pydantic error like:

```
ERROR    2025-09-25 21:40:44,565 __main__:527 core::server: Error creating app: 1 validation error for AnthropicConfig
         api_key
           Input should be a valid string
             For further information visit
             https://errors.pydantic.dev/2.11/v/string_type
```

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han 2025-09-25 10:27:41 +02:00
parent 4af141292f
commit bc64635835
No known key found for this signature in database
79 changed files with 381 additions and 216 deletions

View file

@ -5,15 +5,16 @@
# the root directory of this source tree.
from typing import Any
from pydantic import BaseModel, SecretStr
from pydantic import BaseModel
from llama_stack.core.datatypes import Api
from llama_stack.core.secret_types import MySecretStr
from .config import BraintrustScoringConfig
class BraintrustProviderDataValidator(BaseModel):
openai_api_key: SecretStr
openai_api_key: MySecretStr
async def get_provider_impl(

View file

@ -17,7 +17,7 @@ from autoevals.ragas import (
ContextRelevancy,
Faithfulness,
)
from pydantic import BaseModel, SecretStr
from pydantic import BaseModel
from llama_stack.apis.datasetio import DatasetIO
from llama_stack.apis.datasets import Datasets
@ -31,6 +31,7 @@ from llama_stack.apis.scoring import (
from llama_stack.apis.scoring_functions import ScoringFn, ScoringFnParams
from llama_stack.core.datatypes import Api
from llama_stack.core.request_headers import NeedsRequestProviderData
from llama_stack.core.secret_types import MySecretStr
from llama_stack.providers.datatypes import ScoringFunctionsProtocolPrivate
from llama_stack.providers.utils.common.data_schema_validator import (
get_valid_schemas,
@ -152,7 +153,7 @@ class BraintrustScoringImpl(
raise ValueError(
'Pass OpenAI API Key in the header X-LlamaStack-Provider-Data as { "openai_api_key": <your api key>}'
)
self.config.openai_api_key = SecretStr(provider_data.openai_api_key)
self.config.openai_api_key = MySecretStr(provider_data.openai_api_key)
os.environ["OPENAI_API_KEY"] = self.config.openai_api_key.get_secret_value()

View file

@ -5,12 +5,13 @@
# the root directory of this source tree.
from typing import Any
from pydantic import BaseModel, Field, SecretStr
from pydantic import BaseModel, Field
from llama_stack.core.secret_types import MySecretStr
class BraintrustScoringConfig(BaseModel):
openai_api_key: SecretStr = Field(
default=SecretStr(""),
openai_api_key: MySecretStr = Field(
description="The OpenAI API Key",
)

View file

@ -65,8 +65,7 @@ class ConsoleSpanProcessor(SpanProcessor):
if key.startswith("__") or key in ["message", "severity"]:
continue
str_value = str(value)
logger.info(f"[dim]{key}[/dim]: {str_value}")
logger.info(f"[dim]{key}[/dim]: {value}")
def shutdown(self) -> None:
"""Shutdown the processor."""