Skip to content

Commit e328a08

Browse files
committed
Clean up
1 parent 9932e3b commit e328a08

35 files changed

+309
-395
lines changed

jigsawstack/__init__.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,63 @@
11

2-
from ._client import JigsawStack
2+
from typing import Union
3+
import os
4+
from .audio import Audio
5+
from .vision import Vision
6+
from .search import Search
7+
from .prediction import Prediction
8+
from .sql import SQL
9+
from .store import KV, File
10+
from .translate import Translate
11+
from .web import Web
12+
from .sentiment import Sentiment
13+
from .validate import Validate
14+
from .summary import Summary
15+
16+
class JigsawStack:
17+
audio: Audio
18+
vision : Vision
19+
prediction: Prediction
20+
sql: SQL
21+
file: File
22+
kv: KV
23+
translate: Translate
24+
web: Web
25+
sentiment: Sentiment
26+
validate: Validate
27+
summary: Summary
28+
search: Search
29+
api_key: str
30+
api_url: str
31+
32+
33+
def __init__(self, api_key: Union[str, None] = None, api_url: Union[str, None] = None) -> None:
34+
if api_key is None:
35+
api_key = os.environ.get("JIGSAWSTACK_API_KEY")
36+
37+
if api_key is None:
38+
raise ValueError("The api_key client option must be set either by passing api_key to the client or by setting the JIGSAWSTACK_API_KEY environment variable")
39+
40+
if api_url is None:
41+
api_url = os.environ.get("JIGSAWSTACK_API_URL")
42+
if api_url is None:
43+
api_url = f"https://api.jigsawstack.com/v1"
44+
45+
self.api_key = api_key
46+
self.api_url = api_url
47+
48+
49+
self.audio = Audio(api_key=api_key, api_url=api_url)
50+
self.web = Web(api_key=api_key, api_url=api_url)
51+
self.search = Search(api_key=api_key, api_url=api_url)
52+
self.sentiment = Sentiment(api_key=api_key, api_url=api_url)
53+
self.validate = Validate(api_key=api_key, api_url=api_url)
54+
self.summary = Summary(api_key=api_key, api_url=api_url)
55+
self.vision = Vision(api_key=api_key, api_url=api_url)
56+
self.prediction = Prediction(api_key=api_key, api_url=api_url)
57+
self.sql = SQL(api_key=api_key, api_url=api_url)
58+
self.file = File(api_key=api_key, api_url=api_url)
59+
self.kv = KV(api_key=api_key, api_url=api_url)
60+
self.translate = Translate(api_key=api_key, api_url=api_url)
361

462
# Create a global instance of the Web class
563
__all__ = ["JigsawStack"]

jigsawstack/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import os
33
from .audio import Audio
44
from .vision import Vision
5-
from .search import Search
6-
from .prediction import Prediction
5+
from .searchs import Search
6+
from .predictions import Prediction
77
from .sql import SQL
88
from .store import KV, File
99
from .translate import Translate

jigsawstack/audio.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from typing import Any, Dict, List, cast
2+
from typing_extensions import NotRequired, TypedDict
3+
from .request import Request
4+
from ._config import ClientConfig
5+
from typing import Any, Dict, List, cast
6+
from typing_extensions import NotRequired, TypedDict
7+
8+
class SpeechToTextParams(TypedDict):
9+
url:str
10+
file_store_key : NotRequired[str]
11+
language : NotRequired[str]
12+
translate : NotRequired[bool]
13+
by_speaker : NotRequired[bool]
14+
webhook_url : NotRequired[str]
15+
16+
class SpeechToTextResponse(TypedDict):
17+
success:bool
18+
text : str
19+
chunks : List[object]
20+
21+
22+
class Audio(ClientConfig):
23+
def speech_to_text(self, params: SpeechToTextParams) -> SpeechToTextResponse:
24+
path = "/ai/transcribe"
25+
resp = Request(
26+
api_key=self.api_key,
27+
api_url=self.api_url,
28+
path=path, params=cast(Dict[Any, Any], params), verb="post"
29+
).perform_with_content()
30+
return resp

jigsawstack/audio/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

jigsawstack/audio/_audio.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

jigsawstack/audio/audio.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

