Skip to content

Commit

Permalink
refactor: accept flat text as input for token classification mapper (#…
Browse files Browse the repository at this point in the history
…1686)

Closes #482

(cherry picked from commit 379ac56)
  • Loading branch information
Ankush-Chander authored and frascuchon committed Sep 30, 2022
1 parent d6cb5e6 commit 7e3f708
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/rubrix/monitoring/asgi.py
Expand Up @@ -46,7 +46,12 @@


def token_classification_mapper(inputs, outputs):
text = inputs.get("text", "")
if isinstance(inputs, str):
text = inputs
elif isinstance(inputs, dict):
text = inputs.get("text", "")
else:
text = ""
tokens = outputs.get("tokens") if isinstance(outputs, dict) else None
return TokenClassificationRecord(
text=text,
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_asgi.py
Expand Up @@ -123,7 +123,7 @@ def __call__(self, records, name: str, **kwargs):

mock.post(
expected_endpoint,
json=[{"text": "The main text data"}, {"text": "The main text data"}],
json=[{"text": "The main text data"}, "The main text data"],
)
time.sleep(0.2)
assert mock_log.was_called
Expand Down

0 comments on commit 7e3f708

Please sign in to comment.