Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
natehouk committed Feb 2, 2025
1 parent 8fe1bf6 commit 795d77d
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 57 deletions.
16 changes: 16 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Pinecone configuration
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_ENV=your_pinecone_environment

# Logging configuration
AUDIOKIT_LOG_LEVEL=INFO
AUDIOKIT_LOG_FILE=logs/audiokit.log

# Directory configuration
AUDIOKIT_MODELS_DIR=models
AUDIOKIT_OUTPUT_DIR=output
AUDIOKIT_TEMP_DIR=temp

# Soundcharts API (optional)
SOUNDCHARTS_APP_ID=your_app_id
SOUNDCHARTS_API_KEY=your_api_key
29 changes: 22 additions & 7 deletions audiokit/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@
import os
from pathlib import Path
from typing import Optional, Dict, Any
from dotenv import load_dotenv

from .logging import get_logger

# Load environment variables from .env file
load_dotenv()

logger = get_logger(__name__)

class Config:
"""Global configuration settings."""

def __init__(self):
"""Initialize configuration with environment variables."""
self.log_level = os.getenv("AUDIOKIT_LOG_LEVEL", "INFO")
self.log_file = os.getenv("AUDIOKIT_LOG_FILE")
self.models_dir = os.getenv("AUDIOKIT_MODELS_DIR", "models")
self.output_dir = os.getenv("AUDIOKIT_OUTPUT_DIR", "output")
self.temp_dir = os.getenv("AUDIOKIT_TEMP_DIR", "temp")
self.log_level = self.get("AUDIOKIT_LOG_LEVEL", "INFO")
self.log_file = self.get("AUDIOKIT_LOG_FILE")
self.models_dir = self.get("AUDIOKIT_MODELS_DIR", "models")
self.output_dir = self.get("AUDIOKIT_OUTPUT_DIR", "output")
self.temp_dir = self.get("AUDIOKIT_TEMP_DIR", "temp")

# API credentials
self.soundcharts_app_id = os.getenv("SOUNDCHARTS_APP_ID")
self.soundcharts_api_key = os.getenv("SOUNDCHARTS_API_KEY")
self.soundcharts_app_id = self.get("SOUNDCHARTS_APP_ID")
self.soundcharts_api_key = self.get("SOUNDCHARTS_API_KEY")

# Create necessary directories
self._setup_directories()
Expand Down Expand Up @@ -62,5 +66,16 @@ def to_dict(self) -> Dict[str, Any]:
"temp_dir": self.temp_dir
}

@staticmethod
def get(key: str, default: Optional[str] = None) -> Optional[str]:
"""Get configuration value from environment."""
return os.getenv(key, default)

@staticmethod
def get_bool(key: str, default: bool = False) -> bool:
"""Get boolean configuration value."""
value = os.getenv(key, str(default)).lower()
return value in ('true', '1', 't', 'y', 'yes')

# Global configuration instance
config = Config()
4 changes: 4 additions & 0 deletions audiokit/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ class ModelError(AudioKitError):

class ConfigurationError(AudioKitError):
"""Raised when there are configuration issues."""
pass

class IndexingError(AudioKitError):
"""Raised when there are issues with audio indexing and search operations."""
pass
11 changes: 6 additions & 5 deletions audiokit/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from datetime import datetime

import pinecone
from dotenv import load_dotenv

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

from .logging import get_logger
from .exceptions import IndexingError
from .config import config

logger = get_logger(__name__)

Expand All @@ -29,8 +30,8 @@ def __init__(self):
try:
# Initialize Pinecone
pinecone.init(
api_key=os.getenv("PINECONE_API_KEY"),
environment=os.getenv("PINECONE_ENV")
api_key=config.get("PINECONE_API_KEY"),
environment=config.get("PINECONE_ENV")
)

# Get or create index
Expand Down
8 changes: 7 additions & 1 deletion audiokit/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Optional, Dict, Any

from loguru import logger
from .config import config

# Remove default handler
logger.remove()
Expand Down Expand Up @@ -91,4 +92,9 @@ def handle_exception(exc_type, exc_value, exc_traceback):
)

# Install global exception handler
sys.excepthook = handle_exception
sys.excepthook = handle_exception

def setup_logging():
log_level = config.get("AUDIOKIT_LOG_LEVEL", "INFO")
log_file = config.get("AUDIOKIT_LOG_FILE")
# ... rest of the logging setup ...
33 changes: 0 additions & 33 deletions justfile

This file was deleted.

67 changes: 65 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ repository = "https://github.com/epsilon-records/audiokit"
documentation = "https://github.com/epsilon-records/audiokit/docs"

[tool.poetry.dependencies]
python = "^3.12"
python = ">=3.12,<3.13"
loguru = "^0.7.2"
torch = "^2.2.0"
torchaudio = "^2.2.0"
numpy = "^1.26.0"
llama-index = "0.12.15"
llama-index-vector-stores-pinecone = "0.4.4"
pinecone-client = "^3.1.0"
openai = "^1.12.0"
typer = "^0.9.0"
rich = "^13.7.0"
soundfile = "^0.12.1"
python-dotenv = "^1.0.0"

[tool.poetry.group.test.dependencies]
pytest = "^8.0.0"
Expand Down Expand Up @@ -58,11 +60,4 @@ no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_no_return = true
warn_unreachable = true

[project]
dependencies = [
"llama-index>=0.12.15", # Or the latest version from the GitHub repo
"pinecone-client>=2.2.2",
# other dependencies...
]
warn_unreachable = true

0 comments on commit 795d77d

Please # to comment.