fix: update error handling in request for litellm models (#4536)
handle request exception for litellm models
This commit is contained in:
parent
f8f9b7cace
commit
168c716c58
1 changed files with 10 additions and 2 deletions
|
|
@ -4,11 +4,13 @@ import json
|
|||
import os
|
||||
import pkgutil
|
||||
import threading
|
||||
from json.decoder import JSONDecodeError
|
||||
|
||||
import astra_assistants.tools as astra_assistants_tools
|
||||
import requests
|
||||
from astra_assistants import OpenAIWithDefaultKey, patch
|
||||
from astra_assistants.tools.tool_interface import ToolInterface
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
from langflow.services.cache.utils import CacheMiss
|
||||
|
||||
|
|
@ -26,8 +28,14 @@ def get_patched_openai_client(shared_component_cache):
|
|||
|
||||
|
||||
url = "https://raw.githubusercontent.com/BerriAI/litellm/refs/heads/main/model_prices_and_context_window.json"
|
||||
response = requests.get(url, timeout=10)
|
||||
data = json.loads(response.text)
|
||||
try:
|
||||
response = requests.get(url, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = json.loads(response.text)
|
||||
except RequestException:
|
||||
data = {}
|
||||
except JSONDecodeError:
|
||||
data = {}
|
||||
|
||||
# Extract the model names into a Python list
|
||||
litellm_model_names = [model for model in data if model != "sample_spec"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue