2023-08-14 11:37:20 +00:00
|
|
|
from enum import StrEnum
|
2023-08-24 17:01:34 +00:00
|
|
|
from pathlib import Path
|
2023-08-14 11:37:20 +00:00
|
|
|
|
2023-09-27 14:33:22 +00:00
|
|
|
from pydantic import field_validator
|
2023-08-14 11:37:20 +00:00
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
|
|
|
|
|
|
class Model(StrEnum):
|
|
|
|
"""Model to use for the LLM Chat application."""
|
|
|
|
|
|
|
|
GPT3 = "gpt-3.5-turbo"
|
|
|
|
GPT4 = "gpt-4"
|
2024-02-17 16:13:54 +00:00
|
|
|
GPT4_TURBO = "gpt-4-turbo-preview"
|
2023-08-14 11:37:20 +00:00
|
|
|
|
|
|
|
|
2023-08-19 14:58:54 +00:00
|
|
|
DEFAULT_MODEL = Model.GPT3
|
|
|
|
DEFAULT_TEMPERATURE = 0.7
|
2024-02-23 11:25:27 +00:00
|
|
|
DEFAULT_HISTORY_DIR = Path.home() / ".llm_chat" / "history"
|
2023-08-19 14:58:54 +00:00
|
|
|
|
|
|
|
|
2023-08-14 11:37:20 +00:00
|
|
|
class OpenAISettings(BaseSettings):
|
|
|
|
"""Settings for the LLM Chat application."""
|
|
|
|
|
2023-08-16 09:10:06 +00:00
|
|
|
api_key: str = ""
|
2023-08-19 14:58:54 +00:00
|
|
|
model: Model = DEFAULT_MODEL
|
|
|
|
temperature: float = DEFAULT_TEMPERATURE
|
2023-09-14 16:58:40 +00:00
|
|
|
history_dir: Path = DEFAULT_HISTORY_DIR
|
2023-08-14 11:37:20 +00:00
|
|
|
|
2023-08-16 09:10:06 +00:00
|
|
|
model_config: SettingsConfigDict = SettingsConfigDict( # type: ignore[misc]
|
2023-08-14 11:37:20 +00:00
|
|
|
env_file=".env",
|
|
|
|
env_file_encoding="utf-8",
|
|
|
|
env_prefix="OPENAI_",
|
|
|
|
frozen=True,
|
|
|
|
use_enum_values=True,
|
|
|
|
)
|
2023-09-27 14:33:22 +00:00
|
|
|
|
|
|
|
@field_validator("history_dir")
|
|
|
|
def history_dir_must_exist(cls, history_dir: Path) -> Path:
|
|
|
|
"""Ensure that the history directory exists."""
|
|
|
|
if not history_dir.exists():
|
|
|
|
history_dir.mkdir(parents=True)
|
|
|
|
return history_dir
|