-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
51 lines (41 loc) · 1.54 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Project configuration."""
from enum import Enum
from os import environ
from pathlib import Path
from typing import Optional
from pydantic import BaseModel, Field
from tomlkit import load
class OpenAIModel(str, Enum):
"""OpenAI chatbot models for fine-tuning."""
GPT4 = "gpt-4"
GPT35T = "gpt-3.5-turbo"
DAVINCI = "davinci-002"
BABBAGE = "babbage-002"
class ProjectConfig(BaseModel):
"""Project configuration."""
openai_api_key: str = Field(..., description="OpenAI API key.")
openai_model: OpenAIModel = Field(
OpenAIModel.GPT35T, description="OpenAI model to use."
)
username: Optional[str] = Field(None, description="Username for the chatbot.")
password: Optional[str] = Field(None, description="Password for the chatbot.")
share: Optional[bool] = Field(
False,
description="Share the chatbot UI with outside, can be used for three days.",
)
@classmethod
def from_env(cls):
"""Load config from environment variables."""
return cls(
openai_api_key=environ.get("OPENAI_API_KEY", None),
openai_model=environ.get("OPENAI_MODEL", None),
username=environ.get("USERNAME", None),
password=environ.get("PASSWORD", None),
share=environ.get("SHARE", None),
)
@classmethod
def from_toml_file(cls, path: Path = Path("../../.config.toml")):
"""Load config from a TOML file, under project header."""
with open(path) as f:
config = load(f)
return cls(**config["project"])