From c7148d494d69f72bc0edd55adc4281d5baef0c3d Mon Sep 17 00:00:00 2001 From: Jackson Barbosa Date: Fri, 29 Dec 2023 15:49:06 -0300 Subject: [PATCH 1/4] adding post processing to stop ans in first '\n' --- bothub_nlp_api/utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bothub_nlp_api/utils.py b/bothub_nlp_api/utils.py index b0a4b81..8b56d74 100644 --- a/bothub_nlp_api/utils.py +++ b/bothub_nlp_api/utils.py @@ -300,9 +300,14 @@ def request_wenigpt(context, question): response_json = response.json() text_answers = response_json["output"].get("text") + answers = [] if text_answers: - text_answers = [{"text": answer.strip()} for answer in text_answers] - else: - text_answers = [] - - return {"answers": text_answers, "id": "0"} + for answer in text_answers: + answer = answer.strip() + ans = "" + for ch in answer: + if ch == '\n': + break + ans += ch + answer.append({"text": ans}) + return {"answers": answers, "id": "0"} From 2983aea66b7510ed18fe852a12cd6f56c967529f Mon Sep 17 00:00:00 2001 From: Jackson Barbosa Date: Fri, 29 Dec 2023 16:06:01 -0300 Subject: [PATCH 2/4] adding logger --- bothub_nlp_api/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bothub_nlp_api/utils.py b/bothub_nlp_api/utils.py index 8b56d74..ab84475 100644 --- a/bothub_nlp_api/utils.py +++ b/bothub_nlp_api/utils.py @@ -292,13 +292,15 @@ def request_wenigpt(context, question): } } + text_answers = None + try: response = requests.request("POST", url, headers=headers, data=json.dumps(data)) + response_json = response.json() + text_answers = response_json["output"].get("text") except Exception as e: response = {"error": str(e)} - - response_json = response.json() - text_answers = response_json["output"].get("text") + print(f"[ WENIGPT REQUEST ] {response}") answers = [] if text_answers: From cc98a17ec57e2b498f24a4c6cf7a50e586a774d9 Mon Sep 17 00:00:00 2001 From: Jackson Barbosa Date: Fri, 29 Dec 2023 16:56:48 -0300 Subject: [PATCH 3/4] adding more log --- bothub_nlp_api/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bothub_nlp_api/utils.py b/bothub_nlp_api/utils.py index ab84475..7b1a91a 100644 --- a/bothub_nlp_api/utils.py +++ b/bothub_nlp_api/utils.py @@ -296,6 +296,7 @@ def request_wenigpt(context, question): try: response = requests.request("POST", url, headers=headers, data=json.dumps(data)) + print(f"[ WENIGPT REQUEST] - {response.text}") response_json = response.json() text_answers = response_json["output"].get("text") except Exception as e: From 12be5ec11ed2d36d203ec6d935c4d7392252dc43 Mon Sep 17 00:00:00 2001 From: Jackson Barbosa Date: Fri, 29 Dec 2023 17:34:17 -0300 Subject: [PATCH 4/4] fix var using --- bothub_nlp_api/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bothub_nlp_api/utils.py b/bothub_nlp_api/utils.py index 7b1a91a..566cf00 100644 --- a/bothub_nlp_api/utils.py +++ b/bothub_nlp_api/utils.py @@ -312,5 +312,5 @@ def request_wenigpt(context, question): if ch == '\n': break ans += ch - answer.append({"text": ans}) + answers.append({"text": ans}) return {"answers": answers, "id": "0"}