2121
2222
2323class JigsawStack :
24+ api_key : str
25+ base_url : str
26+ headers : Dict [str , str ]
2427 audio : Audio
25- vision : Vision
26- image_generation : ImageGeneration
27- file : Store
28- web : Web
29- search : Search
3028 classification : Classification
29+ embedding : Embedding
30+ embedding_v2 : EmbeddingV2
31+ store : Store
32+ image_generation : ImageGeneration
33+ prediction : Prediction
3134 prompt_engine : PromptEngine
32- api_key : str
33- api_url : str
34- headers : Dict [str , str ]
35- # disable_request_logging: bool
35+ sentiment : Sentiment
36+ summary : Summary
37+ text_to_sql : SQL
38+ translate : Translate
39+ validate : Validate
40+ vision : Vision
41+ web : Web
3642
3743 def __init__ (
3844 self ,
3945 api_key : Union [str , None ] = None ,
40- api_url : Union [str , None ] = None ,
41- # disable_request_logging: Union[bool, None] = None,
46+ base_url : Union [str , None ] = None ,
4247 headers : Union [Dict [str , str ], None ] = None ,
4348 ) -> None :
4449 if api_key is None :
@@ -49,117 +54,89 @@ def __init__(
4954 "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"
5055 )
5156
52- if api_url is None :
53- api_url = os .environ .get ("JIGSAWSTACK_API_URL" )
54- if api_url is None :
55- api_url = "https://api.jigsawstack.com/"
57+ if base_url is None :
58+ base_url = os .environ .get ("JIGSAWSTACK_API_URL" )
59+ if base_url is None :
60+ base_url = "https://api.jigsawstack.com/"
5661
5762 self .api_key = api_key
58- self .api_url = api_url
63+ self .base_url = base_url
5964
60- self .headers = headers or {}
65+ self .headers = headers or {"Content-Type" : "application/json" }
6166
62- disable_request_logging = self .headers .get ("x-jigsaw-no-request-log" )
67+ self .audio = Audio (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
68+
69+ self .web = Web (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
6370
64- self .audio = Audio (
65- api_key = api_key ,
66- api_url = api_url + "/v1" ,
67- disable_request_logging = disable_request_logging ,
68- )
69- self .web = Web (
70- api_key = api_key ,
71- api_url = api_url + "/v1" ,
72- disable_request_logging = disable_request_logging ,
73- )
7471 self .sentiment = Sentiment (
75- api_key = api_key ,
76- api_url = api_url + "/v1" ,
77- disable_request_logging = disable_request_logging ,
72+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
7873 ).analyze
79- self .validate = Validate (
80- api_key = api_key ,
81- api_url = api_url + "/v1" ,
82- disable_request_logging = disable_request_logging ,
83- )
74+
75+ self .validate = Validate (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
8476 self .summary = Summary (
85- api_key = api_key ,
86- api_url = api_url + "/v1" ,
87- disable_request_logging = disable_request_logging ,
77+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
8878 ).summarize
89- self .vision = Vision (
90- api_key = api_key ,
91- api_url = api_url + "/v1" ,
92- disable_request_logging = disable_request_logging ,
93- )
79+
80+ self .vision = Vision (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
81+
9482 self .prediction = Prediction (
95- api_key = api_key ,
96- api_url = api_url + "/v1" ,
97- disable_request_logging = disable_request_logging ,
83+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
9884 ).predict
85+
9986 self .text_to_sql = SQL (
100- api_key = api_key ,
101- api_url = api_url + "/v1" ,
102- disable_request_logging = disable_request_logging ,
87+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
10388 ).text_to_sql
104- self .store = Store (
105- api_key = api_key ,
106- api_url = api_url + "/v1" ,
107- disable_request_logging = disable_request_logging ,
108- )
109- self .translate = Translate (
110- api_key = api_key ,
111- api_url = api_url + "/v1" ,
112- disable_request_logging = disable_request_logging ,
113- )
89+
90+ self .store = Store (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
91+
92+ self .translate = Translate (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
11493
11594 self .embedding = Embedding (
116- api_key = api_key ,
117- api_url = api_url + "/v1" ,
118- disable_request_logging = disable_request_logging ,
95+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
11996 ).execute
12097
121- self .embeddingV2 = EmbeddingV2 (
122- api_key = api_key ,
123- api_url = api_url + "/v2" ,
124- disable_request_logging = disable_request_logging ,
98+ self .embedding_v2 = EmbeddingV2 (
99+ api_key = api_key , base_url = base_url + "/v2" , headers = headers
125100 ).execute
126101
127102 self .image_generation = ImageGeneration (
128- api_key = api_key ,
129- api_url = api_url + "/v1" ,
130- disable_request_logging = disable_request_logging ,
103+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
131104 ).image_generation
132105
133106 self .classification = Classification (
134- api_key = api_key ,
135- api_url = api_url + "/v1" ,
136- disable_request_logging = disable_request_logging ,
107+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
137108 ).classify
138109
139110 self .prompt_engine = PromptEngine (
140- api_key = api_key ,
141- api_url = api_url + "/v1" ,
142- disable_request_logging = disable_request_logging ,
111+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
143112 )
144113
145114
146115class AsyncJigsawStack :
147- validate : AsyncValidate
148- web : AsyncWeb
116+ api_key : str
117+ base_url : str
118+ headers : Dict [str , str ]
149119 audio : AsyncAudio
150- vision : AsyncVision
120+ classification : AsyncClassification
121+ embedding : AsyncEmbedding
122+ embedding_v2 : AsyncEmbeddingV2
151123 image_generation : AsyncImageGeneration
152- store : AsyncStore
124+ prediction : AsyncPrediction
153125 prompt_engine : AsyncPromptEngine
154- api_key : str
155- api_url : str
156- disable_request_logging : bool
126+ sentiment : AsyncSentiment
127+ store : AsyncStore
128+ summary : AsyncSummary
129+ text_to_sql : AsyncSQL
130+ translate : AsyncTranslate
131+ validate : AsyncValidate
132+ vision : AsyncVision
133+ web : AsyncWeb
157134
158135 def __init__ (
159136 self ,
160137 api_key : Union [str , None ] = None ,
161- api_url : Union [str , None ] = None ,
162- disable_request_logging : Union [bool , None ] = None ,
138+ base_url : Union [str , None ] = None ,
139+ headers : Union [Dict [ str , str ] , None ] = None ,
163140 ) -> None :
164141 if api_key is None :
165142 api_key = os .environ .get ("JIGSAWSTACK_API_KEY" )
@@ -169,100 +146,59 @@ def __init__(
169146 "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"
170147 )
171148
172- if api_url is None :
173- api_url = os .environ .get ("JIGSAWSTACK_API_URL" )
174- if api_url is None :
175- api_url = "https://api.jigsawstack.com/"
149+ if base_url is None :
150+ base_url = os .environ .get ("JIGSAWSTACK_API_URL" )
151+ if base_url is None :
152+ base_url = "https://api.jigsawstack.com/"
176153
177154 self .api_key = api_key
178- self .api_url = api_url
155+ self .base_url = base_url
156+ self .headers = headers or {"Content-Type" : "application/json" }
179157
180- self .web = AsyncWeb (
181- api_key = api_key ,
182- api_url = api_url + "/v1" ,
183- disable_request_logging = disable_request_logging ,
184- )
158+ self .web = AsyncWeb (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
185159
186- self .validate = AsyncValidate (
187- api_key = api_key ,
188- api_url = api_url + "/v1" ,
189- disable_request_logging = disable_request_logging ,
190- )
191- self .audio = AsyncAudio (
192- api_key = api_key ,
193- api_url = api_url + "/v1" ,
194- disable_request_logging = disable_request_logging ,
195- )
160+ self .validate = AsyncValidate (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
196161
197- self .vision = AsyncVision (
198- api_key = api_key ,
199- api_url = api_url + "/v1" ,
200- disable_request_logging = disable_request_logging ,
201- )
162+ self .audio = AsyncAudio (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
202163
203- self .store = AsyncStore (
204- api_key = api_key ,
205- api_url = api_url + "/v1" ,
206- disable_request_logging = disable_request_logging ,
207- )
164+ self .vision = AsyncVision (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
165+
166+ self .store = AsyncStore (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
208167
209168 self .summary = AsyncSummary (
210- api_key = api_key ,
211- api_url = api_url + "/v1" ,
212- disable_request_logging = disable_request_logging ,
169+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
213170 ).summarize
214171
215- self .prediction = AsyncPrediction (
216- api_key = api_key ,
217- api_url = api_url + "/v1" ,
218- disable_request_logging = disable_request_logging ,
219- ).predict
172+ self .prediction = AsyncPrediction (api_key = api_key , base_url = base_url + "/v1" ).predict
173+
220174 self .text_to_sql = AsyncSQL (
221- api_key = api_key ,
222- api_url = api_url + "/v1" ,
223- disable_request_logging = disable_request_logging ,
175+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
224176 ).text_to_sql
225177
226178 self .sentiment = AsyncSentiment (
227- api_key = api_key ,
228- api_url = api_url + "/v1" ,
229- disable_request_logging = disable_request_logging ,
179+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
230180 ).analyze
231181
232- self .translate = AsyncTranslate (
233- api_key = api_key ,
234- api_url = api_url + "/v1" ,
235- disable_request_logging = disable_request_logging ,
236- )
182+ self .translate = AsyncTranslate (api_key = api_key , base_url = base_url + "/v1" , headers = headers )
237183
238184 self .embedding = AsyncEmbedding (
239- api_key = api_key ,
240- api_url = api_url + "/v1" ,
241- disable_request_logging = disable_request_logging ,
185+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
242186 ).execute
243187
244- self .embeddingV2 = AsyncEmbeddingV2 (
245- api_key = api_key ,
246- api_url = api_url + "/v2" ,
247- disable_request_logging = disable_request_logging ,
188+ self .embedding_v2 = AsyncEmbeddingV2 (
189+ api_key = api_key , base_url = base_url + "/v2" , headers = headers
248190 ).execute
249191
250192 self .image_generation = AsyncImageGeneration (
251- api_key = api_key ,
252- api_url = api_url + "/v1" ,
253- disable_request_logging = disable_request_logging ,
193+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
254194 ).image_generation
255195
256196 self .classification = AsyncClassification (
257- api_key = api_key ,
258- api_url = api_url + "/v1" ,
259- disable_request_logging = disable_request_logging ,
197+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
260198 ).classify
261199
262200 self .prompt_engine = AsyncPromptEngine (
263- api_key = api_key ,
264- api_url = api_url + "/v1" ,
265- disable_request_logging = disable_request_logging ,
201+ api_key = api_key , base_url = base_url + "/v1" , headers = headers
266202 )
267203
268204
0 commit comments