Skip to content

Commit 0af8878

Browse files
authored
Merge pull request #3 from JigsawStack/cleanup
Cleanup
2 parents 0c0f761 + c4603c6 commit 0af8878

40 files changed

+364
-486
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pip install jigsawstack
1313
First, you need to get an API key, which is available in the [JigsawStack Dashboard](https://jigsawstack.com).
1414

1515
```py
16-
from jigsawstack from JigsawStack
16+
from jigsawstack import JigsawStack
1717

1818
import os
1919

@@ -24,7 +24,7 @@ import os
2424

2525
```py
2626
import os
27-
from jigsawstack from JigsawStack
27+
from jigsawstack import JigsawStack
2828

2929

3030
ai = JigsawStack(api_key="your-api-key")

jigsawstack/__init__.py

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,63 @@
1+
2+
from typing import Union
13
import os
2-
from ._client import JigsawStack
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
347

4-
# Config vars
5-
api_key = os.environ.get("JIGSAWSTACK_API_KEY", "")
6-
api_url = os.environ.get("JIGSAWSTACK_API_URL", "https://api.jigsawstack.com")
748

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)
861

962
# Create a global instance of the Web class
1063
__all__ = ["JigsawStack"]

jigsawstack/_client.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
2-
from . import resources
31
from typing import Union
4-
from ._config import ClientConfig
52
import os
6-
3+
from .audio import Audio
4+
from .vision import Vision
5+
from .searchs import Search
6+
from .predictions import Prediction
7+
from .sql import SQL
8+
from .store import KV, File
9+
from .translate import Translate
10+
from .web import Web
11+
from .sentiment import Sentiment
12+
from .validate import Validate
13+
from .summary import Summary
714

815
class JigsawStack:
9-
audio: resources.Audio
10-
vision : resources.Vision
11-
prediction: resources.Prediction
12-
sql: resources.SQL
13-
file: resources.File
14-
kv: resources.KV
15-
translate: resources.Translate
16-
web: resources.Web
17-
sentiment: resources.Sentiment
18-
validate: resources.Validate
19-
summary: resources.Summary
20-
search: resources.Search
16+
audio: Audio
17+
vision : Vision
18+
prediction: Prediction
19+
sql: SQL
20+
file: File
21+
kv: KV
22+
translate: Translate
23+
web: Web
24+
sentiment: Sentiment
25+
validate: Validate
26+
summary: Summary
27+
search: Search
2128
api_key: str
2229
api_url: str
2330

