Skip to content

Commit 795d77d

Browse files
committed
Refactor
1 parent 8fe1bf6 commit 795d77d

File tree

8 files changed

+124
-57
lines changed

8 files changed

+124
-57
lines changed

.env

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Pinecone configuration
2+
PINECONE_API_KEY=your_pinecone_api_key
3+
PINECONE_ENV=your_pinecone_environment
4+
5+
# Logging configuration
6+
AUDIOKIT_LOG_LEVEL=INFO
7+
AUDIOKIT_LOG_FILE=logs/audiokit.log
8+
9+
# Directory configuration
10+
AUDIOKIT_MODELS_DIR=models
11+
AUDIOKIT_OUTPUT_DIR=output
12+
AUDIOKIT_TEMP_DIR=temp
13+
14+
# Soundcharts API (optional)
15+
SOUNDCHARTS_APP_ID=your_app_id
16+
SOUNDCHARTS_API_KEY=your_api_key

audiokit/core/config.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,29 @@
88
import os
99
from pathlib import Path
1010
from typing import Optional, Dict, Any
11+
from dotenv import load_dotenv
1112

1213
from .logging import get_logger
1314

15+
# Load environment variables from .env file
16+
load_dotenv()
17+
1418
logger = get_logger(__name__)
1519

1620
class Config:
1721
"""Global configuration settings."""
1822

1923
def __init__(self):
2024
"""Initialize configuration with environment variables."""
21-
self.log_level = os.getenv("AUDIOKIT_LOG_LEVEL", "INFO")
22-
self.log_file = os.getenv("AUDIOKIT_LOG_FILE")
23-
self.models_dir = os.getenv("AUDIOKIT_MODELS_DIR", "models")
24-
self.output_dir = os.getenv("AUDIOKIT_OUTPUT_DIR", "output")
25-
self.temp_dir = os.getenv("AUDIOKIT_TEMP_DIR", "temp")
25+
self.log_level = self.get("AUDIOKIT_LOG_LEVEL", "INFO")
26+
self.log_file = self.get("AUDIOKIT_LOG_FILE")
27+
self.models_dir = self.get("AUDIOKIT_MODELS_DIR", "models")
28+
self.output_dir = self.get("AUDIOKIT_OUTPUT_DIR", "output")
29+
self.temp_dir = self.get("AUDIOKIT_TEMP_DIR", "temp")
2630

2731
# API credentials
28-
self.soundcharts_app_id = os.getenv("SOUNDCHARTS_APP_ID")
29-
self.soundcharts_api_key = os.getenv("SOUNDCHARTS_API_KEY")
32+
self.soundcharts_app_id = self.get("SOUNDCHARTS_APP_ID")
33+
self.soundcharts_api_key = self.get("SOUNDCHARTS_API_KEY")
3034

3135
# Create necessary directories
3236
self._setup_directories()
@@ -62,5 +66,16 @@ def to_dict(self) -> Dict[str, Any]:
6266
"temp_dir": self.temp_dir
6367
}
6468

69+
@staticmethod
70+
def get(key: str, default: Optional[str] = None) -> Optional[str]:
71+
"""Get configuration value from environment."""
72+
return os.getenv(key, default)
73+
74+
@staticmethod
75+
def get_bool(key: str, default: bool = False) -> bool:
76+
"""Get boolean configuration value."""
77+
value = os.getenv(key, str(default)).lower()
78+
return value in ('true', '1', 't', 'y', 'yes')
79+
6580
# Global configuration instance
6681
config = Config()

audiokit/core/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ class ModelError(AudioKitError):
2727

2828
class ConfigurationError(AudioKitError):
2929
"""Raised when there are configuration issues."""
30+
pass
31+
32+
class IndexingError(AudioKitError):
33+
"""Raised when there are issues with audio indexing and search operations."""
3034
pass

audiokit/core/indexing.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from datetime import datetime
1212

1313
import pinecone
14+
from dotenv import load_dotenv
1415

15-
# NEW: Top-level imports for llama_index 0.12.x
16-
from llama_index import VectorStoreIndex, Document, StorageContext
17-
from llama_index.vector_stores import PineconeVectorStore
16+
from llama_index.core import VectorStoreIndex, Document, StorageContext
17+
from llama_index.vector_stores.pinecone import PineconeVectorStore
1818

1919
from .logging import get_logger
2020
from .exceptions import IndexingError
21+
from .config import config
2122

2223
logger = get_logger(__name__)
2324

@@ -29,8 +30,8 @@ def __init__(self):
2930
try:
3031
# Initialize Pinecone
3132
pinecone.init(
32-
api_key=os.getenv("PINECONE_API_KEY"),
33-
environment=os.getenv("PINECONE_ENV")
33+
api_key=config.get("PINECONE_API_KEY"),
34+
environment=config.get("PINECONE_ENV")
3435
)
3536

3637
# Get or create index

audiokit/core/logging.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Optional, Dict, Any
1111

1212
from loguru import logger
13+
from .config import config
1314

1415
# Remove default handler
1516
logger.remove()
@@ -91,4 +92,9 @@ def handle_exception(exc_type, exc_value, exc_traceback):
9192
)
9293

9394
# Install global exception handler
94-
sys.excepthook = handle_exception
95+
sys.excepthook = handle_exception
96+
97+
def setup_logging():
98+
log_level = config.get("AUDIOKIT_LOG_LEVEL", "INFO")
99+
log_file = config.get("AUDIOKIT_LOG_FILE")
100+
# ... rest of the logging setup ...

justfile

-33
This file was deleted.

poetry.lock

+65-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+4-9
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ repository = "https://github.com/epsilon-records/audiokit"
1010
documentation = "https://github.com/epsilon-records/audiokit/docs"
1111

1212
[tool.poetry.dependencies]
13-
python = "^3.12"
13+
python = ">=3.12,<3.13"
1414
loguru = "^0.7.2"
1515
torch = "^2.2.0"
1616
torchaudio = "^2.2.0"
1717
numpy = "^1.26.0"
1818
llama-index = "0.12.15"
19+
llama-index-vector-stores-pinecone = "0.4.4"
1920
pinecone-client = "^3.1.0"
2021
openai = "^1.12.0"
2122
typer = "^0.9.0"
2223
rich = "^13.7.0"
2324
soundfile = "^0.12.1"
25+
python-dotenv = "^1.0.0"
2426

2527
[tool.poetry.group.test.dependencies]
2628
pytest = "^8.0.0"
@@ -58,11 +60,4 @@ no_implicit_optional = true
5860
warn_redundant_casts = true
5961
warn_unused_ignores = true
6062
warn_no_return = true
61-
warn_unreachable = true
62-
63-
[project]
64-
dependencies = [
65-
"llama-index>=0.12.15", # Or the latest version from the GitHub repo
66-
"pinecone-client>=2.2.2",
67-
# other dependencies...
68-
]
63+
warn_unreachable = true

0 commit comments

Comments
 (0)