Skip to content

Add support for embedding generation 🚀 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Changes from 1 commit
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
Next Next commit
clean up
  • Loading branch information
iamNarcisse committed Jan 5, 2025
commit b84878ad55c54b54054e6f21adf588e3138cd43e
80 changes: 80 additions & 0 deletions jigsawstack/embedding_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from typing import Any, Dict, List, Union, cast, Literal
from typing_extensions import NotRequired, TypedDict
from .request import Request, RequestConfig
from .async_request import AsyncRequest
from typing import List, Union
from ._config import ClientConfig


class EmbeddingParams(TypedDict):
text: Union[str, List[str]]
"""
The text to summarize.
"""

type: NotRequired[Literal["text", "points"]]

"""
The summary result type. Supported values are: text, points
"""
url: NotRequired[str]
file_store_key: NotRequired[str]
max_points: NotRequired[int]
max_characters: NotRequired[int]


class EmbeddingResponse(TypedDict):
success: bool
"""
Indicates whether the translation was successful.
"""
summary: str
"""
The summarized text.
"""


class Embedding(ClientConfig):

config: RequestConfig

def __init__(
self,
api_key: str,
api_url: str,
disable_request_logging: Union[bool, None] = False,
):
super().__init__(api_key, api_url, disable_request_logging)
self.config = RequestConfig(
api_url=api_url,
api_key=api_key,
disable_request_logging=disable_request_logging,
)


class AsyncEmbedding(ClientConfig):

config: RequestConfig

def __init__(
self,
api_key: str,
api_url: str,
disable_request_logging: Union[bool, None] = False,
):
super().__init__(api_key, api_url, disable_request_logging)
self.config = RequestConfig(
api_url=api_url,
api_key=api_key,
disable_request_logging=disable_request_logging,
)

async def execute(self, params: EmbeddingParams) -> EmbeddingResponse:
path = "/ai/embedding"
resp = await AsyncRequest(
config=self.config,
path=path,
params=cast(Dict[Any, Any], params),
verb="post",
).perform_with_content()
return resp