@@ -38,15 +45,15 @@ def __init__(self, api_key: Union[str, None] = None, api_url: Union[str, None] =
3845
self.api_url = api_url
3946

4047

41-
self.audio = resources.Audio(api_key=api_key, api_url=api_url)
42-
self.web = resources.Web(api_key=api_key, api_url=api_url)
43-
self.search = resources.Search(api_key=api_key, api_url=api_url)
44-
self.sentiment = resources.Sentiment(api_key=api_key, api_url=api_url)
45-
self.validate = resources.Validate(api_key=api_key, api_url=api_url)
46-
self.summary = resources.Summary(api_key=api_key, api_url=api_url)
47-
self.vision = resources.Vision(api_key=api_key, api_url=api_url)
48-
self.prediction = resources.Prediction(api_key=api_key, api_url=api_url)
49-
self.sql = resources.SQL(api_key=api_key, api_url=api_url)
50-
self.file = resources.File(api_key=api_key, api_url=api_url)
51-
self.kv = resources.KV(api_key=api_key, api_url=api_url)
52-
self.translate = resources.Translate(api_key=api_key, api_url=api_url)
48+
self.audio = Audio(api_key=api_key, api_url=api_url)
49+
self.web = Web(api_key=api_key, api_url=api_url)
50+
self.search = Search(api_key=api_key, api_url=api_url)
51+
self.sentiment = Sentiment(api_key=api_key, api_url=api_url)
52+
self.validate = Validate(api_key=api_key, api_url=api_url)
53+
self.summary = Summary(api_key=api_key, api_url=api_url)
54+
self.vision = Vision(api_key=api_key, api_url=api_url)
55+
self.prediction = Prediction(api_key=api_key, api_url=api_url)
56+
self.sql = SQL(api_key=api_key, api_url=api_url)
57+
self.file = File(api_key=api_key, api_url=api_url)
58+
self.kv = KV(api_key=api_key, api_url=api_url)
59+
self.translate = Translate(api_key=api_key, api_url=api_url)

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 & 15 deletions
This file was deleted.

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

Lines changed: 3 additions & 3 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 jigsawstack 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):
@@ -39,7 +39,7 @@ class PredictionResponse(TypedDict):
3939
class Prediction(ClientConfig):
4040
def predict(self, params: PredictionParams) -> PredictionResponse:
4141
path = "/ai/prediction"
42-
resp = request.Request(
42+
resp = Request(
4343
api_key=self.api_key,
4444
api_url=self.api_url,
4545
path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()

jigsawstack/prediction/__init__.py

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

jigsawstack/request.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from typing import Any, Dict, Generic, List, Union, cast
2-
32
import requests
43
from typing_extensions import Literal, TypeVar
5-
6-
import jigsawstack
7-
from jigsawstack.exceptions import NoContentError, raise_for_code_and_type
4+
from .exceptions import NoContentError, raise_for_code_and_type
85

96
RequestVerb = Literal["get", "post", "put", "patch", "delete"]
107

@@ -108,8 +105,6 @@ def make_request(self, url: str) -> requests.Response:
108105
headers = self.__get_headers()
109106
params = self.params
110107
verb = self.verb
111-
112-
print("ABOUT TO MAKE REQUEST WITH HEADERS",headers)
113108
try:
114109
return requests.request(verb, url, json=params, headers=headers,)
115110
except requests.HTTPError as e:

jigsawstack/resources/__init__.py

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

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

Lines changed: 4 additions & 4 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 jigsawstack 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):
@@ -61,7 +61,7 @@ def ai_search(self,params: AISearchParams) -> SearchAIResponse:
6161
safe_search = params.get("safe_search","moderate")
6262
spell_check = params.get("spell_check", "True")
6363
path = f"/web/search?query={query}&ai_overview={ai_overview}&safe_search={safe_search}&spell_check={spell_check}"
64-
resp = request.Request(
64+
resp = Request(
6565
api_key=self.api_key,
6666
api_url=self.api_url,
6767
path=path, params=cast(Dict[Any, Any], params), verb="GET"
@@ -74,7 +74,7 @@ def ai_search(self,params: AISearchParams) -> SearchAIResponse:
7474
def suggestion(self, params: SearchSuggestionParams) -> SearchSuggestionResponse:
7575
query = params["query"]
7676
path = f"/web/search/suggest?query={query}"
77-
resp = request.Request(
77+
resp = Request(
7878
api_key=self.api_key,
7979
api_url=self.api_url,
8080
path=path, params=cast(Dict[Any, Any], params), verb="GET"

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: 3 additions & 3 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 jigsawstack 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):
@@ -37,6 +37,6 @@ class SentimentResponse(TypedDict):
3737
class Sentiment(ClientConfig):
3838
def analyze(self, params: SentimentParams) -> SentimentResponse:
3939
path = "/ai/sentiment"
40-
resp = request.Request(api_key=self.api_key,
40+
resp = Request(api_key=self.api_key,
4141
api_url=self.api_url,path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()
4242
return resp

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: 3 additions & 3 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 jigsawstack 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):
@@ -37,7 +37,7 @@ class SQL(ClientConfig):
3737
@classmethod
3838
def text_to_sql(self, params: SQLParams) -> SQLResponse:
3939
path = "/ai/sql"
40-
resp = request.Request(
40+
resp = Request(
4141
api_key=self.api_key,
4242
api_url=self.api_url,
4343
path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()

jigsawstack/sql/__init__.py

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

0 commit comments

Comments
 (0)