-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
88 lines (75 loc) · 3.15 KB
/
config.py
File metadata and controls
88 lines (75 loc) · 3.15 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright 2024-2025 DavoCoder
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# config.py
import os
import json
from pathlib import Path
from typing import Dict, Any
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
class Config:
CONFIG_DIR = Path(__file__).parent / "config"
# Knowledge base paths
KNOWLEDGE_ARTICLES_DIR_PATH = os.getenv("KNOWLEDGE_ARTICLES_DIR_PATH")
METADATA_FILE_PATH = os.getenv("METADATA_FILE_PATH")
# HuggingFace Settings
TOKENIZERS_PARALLELISM = "false"
# Chroma Settings
CHROMA_PERSIST_DIR_PATH = os.getenv("CHROMA_PERSIST_DIR_PATH")
# Google Auth Settings
GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID")
GOOGLE_CLIENT_SECRET = os.getenv("GOOGLE_CLIENT_SECRET")
# Auth Database paths
AUTH_DB_PATH = "users.db"
AUTH_DB_SCHEMA_PATH = "auth_schema.sql"
# Validation
@classmethod
def validate(cls):
"""Validate the configuration"""
# Ensure persist directory exists
Path(cls.CHROMA_PERSIST_DIR_PATH).mkdir(parents=True, exist_ok=True)
@classmethod
def set_environment(cls):
"""Set necessary environment variables"""
os.environ["CHROMA_PERSIST_DIR_PATH"] = cls.CHROMA_PERSIST_DIR_PATH
os.environ["KNOWLEDGE_ARTICLES_DIR_PATH"] = cls.KNOWLEDGE_ARTICLES_DIR_PATH
os.environ["METADATA_FILE_PATH"] = cls.METADATA_FILE_PATH
os.environ["TOKENIZERS_PARALLELISM"] = cls.TOKENIZERS_PARALLELISM
@classmethod
def load_config(cls, filename: str) -> Dict[str, Any]:
"""Load configuration from JSON file."""
config_path = cls.CONFIG_DIR / filename
try:
with open(config_path, 'r', encoding='utf-8') as f:
return json.load(f)
except Exception as e:
raise ConfigException(f"Error loading configuration {filename}: {str(e)}") from e
@classmethod
def load_all_configs(cls) -> Dict[str, Dict[str, Any]]:
"""Load all configuration files."""
try:
return {
"provider_models": cls.load_config("provider_models.json"),
"task_descriptions": cls.load_config("task_descriptions.json"),
"task_settings": cls.load_config("task_settings.json"),
"system_prompts": cls.load_config("system_prompts.json")
}
except Exception as e:
raise ConfigException(f"Error loading configurations: {str(e)}") from e
class ConfigException(Exception):
"""Base exception for configuration related errors"""
def __init__(self, message="Configuration error occurred"):
self.message = message
super().__init__(self.message)