From 8fada9ad5f29ac4023f9afcad9bc21aeb2895a89 Mon Sep 17 00:00:00 2001 From: Julien Salinas Date: Fri, 10 Nov 2023 09:53:35 +0000 Subject: [PATCH] DDo not parse the returned JSON if asynchronous request still in progress. --- README.md | 2 +- nlpcloud/__init__.py | 5 ++++- setup.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0086487..8aeae16 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ If you are making asynchronous requests, you will always receive a quick respons client.async_result("https://api.nlpcloud.io/v1/get-async-result/21718218-42e8-4be9-a67f-b7e18e03b436") ``` -The above command returns a JSON object. +The above command returns a JSON object when the response is ready. It returns `None` otherwise. ### Automatic Speech Recognition (Speech to Text) Endpoint diff --git a/nlpcloud/__init__.py b/nlpcloud/__init__.py index 7a47ba6..2a7d82d 100644 --- a/nlpcloud/__init__.py +++ b/nlpcloud/__init__.py @@ -76,7 +76,10 @@ def async_result(self, url): except HTTPError as err: raise HTTPError(str(err) + ": " + str(r.text)) - return r.json() + try: + return r.json() + except requests.exceptions.JSONDecodeError: + return None def chatbot(self, text, context=None, history=None): payload = { diff --git a/setup.py b/setup.py index 5b44cdb..1c7103b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='nlpcloud', - version='1.1.44', + version='1.1.45', description='Python client for the NLP Cloud API', long_description="NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, paraphrasing, grammar and spelling correction, keywords and keyphrases extraction, chatbot, product description and ad generation, intent classification, text generation, image generation, code generation, question answering, automatic speech recognition, machine translation, language detection, semantic search, semantic similarity, speech synthesis, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API.\n\nThis is the Python client for the API.\n\nMore details here: https://nlpcloud.io\n\nDocumentation: https://docs.nlpcloud.io\n\nGithub: https://github.com/nlpcloud/nlpcloud-python", packages=['nlpcloud'],