diff --git a/docs/config.png b/docs/config.png index ae4b19eb..0c709cfd 100644 Binary files a/docs/config.png and b/docs/config.png differ diff --git a/docs/config.puml b/docs/config.puml index 191710c8..a3202893 100644 --- a/docs/config.puml +++ b/docs/config.puml @@ -45,6 +45,7 @@ class "Configuration" as src.models.config.Configuration { llama_stack mcp_servers : Optional[list[ModelContextProtocolServer]] name : str + quota_handlers : Optional[QuotaHandlersConfig] service user_data_collection dump(filename: str) -> None @@ -134,6 +135,11 @@ class "PostgreSQLDatabaseConfiguration" as src.models.config.PostgreSQLDatabaseC user : str check_postgres_configuration() -> Self } +class "QuotaHandlersConfig" as src.models.config.QuotaHandlersConfig { + enable_token_history : bool + postgres : Optional[PostgreSQLDatabaseConfiguration] + sqlite : Optional[SQLiteDatabaseConfiguration] +} class "SQLiteDatabaseConfiguration" as src.models.config.SQLiteDatabaseConfiguration { db_path : str } @@ -178,6 +184,7 @@ src.models.config.JwtRoleRule --|> src.models.config.ConfigurationBase src.models.config.LlamaStackConfiguration --|> src.models.config.ConfigurationBase src.models.config.ModelContextProtocolServer --|> src.models.config.ConfigurationBase src.models.config.PostgreSQLDatabaseConfiguration --|> src.models.config.ConfigurationBase +src.models.config.QuotaHandlersConfig --|> src.models.config.ConfigurationBase src.models.config.SQLiteDatabaseConfiguration --|> src.models.config.ConfigurationBase src.models.config.ServiceConfiguration --|> src.models.config.ConfigurationBase src.models.config.TLSConfiguration --|> src.models.config.ConfigurationBase diff --git a/docs/config.svg b/docs/config.svg index 5c291608..86e2926e 100644 --- a/docs/config.svg +++ b/docs/config.svg @@ -1,88 +1,88 @@ - + - - - - AccessRule - - actions : list[Action] - role : str - + + + + AccessRule + + actions : list[Action] + role : str + - - - - Action - - name - + + + + Action + + name + - - - - AuthenticationConfiguration - - jwk_config : Optional[JwkConfiguration] - jwk_configuration - k8s_ca_cert_path : Optional[FilePath] - k8s_cluster_api : Optional[AnyHttpUrl] - module : str - skip_tls_verification : bool - - check_authentication_model() -> Self + + + + AuthenticationConfiguration + + jwk_config : Optional[JwkConfiguration] + jwk_configuration + k8s_ca_cert_path : Optional[FilePath] + k8s_cluster_api : Optional[AnyHttpUrl] + module : str + skip_tls_verification : bool + + check_authentication_model() -> Self - - - - AuthorizationConfiguration - - access_rules : Optional[list[AccessRule]] - + + + + AuthorizationConfiguration + + access_rules : Optional[list[AccessRule]] + - - - - ByokRag - - db_path : Annotated - embedding_dimension : Annotated - embedding_model : Annotated - rag_id : Annotated - rag_type : Annotated - vector_db_id : Annotated - + + + + ByokRag + + db_path : Annotated + embedding_dimension : Annotated + embedding_model : Annotated + rag_id : Annotated + rag_type : Annotated + vector_db_id : Annotated + - - - - CORSConfiguration - - allow_credentials : bool - allow_headers : list[str] - allow_methods : list[str] - allow_origins : list[str] - - check_cors_configuration() -> Self + + + + CORSConfiguration + + allow_credentials : bool + allow_headers : list[str] + allow_methods : list[str] + allow_origins : list[str] + + check_cors_configuration() -> Self - + - + Configuration authentication : Optional[AuthenticationConfiguration] @@ -95,40 +95,41 @@ llama_stack mcp_servers : Optional[list[ModelContextProtocolServer]] name : str - service - user_data_collection - - dump(filename: str) -> None + quota_handlers : Optional[QuotaHandlersConfig] + service + user_data_collection + + dump(filename: str) -> None - - - - ConfigurationBase - - model_config - + + + + ConfigurationBase + + model_config + - - - - ConversationCacheConfiguration - - memory : Optional[InMemoryCacheConfig] - postgres : Optional[PostgreSQLDatabaseConfiguration] - sqlite : Optional[SQLiteDatabaseConfiguration] - type : Literal['noop', 'memory', 'sqlite', 'postgres'] | None - - check_cache_configuration() -> Self + + + + ConversationCacheConfiguration + + memory : Optional[InMemoryCacheConfig] + postgres : Optional[PostgreSQLDatabaseConfiguration] + sqlite : Optional[SQLiteDatabaseConfiguration] + type : Literal['noop', 'memory', 'sqlite', 'postgres'] | None + + check_cache_configuration() -> Self - + - + CustomProfile path : str @@ -138,164 +139,176 @@ - - - - Customization - - custom_profile : Optional[CustomProfile] - disable_query_system_prompt : bool - profile_path : Optional[str] - system_prompt : Optional[str] - system_prompt_path : Optional[FilePath] - - check_customization_model() -> Self + + + + Customization + + custom_profile : Optional[CustomProfile] + disable_query_system_prompt : bool + profile_path : Optional[str] + system_prompt : Optional[str] + system_prompt_path : Optional[FilePath] + + check_customization_model() -> Self - - - - DatabaseConfiguration - - config - db_type - postgres : Optional[PostgreSQLDatabaseConfiguration] - sqlite : Optional[SQLiteDatabaseConfiguration] - - check_database_configuration() -> Self + + + + DatabaseConfiguration + + config + db_type + postgres : Optional[PostgreSQLDatabaseConfiguration] + sqlite : Optional[SQLiteDatabaseConfiguration] + + check_database_configuration() -> Self - - - - InMemoryCacheConfig - - max_entries : Annotated - + + + + InMemoryCacheConfig + + max_entries : Annotated + - - - - InferenceConfiguration - - default_model : Optional[str] - default_provider : Optional[str] - - check_default_model_and_provider() -> Self + + + + InferenceConfiguration + + default_model : Optional[str] + default_provider : Optional[str] + + check_default_model_and_provider() -> Self - - - - JsonPathOperator - - name - + + + + JsonPathOperator + + name + - - - - JwkConfiguration - - jwt_configuration : Optional[JwtConfiguration] - url : AnyHttpUrl - + + + + JwkConfiguration + + jwt_configuration : Optional[JwtConfiguration] + url : AnyHttpUrl + - - - - JwtConfiguration - - role_rules : Optional[list[JwtRoleRule]] - user_id_claim : str - username_claim : str - + + + + JwtConfiguration + + role_rules : Optional[list[JwtRoleRule]] + user_id_claim : str + username_claim : str + - - - - JwtRoleRule - - compiled_regex - jsonpath : str - negate : bool - operator - roles : list[str] - value : Any - - check_jsonpath() -> Self - check_regex_pattern() -> Self - check_roles() -> Self + + + + JwtRoleRule + + compiled_regex + jsonpath : str + negate : bool + operator + roles : list[str] + value : Any + + check_jsonpath() -> Self + check_regex_pattern() -> Self + check_roles() -> Self - - - - LlamaStackConfiguration - - api_key : Optional[SecretStr] - library_client_config_path : Optional[str] - url : Optional[str] - use_as_library_client : Optional[bool] - - check_llama_stack_model() -> Self + + + + LlamaStackConfiguration + + api_key : Optional[SecretStr] + library_client_config_path : Optional[str] + url : Optional[str] + use_as_library_client : Optional[bool] + + check_llama_stack_model() -> Self - - - - ModelContextProtocolServer - - name : str - provider_id : str - url : str - + + + + ModelContextProtocolServer + + name : str + provider_id : str + url : str + - - - - PostgreSQLDatabaseConfiguration - - ca_cert_path : Optional[FilePath] - db : str - gss_encmode : str - host : str - namespace : Optional[str] - password : SecretStr - port : Annotated - ssl_mode : str - user : str - - check_postgres_configuration() -> Self + + + + PostgreSQLDatabaseConfiguration + + ca_cert_path : Optional[FilePath] + db : str + gss_encmode : str + host : str + namespace : Optional[str] + password : SecretStr + port : Annotated + ssl_mode : str + user : str + + check_postgres_configuration() -> Self + + + + + + + QuotaHandlersConfig + + enable_token_history : bool + postgres : Optional[PostgreSQLDatabaseConfiguration] + sqlite : Optional[SQLiteDatabaseConfiguration] + - - - - SQLiteDatabaseConfiguration - - db_path : str - + + + + SQLiteDatabaseConfiguration + + db_path : str + - + ServiceConfiguration @@ -313,172 +326,177 @@ - - - - TLSConfiguration - - tls_certificate_path : Optional[FilePath] - tls_key_password : Optional[FilePath] - tls_key_path : Optional[FilePath] - - check_tls_configuration() -> Self + + + + TLSConfiguration + + tls_certificate_path : Optional[FilePath] + tls_key_password : Optional[FilePath] + tls_key_path : Optional[FilePath] + + check_tls_configuration() -> Self - - - - UserDataCollection - - feedback_enabled : bool - feedback_storage : Optional[str] - transcripts_enabled : bool - transcripts_storage : Optional[str] - - check_storage_location_is_set_when_needed() -> Self + + + + UserDataCollection + + feedback_enabled : bool + feedback_storage : Optional[str] + transcripts_enabled : bool + transcripts_storage : Optional[str] + + check_storage_location_is_set_when_needed() -> Self - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + - - + + - - + + - - + + - - + + - - + + custom_profile - - - operator + + + operator - - - llama_stack + + + llama_stack - - - sqlite + + + sqlite - - - service + + + service - - - user_data_collection + + + user_data_collection - + diff --git a/src/models/config.py b/src/models/config.py index 82fa2ece..cd753b02 100644 --- a/src/models/config.py +++ b/src/models/config.py @@ -564,6 +564,14 @@ class ByokRag(ConfigurationBase): db_path: FilePath +class QuotaHandlersConfig(ConfigurationBase): + """Quota limiter configuration.""" + + sqlite: Optional[SQLiteDatabaseConfiguration] = None + postgres: Optional[PostgreSQLDatabaseConfiguration] = None + enable_token_history: bool = False + + class Configuration(ConfigurationBase): """Global service configuration.""" @@ -583,6 +591,7 @@ class Configuration(ConfigurationBase): default_factory=ConversationCacheConfiguration ) byok_rag: list[ByokRag] = Field(default_factory=list) + quota_handlers: QuotaHandlersConfig = Field(default_factory=QuotaHandlersConfig) def dump(self, filename: str = "configuration.json") -> None: """Dump actual configuration into JSON file.""" diff --git a/tests/unit/models/config/test_dump_configuration.py b/tests/unit/models/config/test_dump_configuration.py index 4718e5b1..8fc18c12 100644 --- a/tests/unit/models/config/test_dump_configuration.py +++ b/tests/unit/models/config/test_dump_configuration.py @@ -89,6 +89,7 @@ def test_dump_configuration(tmp_path) -> None: assert "inference" in content assert "database" in content assert "byok_rag" in content + assert "quota_handlers" in content # check the whole deserialized JSON file content assert content == { @@ -171,6 +172,11 @@ def test_dump_configuration(tmp_path) -> None: "type": None, }, "byok_rag": [], + "quota_handlers": { + "sqlite": None, + "postgres": None, + "enable_token_history": False, + }, }