Skip to content

Commit

Permalink
Merge pull request #143 from weni-ai/feature/add-wenigpt-postprocessing
Browse files Browse the repository at this point in the history
Feature/add wenigpt postprocessing
  • Loading branch information
Sandro-Meireles authored Dec 29, 2023
2 parents 3b2da0c + 12be5ec commit 49208ea
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions bothub_nlp_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,25 @@ def request_wenigpt(context, question):
}
}

text_answers = None

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:
response = {"error": str(e)}
print(f"[ WENIGPT REQUEST ] {response}")

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
answers.append({"text": ans})
return {"answers": answers, "id": "0"}

0 comments on commit 49208ea

Please sign in to comment.