Config: Make API server literals case insensitive
There's no native way to handle case insensitivity in pydantic, so add a validator which converts the API server input to be lowercase. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
2fd02cf4fc
commit
edf3a00310
1 changed files with 15 additions and 2 deletions
|
|
@ -1,5 +1,12 @@
|
|||
from pathlib import Path
|
||||
from pydantic import BaseModel, ConfigDict, Field, PrivateAttr
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
Field,
|
||||
PrivateAttr,
|
||||
field_validator,
|
||||
validator,
|
||||
)
|
||||
from typing import List, Literal, Optional, Union
|
||||
|
||||
|
||||
|
|
@ -79,7 +86,7 @@ class NetworkConfig(BaseConfigModel):
|
|||
"NOTE: Only enable this for debug purposes."
|
||||
),
|
||||
)
|
||||
api_servers: Optional[List[Literal["OAI", "Kobold"]]] = Field(
|
||||
api_servers: Optional[List[Literal["oai", "kobold"]]] = Field(
|
||||
["OAI"],
|
||||
description=(
|
||||
'Select API servers to enable (default: ["OAI"]).\n'
|
||||
|
|
@ -87,6 +94,12 @@ class NetworkConfig(BaseConfigModel):
|
|||
),
|
||||
)
|
||||
|
||||
# Converts all strings in the api_servers list to lowercase
|
||||
# NOTE: Expand if more models need this validator
|
||||
@field_validator("api_servers", mode="before")
|
||||
def api_server_validator(cls, api_servers):
|
||||
return [server_name.lower() for server_name in api_servers]
|
||||
|
||||
|
||||
# TODO: Migrate config.yml to have the log_ prefix
|
||||
# This is a breaking change.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue