Skip to content

Commit

Permalink
python: always check status code of HTTP responses (nomic-ai#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
cebtenzzre authored Oct 11, 2023
1 parent afaa291 commit aed2068
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gpt4all-bindings/python/gpt4all/gpt4all.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def list_models() -> List[ConfigType]:
Returns:
Model list in JSON format.
"""
return requests.get("https://gpt4all.io/models/models2.json").json()
resp = requests.get("https://gpt4all.io/models/models2.json")
if resp.status_code != 200:
raise ValueError(f'Request failed: HTTP {resp.status_code} {resp.reason}')
return resp.json()

@staticmethod
def retrieve_model(
Expand Down Expand Up @@ -215,6 +218,9 @@ def get_download_url(model_filename):
download_url = get_download_url(model_filename)

response = requests.get(download_url, stream=True)
if response.status_code != 200:
raise ValueError(f'Request failed: HTTP {response.status_code} {response.reason}')

total_size_in_bytes = int(response.headers.get("content-length", 0))
block_size = 2**20 # 1 MB

Expand Down

0 comments on commit aed2068

Please sign in to comment.