Skip to content

Commit

Permalink
[Multimodal] Revise dependency versions (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenhong authored Nov 2, 2024
1 parent 2e87296 commit 19dda2e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[tool.poetry]
name = "voyageai"
version = "0.3.0rc0"
version = "0.3.0"
description = ""
authors = ["Yujie Qian <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.7.1"
requests = "^2.20"
aiohttp = "^3.5"
tenacity = ">=8.0.1"
numpy = ">=1.11"
aiolimiter = "^1.1.0"
pillow = "^9.5.0"
pydantic = "^2.5.3"
tokenizers = "^0.20.0"
python = "^3.9,<3.13"
requests = "*"
aiohttp = "*"
tenacity = "*"
oldest-supported-numpy = "*"
aiolimiter = "*"
pillow = "*"
pydantic = ">=1.10.8"
tokenizers = ">=0.14.0"

[tool.poetry.group.test.dependencies]
pytest = "^7.4.2"
pytest-asyncio = "^0.21.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
build-backend = "poetry.core.masonry.api"
4 changes: 2 additions & 2 deletions tests/test_client_multimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def embedding_dimension():

sample_input_list_text_01 = ["this is an image of a blue sailboat on a lake."]

sample_input_list_img_01 = [Image.open("example_image_01.jpg")]
sample_input_list_img_01 = [Image.open("tests/example_image_01.jpg")]

sample_input_list_img_02 = [Image.open("example_image_01.jpg").resize((256, 256))]
sample_input_list_img_02 = [Image.open("tests/example_image_01.jpg").resize((256, 256))]

sample_input_list_img_03 = [Image.new("L", (400, 400), color=128)]

Expand Down
21 changes: 15 additions & 6 deletions voyageai/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import voyageai
import voyageai.error as error
from voyageai.object.multimodal_embeddings import MultimodalInputRequest, MultimodalInputSegmentText, \
MultimodalInputSegmentImageURL, MultimodalInputSegmentImageBase64
MultimodalInputSegmentImageURL, MultimodalInputSegmentImageBase64, MultimodalEmbeddingsObject
from voyageai.util import default_api_key
from voyageai.object import EmbeddingsObject, RerankingObject

Expand All @@ -35,7 +35,7 @@ def _get_client_config(
return data_dict


class _BaseClient:
class _BaseClient(ABC):
"""Voyage AI Client
Args:
Expand All @@ -58,15 +58,14 @@ def __init__(
"request_timeout": timeout,
}


@abstractmethod
def embed(
self,
texts: List[str],
model: Optional[str] = None,
input_type: Optional[str] = None,
truncation: bool = True,
) -> Union[EmbeddingsObject, Awaitable[EmbeddingsObject]]:
) -> EmbeddingsObject:
pass

@abstractmethod
Expand All @@ -77,7 +76,17 @@ def rerank(
model: str,
top_k: Optional[int] = None,
truncation: bool = True,
) -> Union[RerankingObject, Awaitable[RerankingObject]]:
) -> RerankingObject:
pass

@abstractmethod
def multimodal_embed(
self,
inputs: Union[List[Dict], List[List[Union[str, PIL.Image.Image]]]],
model: str,
input_type: Optional[str] = None,
truncation: bool = True,
) -> MultimodalEmbeddingsObject:
pass

@functools.lru_cache()
Expand Down Expand Up @@ -130,7 +139,7 @@ def count_usage(
self,
inputs: Union[List[Dict], List[List[Union[str, PIL.Image.Image]]]],
model: str,
) -> dict[str, int]:
) -> Dict[str, int]:
"""
This method returns estimated usage metrics for the provided input.
Currently, only multimodal models are supported. Image URL segments are not supported.
Expand Down
2 changes: 1 addition & 1 deletion voyageai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def multimodal_embed(
model=model,
input_type=input_type,
truncation=truncation,
).model_dump(),
).dict(),
**self._params,
)

Expand Down
2 changes: 1 addition & 1 deletion voyageai/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def multimodal_embed(
model=model,
input_type=input_type,
truncation=truncation,
).model_dump(),
).dict(),
**self._params,
)

Expand Down
9 changes: 6 additions & 3 deletions voyageai/object/multimodal_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import PIL.ImageFile
from io import BytesIO
from enum import Enum
from pydantic import BaseModel, Field, Extra, ValidationError
from typing import List, Optional, Union, Dict, Literal, Annotated

from voyageai import error
from voyageai.api_resources import VoyageResponse

try:
from pydantic.v1 import BaseModel, Field, Extra, ValidationError
except ImportError:
from pydantic import BaseModel, Field, Extra, ValidationError

class MultimodalEmbeddingsObject:
def __init__(self, response: Optional[VoyageResponse] = None):
Expand Down Expand Up @@ -74,7 +77,7 @@ class MultimodalInput(BaseModel):
],
Field(discriminator="type"),
]
] = Field(..., min_length=1)
] = Field(..., min_items=1)


class MultimodalInputRequest(BaseModel):
Expand Down Expand Up @@ -167,7 +170,7 @@ def _process_dict_input(cls, input_data: Dict, idx: int) -> MultimodalInput:
raise ValueError(f"Input at index {idx} is missing the 'content' field.")

try:
return MultimodalInput.model_validate(input_data)
return MultimodalInput.parse_obj(input_data)
except ValidationError as ve:
raise ValueError(f"Validation error for input at index {idx}: {ve}") from ve

Expand Down

0 comments on commit 19dda2e

Please sign in to comment.