Adding configuration system
parent
5be80d49c2
commit
3c5c80624c
@ -0,0 +1,29 @@
|
||||
from pydantic import BaseSettings, Field, SecretStr
|
||||
|
||||
|
||||
class SavantSettings(BaseSettings):
|
||||
"""Savant Application Settings.
|
||||
|
||||
All environment varaibles supplied should be prefixed with "SAVANT_".
|
||||
"""
|
||||
|
||||
eleven_labs_api_key: SecretStr = Field(
|
||||
default="", description="An optional Eleven Labs API key for text to speech."
|
||||
)
|
||||
llm_model_name: str = Field(
|
||||
default="eachadea_vicuna-7b-1.1", description="The large language model name used in API requests."
|
||||
)
|
||||
openai_api_key: SecretStr = Field(
|
||||
default="EMPTY", description="An OPEN_API_KEY or an empty value if using FastChat replacement server"
|
||||
)
|
||||
openai_api_base: str = Field(
|
||||
default="http://localhost:8000/v1",
|
||||
description="The base url to an OpenAI API compliant endpoint. \
|
||||
Defaulted to FastChat replacement server defaults.",
|
||||
)
|
||||
|
||||
class Config:
|
||||
env_prefix = "SAVANT_"
|
||||
|
||||
|
||||
savant_settings = SavantSettings()
|
@ -0,0 +1 @@
|
||||
pydantic>=1.6.2,<2.0.0
|
@ -1,6 +1,10 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with Python 3.11
|
||||
# This file is autogenerated by pip-compile with Python 3.10
|
||||
# by the following command:
|
||||
#
|
||||
# pip-compile --output-file=requirements.txt requirements.in
|
||||
# pip-compile requirements.in
|
||||
#
|
||||
pydantic==1.10.8
|
||||
# via -r requirements.in
|
||||
typing-extensions==4.6.2
|
||||
# via pydantic
|
||||
|
@ -0,0 +1,32 @@
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
from pydantic.types import SecretStr
|
||||
|
||||
from chat_savant.settings import SavantSettings
|
||||
|
||||
SETTING_DEFAULTS = {
|
||||
"OPENAI_API_KEY": "EMPTY",
|
||||
"OPENAI_API_BASE": "http://localhost:8000/v1",
|
||||
"LLM_MODEL_NAME": "eachadea_vicuna-7b-1.1",
|
||||
"ELEVEN_LABS_API_KEY": "",
|
||||
}
|
||||
|
||||
|
||||
def test_setting_defaults():
|
||||
"""Regression test for settings schema."""
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
savant_settings = SavantSettings()
|
||||
assert len(savant_settings.dict()) == len(SETTING_DEFAULTS)
|
||||
for k, v in SETTING_DEFAULTS.items():
|
||||
_setting_value = getattr(savant_settings, k.lower())
|
||||
unmasked_setting = (
|
||||
_setting_value.get_secret_value() if isinstance(_setting_value, SecretStr) else _setting_value
|
||||
)
|
||||
unmasked_setting == v
|
||||
|
||||
|
||||
def test_with_envvar_prefix():
|
||||
with patch.dict(os.environ, {"SAVANT_ELEVEN_LABS_API_KEY": "thisisnotreal"}, clear=True):
|
||||
savant_settings = SavantSettings()
|
||||
assert savant_settings.eleven_labs_api_key.get_secret_value() == "thisisnotreal"
|
Loading…
Reference in New Issue