Last active
June 2, 2021 11:43
-
-
Save philschmid/06d93e81b05b9cc5f8d25b17573d0ca4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const API_URL = "https:/{URL}/api/{TASK}" | |
| async function query(payload) { | |
| const body = JSON.stringify(payload) | |
| try { | |
| const response = await fetch(API_URL, { | |
| method: 'post', | |
| body | |
| }) | |
| return response.json(); | |
| } catch (errr) { | |
| console.error(errr) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import requests | |
| API_URL = "https:/{URL}/api/{TASK}" | |
| def query(payload=''): | |
| body = {"input":payload} | |
| response = requests.request("POST", API_URL, data= json.dumps(body)) | |
| try: | |
| response.raise_for_status() | |
| except requests.exceptions.HTTPError: | |
| return "Error:"+" ".join(response.json()['error']) | |
| return response.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment