Skip to content

Commit f4d9870

Browse files
authored
Merge pull request #27 from JigsawStack/feat/async
Feat/async
2 parents 26dc362 + bb617a2 commit f4d9870

24 files changed

+2006
-55
lines changed

jigsawstack/__init__.py

Lines changed: 118 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
from typing import Union
22
import os
3-
from .audio import Audio
4-
from .vision import Vision
3+
from .audio import Audio, AsyncAudio
4+
from .vision import Vision, AsyncVision
55
from .search import Search
6-
from .prediction import Prediction
7-
from .sql import SQL
8-
from .store import KV, Store
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
14-
from .geo import Geo
15-
from .prompt_engine import PromptEngine
6+
from .prediction import Prediction, AsyncPrediction
7+
from .sql import SQL, AsyncSQL
8+
from .store import Store, AsyncStore
9+
from .translate import Translate, AsyncTranslate
10+
from .web import Web, AsyncWeb
11+
from .sentiment import Sentiment, AsyncSentiment
12+
from .validate import Validate, AsyncValidate
13+
from .summary import Summary, AsyncSummary
14+
from .geo import Geo, AsyncGeo
15+
from .prompt_engine import PromptEngine, AsyncPromptEngine
1616
from .exceptions import JigsawStackError
1717

18-
# from .version import get_version
19-
2018

2119
class JigsawStack:
2220
audio: Audio
2321
vision: Vision
24-
prediction: Prediction
25-
text_to_sql: SQL
2622
file: Store
27-
kv: KV
28-
translate: Translate
2923
web: Web
30-
sentiment: Sentiment
31-
validate: Validate
32-
summary: Summary
3324
search: Search
3425
geo: Geo
3526
prompt_engine: PromptEngine
@@ -104,11 +95,6 @@ def __init__(
10495
api_url=api_url,
10596
disable_request_logging=disable_request_logging,
10697
)
107-
self.kv = KV(
108-
api_key=api_key,
109-
api_url=api_url,
110-
disable_request_logging=disable_request_logging,
111-
)
11298
self.translate = Translate(
11399
api_key=api_key,
114100
api_url=api_url,
@@ -126,5 +112,110 @@ def __init__(
126112
)
127113

128114

115+
class AsyncJigsawStack:
116+
geo: AsyncGeo
117+
validate: AsyncValidate
118+
web: AsyncWeb
119+
audio: AsyncAudio
120+
vision: AsyncVision
121+
store: AsyncStore
122+
prompt_engine: AsyncPromptEngine
123+
api_key: str
124+
api_url: str
125+
disable_request_logging: bool
126+
127+
def __init__(
128+
self,
129+
api_key: Union[str, None] = None,
130+
api_url: Union[str, None] = None,
131+
disable_request_logging: Union[bool, None] = None,
132+
) -> None:
133+
if api_key is None:
134+
api_key = os.environ.get("JIGSAWSTACK_API_KEY")
135+
136+
if api_key is None:
137+
raise ValueError(
138+
"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"
139+
)
140+
141+
if api_url is None:
142+
api_url = os.environ.get("JIGSAWSTACK_API_URL")
143+
if api_url is None:
144+
api_url = f"https://api.jigsawstack.com/v1"
145+
146+
self.api_key = api_key
147+
self.api_url = api_url
148+
149+
self.web = AsyncWeb(
150+
api_key=api_key,
151+
api_url=api_url,
152+
disable_request_logging=disable_request_logging,
153+
)
154+
155+
self.geo = AsyncGeo(
156+
api_key=api_key,
157+
api_url=api_url,
158+
disable_request_logging=disable_request_logging,
159+
)
160+
161+
self.validate = AsyncValidate(
162+
api_key=api_key,
163+
api_url=api_url,
164+
disable_request_logging=disable_request_logging,
165+
)
166+
self.audio = AsyncAudio(
167+
api_key=api_key,
168+
api_url=api_url,
169+
disable_request_logging=disable_request_logging,
170+
)
171+
172+
self.vision = AsyncVision(
173+
api_key=api_key,
174+
api_url=api_url,
175+
disable_request_logging=disable_request_logging,
176+
)
177+
178+
self.store = AsyncStore(
179+
api_key=api_key,
180+
api_url=api_url,
181+
disable_request_logging=disable_request_logging,
182+
)
183+
184+
self.summary = AsyncSummary(
185+
api_key=api_key,
186+
api_url=api_url,
187+
disable_request_logging=disable_request_logging,
188+
).summarize
189+
190+
self.prediction = AsyncPrediction(
191+
api_key=api_key,
192+
api_url=api_url,
193+
disable_request_logging=disable_request_logging,
194+
).predict
195+
self.text_to_sql = AsyncSQL(
196+
api_key=api_key,
197+
api_url=api_url,
198+
disable_request_logging=disable_request_logging,
199+
).text_to_sql
200+
201+
self.sentiment = AsyncSentiment(
202+
api_key=api_key,
203+
api_url=api_url,
204+
disable_request_logging=disable_request_logging,
205+
).analyze
206+
207+
self.translate = AsyncTranslate(
208+
api_key=api_key,
209+
api_url=api_url,
210+
disable_request_logging=disable_request_logging,
211+
).translate
212+
213+
self.prompt_engine = AsyncPromptEngine(
214+
api_key=api_key,
215+
api_url=api_url,
216+
disable_request_logging=disable_request_logging,
217+
)
218+
219+
129220
# Create a global instance of the Web class
130-
__all__ = ["JigsawStack", "Search", "JigsawStackError"]
221+
__all__ = ["JigsawStack", "Search", "JigsawStackError", "AsyncJigsawStack"]

jigsawstack/_client.py

Lines changed: 12 additions & 9 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 .searchs import Search
6-
from .predictions import Prediction
5+
from .search import Search
6+
from .prediction import Prediction
77
from .sql import SQL
88
from .store import KV, File
99
from .translate import Translate
@@ -12,9 +12,10 @@
1212
from .validate import Validate
1313
from .summary import Summary
1414

15+
1516
class JigsawStack:
1617
audio: Audio
17-
vision : Vision
18+
vision: Vision
1819
prediction: Prediction
1920
sql: SQL
2021
file: File
@@ -28,14 +29,17 @@ class JigsawStack:
2829
api_key: str
2930
api_url: str
3031

31-
32-
def __init__(self, api_key: Union[str, None] = None, api_url: Union[str, None] = None) -> None:
32+
def __init__(
33+
self, api_key: Union[str, None] = None, api_url: Union[str, None] = None
34+
) -> None:
3335
if api_key is None:
3436
api_key = os.environ.get("JIGSAWSTACK_API_KEY")
35-
37+
3638
if api_key is None:
37-
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")
38-
39+
raise ValueError(
40+
"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"
41+
)
42+
3943
if api_url is None:
4044
api_url = os.environ.get("JIGSAWSTACK_API_URL")
4145
if api_url is None:
@@ -44,7 +48,6 @@ def __init__(self, api_key: Union[str, None] = None, api_url: Union[str, None] =
4448
self.api_key = api_key
4549
self.api_url = api_url
4650

47-
4851
self.audio = Audio(api_key=api_key, api_url=api_url)
4952
self.web = Web(api_key=api_key, api_url=api_url)
5053
self.search = Search(api_key=api_key, api_url=api_url)

0 commit comments

Comments
 (0)