arabic-RAG / backend /query_llm.py
derek-thomas's picture
derek-thomas HF staff
Adding error handling
5f311b3
raw
history blame
790 Bytes
import requests
from os import getenv
API_URL = getenv('API_URL')
BEARER = getenv('BEARER')
headers = {
"Authorization": f"Bearer {BEARER}",
"Content-Type": "application/json"
}
def call_jais(payload):
try:
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status() # This will raise an exception for HTTP error codes
return response.json()
except requests.exceptions.HTTPError as http_err:
raise gr.Error(f"An error occurred while processing the request. {http_err}")
except Exception as err:
raise gr.Error(f"An error occurred while processing the request. {err}")
def generate(prompt: str):
payload = {'inputs': '', 'prompt':prompt}
response = call_jais(payload)
return response