-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Matt Zhou <[email protected]>
- Loading branch information
Showing
3 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import requests | ||
|
||
from letta.utils import printd, smart_urljoin | ||
|
||
|
||
def mistral_get_model_list(url: str, api_key: str) -> dict: | ||
url = smart_urljoin(url, "models") | ||
|
||
headers = {"Content-Type": "application/json"} | ||
if api_key is not None: | ||
headers["Authorization"] = f"Bearer {api_key}" | ||
|
||
printd(f"Sending request to {url}") | ||
response = None | ||
try: | ||
# TODO add query param "tool" to be true | ||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() # Raises HTTPError for 4XX/5XX status | ||
response_json = response.json() # convert to dict from string | ||
return response_json | ||
except requests.exceptions.HTTPError as http_err: | ||
# Handle HTTP errors (e.g., response 4XX, 5XX) | ||
try: | ||
if response: | ||
response = response.json() | ||
except: | ||
pass | ||
printd(f"Got HTTPError, exception={http_err}, response={response}") | ||
raise http_err | ||
except requests.exceptions.RequestException as req_err: | ||
# Handle other requests-related errors (e.g., connection error) | ||
try: | ||
if response: | ||
response = response.json() | ||
except: | ||
pass | ||
printd(f"Got RequestException, exception={req_err}, response={response}") | ||
raise req_err | ||
except Exception as e: | ||
# Handle other potential errors | ||
try: | ||
if response: | ||
response = response.json() | ||
except: | ||
pass | ||
printd(f"Got unknown Exception, exception={e}, response={response}") | ||
raise e |
This file contains 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
This file contains 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