-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(embedding): add litellm embeddings (#37)
- Loading branch information
Showing
19 changed files
with
248 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .base import EmbeddingClient | ||
from .litellm import LiteLLMEmbeddingClient | ||
|
||
__all__ = ["EmbeddingClient", "LiteLLMEmbeddingClient"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from .._exceptions import DbAllyError | ||
|
||
|
||
class EmbeddingError(DbAllyError): | ||
""" | ||
Base class for all exceptions raised by the EmbeddingClient. | ||
""" | ||
|
||
def __init__(self, message: str) -> None: | ||
super().__init__(message) | ||
self.message = message | ||
|
||
|
||
class EmbeddingConnectionError(EmbeddingError): | ||
""" | ||
Raised when there is an error connecting to the embedding API. | ||
""" | ||
|
||
def __init__(self, message: str = "Connection error.") -> None: | ||
super().__init__(message) | ||
|
||
|
||
class EmbeddingStatusError(EmbeddingError): | ||
""" | ||
Raised when an API response has a status code of 4xx or 5xx. | ||
""" | ||
|
||
def __init__(self, message: str, status_code: int) -> None: | ||
super().__init__(message) | ||
self.status_code = status_code | ||
|
||
|
||
class EmbeddingResponseError(EmbeddingError): | ||
""" | ||
Raised when an API response has an invalid schema. | ||
""" | ||
|
||
def __init__(self, message: str = "Data returned by API invalid for expected schema.") -> None: | ||
super().__init__(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List | ||
|
||
|
||
class EmbeddingClient(ABC): | ||
""" | ||
Abstract client for creating text embeddings. | ||
""" | ||
|
||
@abstractmethod | ||
async def get_embeddings(self, data: List[str]) -> List[List[float]]: | ||
""" | ||
Creates embeddings for the given strings. | ||
Args: | ||
data: List of strings to get embeddings for. | ||
Returns: | ||
List of embeddings for the given strings. | ||
""" |
Oops, something went wrong.