mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-21 23:09:13 +00:00
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:
@@ -1,5 +1,12 @@
|
|||||||
from pathlib import Path
|
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
|
from typing import List, Literal, Optional, Union
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +86,7 @@ class NetworkConfig(BaseConfigModel):
|
|||||||
"NOTE: Only enable this for debug purposes."
|
"NOTE: Only enable this for debug purposes."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
api_servers: Optional[List[Literal["OAI", "Kobold"]]] = Field(
|
api_servers: Optional[List[Literal["oai", "kobold"]]] = Field(
|
||||||
["OAI"],
|
["OAI"],
|
||||||
description=(
|
description=(
|
||||||
'Select API servers to enable (default: ["OAI"]).\n'
|
'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
|
# TODO: Migrate config.yml to have the log_ prefix
|
||||||
# This is a breaking change.
|
# This is a breaking change.
|
||||||
|
|||||||
Reference in New Issue
Block a user