make keyconfig
This commit is contained in:
@@ -3,11 +3,11 @@ from typing import Any, Tuple, Type
|
|||||||
import yaml
|
import yaml
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
import os
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
## NOTE: base classes taken from nerfstudio
|
## NOTE: base classes taken from nerfstudio
|
||||||
# Pretty printing class
|
|
||||||
class PrintableConfig:
|
class PrintableConfig:
|
||||||
"""Printable Config defining str function"""
|
"""Printable Config defining str function"""
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ class PrintableConfig:
|
|||||||
|
|
||||||
if self.is_secrete(key):
|
if self.is_secrete(key):
|
||||||
val = str(val)
|
val = str(val)
|
||||||
val = val[:3] + "*"*(len(val) - 3)
|
val = val[:3] + "*"*(len(val) - 6) + val[-3:]
|
||||||
|
|
||||||
if isinstance(val, Tuple):
|
if isinstance(val, Tuple):
|
||||||
flattened_val = "["
|
flattened_val = "["
|
||||||
@@ -56,6 +56,22 @@ class InstantiateConfig(PrintableConfig):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class KeyConfig(InstantiateConfig):
|
||||||
|
|
||||||
|
api_key:str = None
|
||||||
|
"""api key for llm"""
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
if self.api_key == "wrong-key" or self.api_key is None:
|
||||||
|
self.api_key = os.environ.get("ALI_API_KEY")
|
||||||
|
if self.api_key is None:
|
||||||
|
logger.error(f"no ALI_API_KEY provided for embedding")
|
||||||
|
else:
|
||||||
|
logger.info("ALI_API_KEY loaded from environ")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ToolConfig(InstantiateConfig):
|
class ToolConfig(InstantiateConfig):
|
||||||
use_tool:bool = True
|
use_tool:bool = True
|
||||||
|
|||||||
Reference in New Issue
Block a user