Added auto-check for model choice
Browse files
app.py
CHANGED
@@ -78,12 +78,42 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
78 |
|
79 |
final_answer = FinalAnswerTool()
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
model = HfApiModel(
|
82 |
max_tokens=1048,
|
83 |
temperature=0.5,
|
84 |
#model_id='meta-llama/Llama-3.2-1B-Instruct',
|
85 |
#model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
86 |
-
model_id = 'Qwen/Qwen2.5-Coder-1.5B-Instruct',
|
|
|
87 |
custom_role_conversions=None,
|
88 |
)
|
89 |
|
|
|
78 |
|
79 |
final_answer = FinalAnswerTool()
|
80 |
|
81 |
+
MODEL_IDS = [
|
82 |
+
'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud/',
|
83 |
+
'https://jc26mwg228mkj8dw.us-east-1.aws.endpoints.huggingface.cloud/',
|
84 |
+
'meta-llama/Llama-3.2-1B-Instruct',
|
85 |
+
'Qwen/Qwen2.5-Coder-32B-Instruct',
|
86 |
+
'Qwen/Qwen2.5-Coder-1.5B-Instruct'
|
87 |
+
# Add here wherever model is working for you
|
88 |
+
]
|
89 |
+
|
90 |
+
def is_model_overloaded(model_url):
|
91 |
+
"""Verify if the model is overloaded doing a test call."""
|
92 |
+
try:
|
93 |
+
response = requests.post(model_url, json={"inputs": "Test"})
|
94 |
+
if response.status_code == 503: # 503 Service Unavailable = Overloaded
|
95 |
+
return True
|
96 |
+
return False
|
97 |
+
except requests.RequestException:
|
98 |
+
return True # if there are an error is overloaded
|
99 |
+
|
100 |
+
def get_available_model():
|
101 |
+
"""Select the first model available from the list."""
|
102 |
+
for model_url in MODEL_IDS:
|
103 |
+
print("trying model_url\n")
|
104 |
+
if not is_model_overloaded(model_url):
|
105 |
+
return model_url
|
106 |
+
return MODEL_IDS[0] # if all are failing, use the first model by dfault
|
107 |
+
|
108 |
+
selected_model_id = get_available_model()
|
109 |
+
|
110 |
model = HfApiModel(
|
111 |
max_tokens=1048,
|
112 |
temperature=0.5,
|
113 |
#model_id='meta-llama/Llama-3.2-1B-Instruct',
|
114 |
#model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
115 |
+
#model_id = 'Qwen/Qwen2.5-Coder-1.5B-Instruct',
|
116 |
+
model_id = selected_model_id # model available selected from the list automatically
|
117 |
custom_role_conversions=None,
|
118 |
)
|
119 |
|