wiba 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wiba might be problematic. Click here for more details.
- wiba/__init__.py +31 -20
- {wiba-0.1.0.dist-info → wiba-0.1.1.dist-info}/LICENSE +1 -1
- {wiba-0.1.0.dist-info → wiba-0.1.1.dist-info}/METADATA +1 -1
- wiba-0.1.1.dist-info/RECORD +6 -0
- wiba-0.1.0.dist-info/RECORD +0 -6
- {wiba-0.1.0.dist-info → wiba-0.1.1.dist-info}/WHEEL +0 -0
- {wiba-0.1.0.dist-info → wiba-0.1.1.dist-info}/top_level.txt +0 -0
wiba/__init__.py
CHANGED
|
@@ -20,6 +20,7 @@ class ClientConfig:
|
|
|
20
20
|
log_level: str = "INFO"
|
|
21
21
|
api_token: Optional[str] = None
|
|
22
22
|
api_url: str = "https://wiba.dev"
|
|
23
|
+
allow_anonymous: bool = False # Whether to allow requests without an API token
|
|
23
24
|
|
|
24
25
|
@dataclass
|
|
25
26
|
class ClientStatistics:
|
|
@@ -216,8 +217,8 @@ class WIBA:
|
|
|
216
217
|
|
|
217
218
|
# Set API token from either direct argument or config
|
|
218
219
|
self.api_token = api_token or self.config.api_token
|
|
219
|
-
if not self.api_token:
|
|
220
|
-
raise ValidationError("API token is required
|
|
220
|
+
if not self.api_token and not self.config.allow_anonymous:
|
|
221
|
+
raise ValidationError("API token is required unless allow_anonymous is True")
|
|
221
222
|
|
|
222
223
|
# Initialize statistics
|
|
223
224
|
self.statistics = ClientStatistics()
|
|
@@ -339,14 +340,17 @@ class WIBA:
|
|
|
339
340
|
# Extract method name from endpoint, removing 'api' prefix
|
|
340
341
|
method_name = endpoint.split('/')[-1]
|
|
341
342
|
|
|
342
|
-
# Add request ID and
|
|
343
|
-
request_id = self._get_request_id()
|
|
343
|
+
# Add request ID and headers
|
|
344
344
|
request_headers = {
|
|
345
|
-
"X-Request-ID":
|
|
345
|
+
"X-Request-ID": self._get_request_id(),
|
|
346
346
|
"X-Requested-With": "XMLHttpRequest",
|
|
347
|
-
"Content-Type": "application/json"
|
|
348
|
-
"X-API-Token": self.api_token
|
|
347
|
+
"Content-Type": "application/json"
|
|
349
348
|
}
|
|
349
|
+
|
|
350
|
+
# Only add API token if we have one
|
|
351
|
+
if self.api_token:
|
|
352
|
+
request_headers["X-API-Token"] = self.api_token
|
|
353
|
+
|
|
350
354
|
if headers:
|
|
351
355
|
request_headers.update(headers)
|
|
352
356
|
|
|
@@ -374,11 +378,7 @@ class WIBA:
|
|
|
374
378
|
# Handle all error cases
|
|
375
379
|
if not response.ok:
|
|
376
380
|
self._update_statistics(method_name, error=True)
|
|
377
|
-
if response.status_code ==
|
|
378
|
-
raise ValidationError("Invalid API token")
|
|
379
|
-
elif response.status_code == 403:
|
|
380
|
-
raise ValidationError("API token does not have sufficient permissions")
|
|
381
|
-
elif response.status_code == 400:
|
|
381
|
+
if response.status_code == 400:
|
|
382
382
|
raise ValidationError(f"Bad request: {response.text}")
|
|
383
383
|
response.raise_for_status()
|
|
384
384
|
|
|
@@ -390,9 +390,6 @@ class WIBA:
|
|
|
390
390
|
|
|
391
391
|
except requests.exceptions.RequestException as e:
|
|
392
392
|
self._update_statistics(method_name, error=True)
|
|
393
|
-
if isinstance(e, requests.exceptions.HTTPError) and e.response is not None:
|
|
394
|
-
if e.response.status_code in (401, 403):
|
|
395
|
-
raise ValidationError(f"Authentication failed: {str(e)}")
|
|
396
393
|
raise WIBAError(f"Request failed: {str(e)}")
|
|
397
394
|
|
|
398
395
|
def _validate_dataframe(self, df: pd.DataFrame, required_columns: List[str]) -> None:
|
|
@@ -860,12 +857,22 @@ class WIBA:
|
|
|
860
857
|
}
|
|
861
858
|
)
|
|
862
859
|
|
|
860
|
+
# Handle empty response
|
|
861
|
+
if not response:
|
|
862
|
+
return pd.DataFrame()
|
|
863
|
+
|
|
863
864
|
# Convert response to DataFrame
|
|
864
865
|
if isinstance(response, list):
|
|
866
|
+
if not response: # Empty list
|
|
867
|
+
return pd.DataFrame()
|
|
865
868
|
result_df = pd.DataFrame(response)
|
|
866
869
|
else:
|
|
867
870
|
result_df = pd.DataFrame([response])
|
|
868
871
|
|
|
872
|
+
# Handle empty DataFrame
|
|
873
|
+
if result_df.empty:
|
|
874
|
+
return result_df
|
|
875
|
+
|
|
869
876
|
# Ensure all required columns are present
|
|
870
877
|
required_columns = [
|
|
871
878
|
'id', 'text', 'text_segment', 'start_index', 'end_index',
|
|
@@ -876,7 +883,7 @@ class WIBA:
|
|
|
876
883
|
for col in required_columns:
|
|
877
884
|
if col not in result_df.columns:
|
|
878
885
|
if col == 'overlapping_segments':
|
|
879
|
-
result_df[col] = result_df[col].apply(lambda x: [] if pd.isna(x) else x)
|
|
886
|
+
result_df[col] = result_df[col].apply(lambda x: [] if pd.isna(x) or not isinstance(x, list) else x)
|
|
880
887
|
elif col == 'argument_prediction':
|
|
881
888
|
# If segment_type exists, use it to set argument_prediction
|
|
882
889
|
if 'segment_type' in result_df.columns:
|
|
@@ -898,10 +905,14 @@ class WIBA:
|
|
|
898
905
|
result_df = result_df.drop(columns=[col for col in columns_to_drop if col in result_df.columns])
|
|
899
906
|
|
|
900
907
|
# Sort by start_index and argument_confidence
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
908
|
+
if 'start_index' in result_df.columns:
|
|
909
|
+
result_df = result_df.sort_values(
|
|
910
|
+
['start_index', 'argument_confidence'],
|
|
911
|
+
ascending=[True, False]
|
|
912
|
+
)
|
|
913
|
+
|
|
914
|
+
# Ensure all values are JSON-compatible
|
|
915
|
+
result_df = result_df.replace({np.nan: None, np.inf: None, -np.inf: None})
|
|
905
916
|
|
|
906
917
|
return result_df
|
|
907
918
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
wiba/__init__.py,sha256=MG7qzDljAoDct9VpofDWukukHhs41gDKJXcwu6eH64g,39788
|
|
2
|
+
wiba-0.1.1.dist-info/LICENSE,sha256=p1I8RmWr_Jzlh436pXBgcqvCzeMbFDQRPpYe_oegDj0,1068
|
|
3
|
+
wiba-0.1.1.dist-info/METADATA,sha256=BJw9pj1NzlMEyMuMhwEulzbqZI_rNJSXE6d-Nqj8kPE,4878
|
|
4
|
+
wiba-0.1.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
5
|
+
wiba-0.1.1.dist-info/top_level.txt,sha256=nAllQVKrFATsq88y_OeOwPEtwucwbqkZ0jHB8OkKclI,5
|
|
6
|
+
wiba-0.1.1.dist-info/RECORD,,
|
wiba-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
wiba/__init__.py,sha256=LY2nqW2D4BwNUim2RIx7Wa3hnInKKugsbTJb0E85KZ0,39551
|
|
2
|
-
wiba-0.1.0.dist-info/LICENSE,sha256=fPUf3LPdrEm9c7af7DvOfkWLDbWtR-D1QB34Q04JeUE,1071
|
|
3
|
-
wiba-0.1.0.dist-info/METADATA,sha256=QcV9kA71kc1kwNeui4uZ9Ix-CuWYWizYCplbuuRdChU,4878
|
|
4
|
-
wiba-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
5
|
-
wiba-0.1.0.dist-info/top_level.txt,sha256=nAllQVKrFATsq88y_OeOwPEtwucwbqkZ0jHB8OkKclI,5
|
|
6
|
-
wiba-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|