make keyconfig

This commit is contained in:
2025-10-22 12:10:40 +08:00
parent 12a0e610e5
commit 193944a3a2

View File

@@ -3,11 +3,11 @@ from typing import Any, Tuple, Type
import yaml
from pathlib import Path
from typing import Dict
import os
from loguru import logger
## NOTE: base classes taken from nerfstudio
# Pretty printing class
class PrintableConfig:
"""Printable Config defining str function"""
@@ -17,7 +17,7 @@ class PrintableConfig:
if self.is_secrete(key):
val = str(val)
val = val[:3] + "*"*(len(val) - 3)
val = val[:3] + "*"*(len(val) - 6) + val[-3:]
if isinstance(val, Tuple):
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
class ToolConfig(InstantiateConfig):
use_tool:bool = True