Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions gentopia/memory/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
)
from gentopia.memory.utils import get_from_dict_or_env

from enum import Enum

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -156,6 +158,9 @@ async def _async_embed_with_retry(**kwargs: Any) -> Any:

return await _async_embed_with_retry(**kwargs)

class SpecialAllow:
class ValueField(str, Enum):
VALID_VALUE = "all"

class OpenAIEmbeddings(BaseModel, Embeddings):
"""Wrapper around OpenAI embedding models."""
Expand All @@ -173,8 +178,8 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
embedding_ctx_length: int = 8191
openai_api_key: Optional[str] = None
openai_organization: Optional[str] = None
allowed_special: Union[Literal["all"], Set[str]] = set()
disallowed_special: Union[Literal["all"], Set[str], Sequence[str]] = "all"
allowed_special: Union[SpecialAllow.ValueField, Set[str]] = set()
disallowed_special: Union[SpecialAllow.ValueField, Set[str], Sequence[str]] = "all"
chunk_size: int = 1000
"""Maximum number of texts to embed in each batch"""
max_retries: int = 6
Expand Down