File size: 661 Bytes
d9c2461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""API interactions for the Kwest API."""

import os

import requests


API_URL = os.getenv("API_URL", None)
AUTH_TOKEN = os.getenv("AUTH_TOKEN", None)

if not API_URL or not AUTH_TOKEN:
    raise ValueError("API_URL and AUTH_TOKEN secrets must be set in the environment variables.")


def check_if_input_is_valid(input_str: str) -> bool:
    """Check if the input string is valid for the API."""
    response = requests.post(
        f"{API_URL}/check-input",
        headers={"Authorization": f"{AUTH_TOKEN}"},
        json={"input": input_str},
    )
    if response.status_code == 200:
        return response.json()["output"]
    else:
        return None