derek-thomas HF staff commited on
Commit
5f311b3
1 Parent(s): 4e966cd

Adding error handling

Browse files
Files changed (1) hide show
  1. backend/query_llm.py +10 -2
backend/query_llm.py CHANGED
@@ -11,9 +11,17 @@ headers = {
11
  "Content-Type": "application/json"
12
  }
13
 
 
14
  def call_jais(payload):
15
- response = requests.post(API_URL, headers=headers, json=payload)
16
- return response.json()
 
 
 
 
 
 
 
17
 
18
  def generate(prompt: str):
19
  payload = {'inputs': '', 'prompt':prompt}
 
11
  "Content-Type": "application/json"
12
  }
13
 
14
+
15
  def call_jais(payload):
16
+ try:
17
+ response = requests.post(API_URL, headers=headers, json=payload)
18
+ response.raise_for_status() # This will raise an exception for HTTP error codes
19
+ return response.json()
20
+ except requests.exceptions.HTTPError as http_err:
21
+ raise gr.Error(f"An error occurred while processing the request. {http_err}")
22
+ except Exception as err:
23
+ raise gr.Error(f"An error occurred while processing the request. {err}")
24
+
25
 
26
  def generate(prompt: str):
27
  payload = {'inputs': '', 'prompt':prompt}