pagezyhf HF Staff commited on
Commit
d6a1cfd
·
1 Parent(s): 5d99e77
Files changed (2) hide show
  1. app/main.py +26 -4
  2. requirements.txt +2 -1
app/main.py CHANGED
@@ -7,6 +7,7 @@ from optimum.neuron import utils
7
  import logging
8
  import sys
9
  import os
 
10
  # Configure logging
11
  logging.basicConfig(
12
  level=logging.INFO,
@@ -102,12 +103,33 @@ async def get_model_list():
102
  async def get_model_info_endpoint(model_id: str):
103
  logger.info(f"Fetching configurations for model: {model_id}")
104
  try:
105
- configs = utils.get_hub_cached_entries(model_id=model_id, mode="inference")
 
 
 
 
 
 
 
 
 
 
 
 
106
  logger.info(f"Found {len(configs)} configurations for model {model_id}")
107
- # Return empty list if no configurations found
108
- if not configs:
109
- return JSONResponse(content={"configurations": []})
110
  return JSONResponse(content={"configurations": configs})
 
 
 
 
 
 
 
 
 
 
 
 
111
  except Exception as e:
112
  logger.error(f"Error fetching configurations for model {model_id}: {str(e)}", exc_info=True)
113
  return JSONResponse(
 
7
  import logging
8
  import sys
9
  import os
10
+ import httpx
11
  # Configure logging
12
  logging.basicConfig(
13
  level=logging.INFO,
 
103
  async def get_model_info_endpoint(model_id: str):
104
  logger.info(f"Fetching configurations for model: {model_id}")
105
  try:
106
+ # Define the base URL for the HuggingFace API
107
+ base_url = "https://huggingface.co/api/integrations/aws/v1/lookup"
108
+ api_url = f"{base_url}/{model_id}"
109
+
110
+ # Make async HTTP request with timeout
111
+ timeout = httpx.Timeout(15.0, connect=5.0) # 10s for entire request, 5s for connection
112
+ async with httpx.AsyncClient(timeout=timeout) as client:
113
+ response = await client.get(api_url)
114
+ response.raise_for_status()
115
+
116
+ data = response.json()
117
+ configs = data.get("cached_configs", [])
118
+
119
  logger.info(f"Found {len(configs)} configurations for model {model_id}")
 
 
 
120
  return JSONResponse(content={"configurations": configs})
121
+ except httpx.TimeoutException as e:
122
+ logger.error(f"Timeout while fetching configurations for model {model_id}: {str(e)}", exc_info=True)
123
+ return JSONResponse(
124
+ status_code=504, # Gateway Timeout
125
+ content={"error": "Request timed out while fetching model configurations"}
126
+ )
127
+ except httpx.HTTPError as e:
128
+ logger.error(f"HTTP error fetching configurations for model {model_id}: {str(e)}", exc_info=True)
129
+ return JSONResponse(
130
+ status_code=500,
131
+ content={"error": f"Failed to fetch model configurations: {str(e)}"}
132
+ )
133
  except Exception as e:
134
  logger.error(f"Error fetching configurations for model {model_id}: {str(e)}", exc_info=True)
135
  return JSONResponse(
requirements.txt CHANGED
@@ -3,4 +3,5 @@ uvicorn==0.24.0
3
  jinja2==3.1.2
4
  optimum-neuron==0.1.0
5
  python-multipart==0.0.6
6
- optimum==1.23.3
 
 
3
  jinja2==3.1.2
4
  optimum-neuron==0.1.0
5
  python-multipart==0.0.6
6
+ optimum==1.23.3
7
+ httpx>=0.25.0