Skip to content

Commit

Permalink
chore: Add AsyncEmbeddings and Embeddings resources for text embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
herumes committed Jun 6, 2024
1 parent a1aa85b commit 4aae2f4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions shuttleai/client/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(
self.images: resources.AsyncImages = resources.AsyncImages(self)
self.audio: resources.AsyncAudio = resources.AsyncAudio(self)
self.moderations: resources.AsyncModerations = resources.AsyncModerations(self)
self.embeddings: resources.AsyncEmbeddings = resources.AsyncEmbeddings(self)

async def __aenter__(self) -> "AsyncShuttleAI":
if self._session is None:
Expand Down
1 change: 1 addition & 0 deletions shuttleai/client/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(
self.images: resources.Images = resources.Images(self)
self.audio: resources.Audio = resources.Audio(self)
self.moderations: resources.Moderations = resources.Moderations(self)
self.embeddings: resources.Embeddings = resources.Embeddings(self)

def __del__(self) -> None:
self._http_client.close()
Expand Down
3 changes: 3 additions & 0 deletions shuttleai/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .chat.completions import AsyncChat, Chat
from .images.generations import AsyncImages, Images
from .moderations import AsyncModerations, Moderations
from .embeddings import AsyncEmbeddings, Embeddings

__all__ = [
"AsyncChat",
Expand All @@ -12,5 +13,7 @@
"Audio",
"AsyncModerations",
"Moderations",
"AsyncEmbeddings",
"Embeddings",
# Add new resources here
]
41 changes: 40 additions & 1 deletion shuttleai/resources/embeddings.py
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# TODO
from typing import Literal, Optional, Union

from shuttleai.resources.common import AsyncResource, SyncResource
from shuttleai.schemas.embeddings import EmbeddingResponse


class AsyncEmbeddings(AsyncResource):
async def create(
self,
input: str,
model: Optional[
Union[str, Literal["text-embedding-3-small", "text-embedding-3-large"]]
] = "text-embedding-3-large",
) -> EmbeddingResponse:
request = {"input": input, "model": model}

return await self.handle_request( # type: ignore
method="post",
endpoint="v1/embeddings",
request_data=request,
response_cls=EmbeddingResponse,
)


class Embeddings(SyncResource):
def create(
self,
input: str,
model: Optional[
Union[str, Literal["text-embedding-3-small", "text-embedding-3-large"]]
] = "text-embedding-3-large",
) -> EmbeddingResponse:
request = {"input": input, "model": model}

return self.handle_request( # type: ignore
method="post",
endpoint="v1/embeddings",
request_data=request,
response_cls=EmbeddingResponse,
)

0 comments on commit 4aae2f4

Please sign in to comment.