jigsawstack/prediction/_prediction.py renamed to jigsawstack/prediction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from ..request import Request
3+
from .request import Request
44
from typing import List, Union
5-
from .._config import ClientConfig
5+
from ._config import ClientConfig
66

77

88
class Dataset(TypedDict):

jigsawstack/prediction/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

jigsawstack/request.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ def make_request(self, url: str) -> requests.Response:
105105
headers = self.__get_headers()
106106
params = self.params
107107
verb = self.verb
108-
109-
print("ABOUT TO MAKE REQUEST WITH HEADERS",headers)
110108
try:
111109
return requests.request(verb, url, json=params, headers=headers,)
112110
except requests.HTTPError as e:

jigsawstack/search/_search.py renamed to jigsawstack/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from ..request import Request
3+
from .request import Request
44
from typing_extensions import NotRequired, TypedDict
5-
from .._config import ClientConfig
5+
from ._config import ClientConfig
66

77

88
class SearchAIResponse(TypedDict):

jigsawstack/search/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

jigsawstack/sentiment/_sentiment.py renamed to jigsawstack/sentiment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from ..request import Request
3+
from .request import Request
44
from typing import List, Union
5-
from .._config import ClientConfig
5+
from ._config import ClientConfig
66

77

88
class SentimentParams(TypedDict):

jigsawstack/sentiment/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

jigsawstack/sql/_sql.py renamed to jigsawstack/sql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from ..request import Request
3+
from .request import Request
44
from typing import List, Union
5-
from .._config import ClientConfig
5+
from ._config import ClientConfig
66

77

88
class SQLParams(TypedDict):

jigsawstack/sql/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

jigsawstack/store.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from typing import Any, Dict, List, cast
2+
from typing_extensions import NotRequired, TypedDict
3+
from .request import Request
4+
from ._config import ClientConfig
5+
from typing import Any, Dict, List, cast
6+
from typing_extensions import NotRequired, TypedDict
7+
8+
class FileDeleteResponse(TypedDict):
9+
success:bool
10+
11+
12+
class KVGetParams(TypedDict):
13+
key:str
14+
15+
class KVGetResponse(TypedDict):
16+
success:bool
17+
value : str
18+
19+
class KVAddParams(TypedDict):
20+
key:str
21+
value :str
22+
encrypt : NotRequired[bool]
23+
24+
class KVAddResponse(TypedDict):
25+
success:bool
26+
27+
28+
29+
class File(ClientConfig):
30+
31+
32+
def get(self, key: str) -> Any:
33+
path =f"/store/file/{key}"
34+
resp = Request(
35+
api_key=self.api_key,
36+
api_url=self.api_url,
37+
path=path, params=cast(Dict[Any, Any], params={}), verb="get"
38+
).perform_with_content()
39+
return resp
40+
41+
def delete(self, key: str) -> FileDeleteResponse:
42+
path =f"/store/file/{key}"
43+
resp = Request(
44+
api_key=self.api_key,
45+
api_url=self.api_url,
46+
path=path, params=cast(Dict[Any, Any], params={}), verb="delete"
47+
).perform_with_content()
48+
return resp
49+
50+
51+
class KV(ClientConfig):
52+
53+
def add(self, params: KVAddParams) -> KVAddResponse:
54+
path = "/store/kv"
55+
resp = Request(
56+
api_key=self.api_key,
57+
api_url=self.api_url,
58+
path=path, params=cast(Dict[Any, Any], params), verb="post"
59+
).perform_with_content()
60+
return resp
61+
62+
def get(self, key: str) -> KVGetResponse:
63+
path =f"/store/kv/{key}"
64+
resp = Request(
65+
api_key=self.api_key,
66+
api_url=self.api_url,
67+
path=path, params=cast(Dict[Any, Any], params={}), verb="get"
68+
).perform_with_content()
69+
return resp
70+
71+
72+
def delete(self, key: str) -> KVGetResponse:
73+
path =f"/store/kv/{key}"
74+
resp = Request(
75+
api_key=self.api_key,
76+
api_url=self.api_url,
77+
path=path, params=cast(Dict[Any, Any], params={}), verb="delete"
78+
).perform_with_content()
79+
return resp

jigsawstack/store/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

jigsawstack/store/_file.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

jigsawstack/store/_kv.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

jigsawstack/store/file.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)