Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions jigsawstack/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class KVAddParams(TypedDict):
key: str
value: str
encrypt: NotRequired[bool]
byo_secret: NotRequired[str]


class KVAddResponse(TypedDict):
Expand Down
25 changes: 21 additions & 4 deletions jigsawstack/summary.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from typing import Any, Dict, List, Union, cast
from typing import Any, Dict, List, Union, cast, Literal
from typing_extensions import NotRequired, TypedDict
from .request import Request, RequestConfig
from typing import List, Union
from ._config import ClientConfig


class SummaryParams(TypedDict):
text: str
text: NotRequired[str]
"""
The text to summarize.
"""

type: NotRequired[str]
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 SummaryResponse(TypedDict):
Expand All @@ -29,6 +33,17 @@ class SummaryResponse(TypedDict):
"""


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


class Summary(ClientConfig):

config: RequestConfig
Expand All @@ -46,7 +61,9 @@ def __init__(
disable_request_logging=disable_request_logging,
)

def summarize(self, params: SummaryParams) -> SummaryResponse:
def summarize(
self, params: SummaryParams
) -> Union[SummaryResponse, SummaryListResponse]:
path = "/ai/summary"
resp = Request(
config=self.config,
Expand Down
17 changes: 15 additions & 2 deletions jigsawstack/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TranslateParams(TypedDict):
"""
Language to translate from.
"""
text: str
text: Union[str, list[str]]
"""
The text to translate.
"""
Expand All @@ -31,6 +31,17 @@ class TranslateResponse(TypedDict):
"""


class TranslateListResponse(TypedDict):
success: bool
"""
Indicates whether the translation was successful.
"""
translated_text: List[str]
"""
The translated text.
"""


class Translate(ClientConfig):

config: RequestConfig
Expand All @@ -48,7 +59,9 @@ def __init__(
disable_request_logging=disable_request_logging,
)

def translate(self, params: TranslateParams) -> TranslateResponse:
def translate(
self, params: TranslateParams
) -> Union[TranslateResponse, TranslateListResponse]:
path = "/ai/translate"
resp = Request(
config=self.config,
Expand Down
23 changes: 13 additions & 10 deletions jigsawstack/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,29 @@ def email(self, params: EmailValidationParams) -> EmailValidationResponse:
return resp

def nsfw(self, url: str) -> NSFWResponse:
path = f"/validate/nsfw?url={url}"
path = f"/validate/nsfw"
resp = Request(
config=self.config,
path=path,
params=cast(Dict[Any, Any], params={"url": url}),
verb="get",
params=cast(
Dict[Any, Any],
params={"url": url},
),
verb="post",
).perform_with_content()
return resp

def profanity(self, params: ProfanityParams) -> ProfanityResponse:
text = params.get("text")
censor_replacement = params.get("censor_replacement", "*")
path = (
f"/validate/profanity?text={text}&censor_replacement={censor_replacement}"
)
path = f"/validate/profanity"
resp = Request(
config=self.config,
path=path,
params=cast(Dict[Any, Any], params),
verb="get",
params=cast(
Dict[Any, Any], {"text": text, "censor_replacement": censor_replacement}
),
verb="post",
).perform_with_content()
return resp

Expand All @@ -127,12 +130,12 @@ def spellcheck(self, params: SpellCheckParams) -> SpellCheckResponse:
config=self.config,
path=path,
params=cast(Dict[Any, Any], params),
verb="get",
verb="post",
).perform_with_content()
return resp

def spamcheck(self, params: SpamCheckParams) -> SpamCheckResponse:
path = "/ai/spamcheck"
path = "/validate/spam_check"
resp = Request(
config=self.config,
path=path,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="jigsawstack",
version="0.1.18",
version="0.1.19",
description="JigsawStack Python SDK",
long_description=open("README.md", encoding="utf8").read(),
long_description_content_type="text/markdown",
Expand Down