Skip to content

Commit 3f154fc

Browse files
committed
Refactor
1 parent 74d79b4 commit 3f154fc

7 files changed

+51
-7
lines changed
52 KB
Binary file not shown.

DEVELOPMENT.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,23 @@ To trigger a manual build:
1919
PINECONE_API_KEY=your-api-key
2020
PINECONE_INDEX_NAME=audiokit-brain
2121
```
22-
3. Ensure the `.env` file is not committed to version control
22+
3. Ensure the `.env` file is not committed to version control
23+
24+
## Testing Requirements
25+
26+
To run the tests, you'll need:
27+
28+
1. OpenRouter API Key
29+
- Create an account at https://openrouter.ai
30+
- Generate an API key
31+
- Add it to your `.env` file as `OPENROUTER_API_KEY`
32+
- Choose a model and add it as `OPENROUTER_MODEL` (e.g., `openai/gpt-4`)
33+
34+
2. Pinecone API Key
35+
- Create an account at https://www.pinecone.io
36+
- Generate an API key
37+
- Add it to your `.env` file as `PINECONE_API_KEY`
38+
39+
3. Create a Pinecone index
40+
- Create an index in your Pinecone dashboard
41+
- Add the index name to your `.env` file as `PINECONE_INDEX_NAME`

audiokit/core/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def __init__(self):
3737
logger.debug(f"Pinecone API key: {'*' * 8}{self.pinecone_api_key[-4:]}" if self.pinecone_api_key else "No API key found")
3838
self.pinecone_index_name = self.get("PINECONE_INDEX_NAME")
3939

40+
# OpenRouter configuration
41+
self.openrouter_api_key = os.getenv("OPENROUTER_API_KEY")
42+
self.openrouter_model = os.getenv("OPENROUTER_MODEL", "openai/gpt-4")
43+
4044
# Create necessary directories
4145
self._setup_directories()
4246
logger.debug("Configuration initialized")

audiokit/core/indexing.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
from llama_index.core import VectorStoreIndex, Document, StorageContext
1414
from llama_index.vector_stores.pinecone import PineconeVectorStore
15+
from llama_index.llms import OpenRouter
16+
from llama_index.embeddings import OpenRouterEmbedding
1517

1618
from .logging import get_logger
1719
from .exceptions import IndexingError, ConfigurationError
@@ -49,10 +51,13 @@ def __init__(self):
4951
storage_context = StorageContext.from_defaults(vector_store=vector_store)
5052

5153
logger.debug("Initializing vector store index")
54+
llm = OpenRouter(api_key=config.openrouter_api_key, model=config.openrouter_model)
55+
embed_model = OpenRouterEmbedding(api_key=config.openrouter_api_key, model=config.openrouter_model)
56+
5257
self.index = VectorStoreIndex.from_documents(
53-
[],
54-
storage_context=storage_context,
55-
show_progress=True
58+
documents=[],
59+
llm=llm,
60+
embed_model=embed_model
5661
)
5762

5863
logger.info("Audio index initialized successfully")

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ addopts = "-v --cov=audiokit --cov-report=term-missing"
4848
testpaths = [
4949
"tests",
5050
]
51+
log_cli = true
52+
log_level = "INFO"
5153

5254
[tool.mypy]
5355
python_version = "3.12"

tests/conftest.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,28 @@
99
import pytest
1010
from pathlib import Path
1111
from dotenv import load_dotenv
12+
from loguru import logger
1213

1314
# Load environment variables before any tests run
1415
load_dotenv()
1516

1617
@pytest.fixture(scope="session", autouse=True)
17-
def load_env():
18-
"""Ensure environment variables are loaded for all tests."""
19-
pass
18+
def log_api_keys():
19+
"""Log API keys used in tests."""
20+
logger.debug("log_api_keys fixture is running")
21+
from audiokit.core.config import config
22+
logger.info("Using Pinecone API key: {}", config.pinecone_api_key)
23+
logger.info("Using Pinecone index: {}", config.pinecone_index_name)
24+
logger.info("Using OpenRouter API key: {}", config.openrouter_api_key)
25+
yield
26+
27+
@pytest.fixture(scope="session", autouse=True)
28+
def setup_openrouter():
29+
"""Setup OpenRouter configuration for tests."""
30+
from audiokit.core.config import config
31+
if not config.openrouter_api_key:
32+
pytest.skip("OpenRouter API key is required for these tests")
33+
yield
2034

2135
@pytest.fixture
2236
def fixture_dir() -> Path:
File renamed without changes.

0 commit comments

Comments
 (0)