mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-22 00:32:49 +00:00
refactor(embedding): remove env fallbacks from BaseEmbeddingModel; pass credentials in tests
This commit is contained in:
parent
b10c41a7da
commit
1a5b64c6dc
3 changed files with 9 additions and 24 deletions
|
|
@ -6,7 +6,6 @@ Defines the abstract base class and standard API for all embedding model impleme
|
|||
import asyncio
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from abc import ABC
|
||||
from collections import OrderedDict
|
||||
|
|
@ -56,8 +55,8 @@ class BaseEmbeddingModel(ABC):
|
|||
enable_cache: Whether to enable embedding cache
|
||||
**kwargs: Additional model-specific parameters
|
||||
"""
|
||||
self._api_key: str | None = api_key
|
||||
self._base_url: str | None = base_url
|
||||
self.api_key: str | None = api_key
|
||||
self.base_url: str | None = base_url
|
||||
self.model_name = model_name
|
||||
self.dimensions = dimensions
|
||||
self.use_dimensions = use_dimensions
|
||||
|
|
@ -78,25 +77,6 @@ class BaseEmbeddingModel(ABC):
|
|||
self.cache_path: Path = Path(self.cache_dir)
|
||||
self.cache_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@property
|
||||
def api_key(self) -> str | None:
|
||||
"""Get API key from environment variable."""
|
||||
return (
|
||||
os.getenv("REME_EMBEDDING_API_KEY")
|
||||
or os.getenv("EMBEDDING_API_KEY")
|
||||
or os.getenv("OPENAI_API_KEY")
|
||||
or self._api_key
|
||||
)
|
||||
|
||||
@property
|
||||
def base_url(self) -> str | None:
|
||||
"""Get base URL from environment variable."""
|
||||
return (
|
||||
os.getenv("REME_EMBEDDING_BASE_URL")
|
||||
or os.getenv("EMBEDDING_BASE_URL")
|
||||
or self._base_url
|
||||
)
|
||||
|
||||
def _truncate_text(self, text: str) -> str:
|
||||
"""Truncate text to max_input_length if it exceeds the limit."""
|
||||
if len(text) > self.max_input_length:
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ def create_file_store(store_type: str) -> BaseFileStore:
|
|||
"""
|
||||
config = TestConfig()
|
||||
|
||||
# Initialize embedding model (api_key/base_url from env: EMBEDDING_* or OPENAI_API_KEY)
|
||||
# api_key/base_url from env (same as Application.embedding_api_key in application.py)
|
||||
embedding_api_key = os.environ.get("EMBEDDING_API_KEY") or os.environ.get("OPENAI_API_KEY")
|
||||
embedding_base_url = os.environ.get("EMBEDDING_BASE_URL") or os.environ.get("OPENAI_BASE_URL")
|
||||
# use_dimensions=True so API returns 64-dim, matching collection/table schema for all backends
|
||||
|
|
|
|||
|
|
@ -278,11 +278,16 @@ def create_vector_store(store_type: str, collection_name: str) -> BaseVectorStor
|
|||
"""
|
||||
config = TestConfig()
|
||||
|
||||
# Initialize embedding model (use_dimensions=True so API output matches HNSW dim / vector column)
|
||||
# api_key/base_url from env (Application layer does the same via embedding_api_key in application.py)
|
||||
embedding_api_key = os.environ.get("EMBEDDING_API_KEY") or os.environ.get("OPENAI_API_KEY")
|
||||
embedding_base_url = os.environ.get("EMBEDDING_BASE_URL") or os.environ.get("OPENAI_BASE_URL")
|
||||
# use_dimensions=True so API output matches HNSW dim / vector column
|
||||
embedding_model = OpenAIEmbeddingModel(
|
||||
model_name=config.EMBEDDING_MODEL_NAME,
|
||||
dimensions=config.EMBEDDING_DIMENSIONS,
|
||||
use_dimensions=True,
|
||||
api_key=embedding_api_key or None,
|
||||
base_url=embedding_base_url or None,
|
||||
)
|
||||
|
||||
if store_type == "local":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue