anuragrawal commited on
Commit
23b06d7
·
verified ·
1 Parent(s): ba90f9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -1
app.py CHANGED
@@ -34,11 +34,51 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  final_answer = FinalAnswerTool()
38
  model = HfApiModel(
39
  max_tokens=2096,
40
  temperature=0.5,
41
- model_id= 'meta-llama/Llama-3.2-1B',#'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
42
  custom_role_conversions=None,
43
  )
44
 
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
+ MODEL_IDS = [
38
+ #'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud/',
39
+ #'https://jc26mwg228mkj8dw.us-east-1.aws.endpoints.huggingface.cloud/',
40
+ #'meta-llama/Llama-3.2-1B-Instruct', ## Does a poor job of interpreting my questions and matching them to the tools
41
+ 'Qwen/Qwen2.5-Coder-32B-Instruct',
42
+ 'Qwen/Qwen2.5-Coder-14B-Instruct',
43
+ 'Qwen/Qwen2.5-Coder-7B-Instruct',
44
+ 'Qwen/Qwen2.5-Coder-3B-Instruct',
45
+ 'Qwen/Qwen2.5-Coder-1.5B-Instruct'
46
+ # Add here wherever model is working for you
47
+ ]
48
+
49
+ def is_model_overloaded(model_url):
50
+ """Verify if the model is overloaded doing a test call."""
51
+ try:
52
+ response = requests.post(model_url, json={"inputs": "Test"})
53
+ if verbose:
54
+ print(response.status_code)
55
+ if response.status_code == 503: # 503 Service Unavailable = Overloaded
56
+ return True
57
+ if response.status_code == 404: # 404 Client Error: Not Found
58
+ return True
59
+ if response.status_code == 424: # 424 Client Error: Failed Dependency for url:
60
+ return True
61
+ return False
62
+ except requests.RequestException:
63
+ return True # if there are an error is overloaded
64
+
65
+ def get_available_model():
66
+ """Select the first model available from the list."""
67
+ for model_url in MODEL_IDS:
68
+ print("trying",model_url)
69
+ if not is_model_overloaded(model_url):
70
+ return model_url
71
+ return MODEL_IDS[0] # if all are failing, use the first model by dfault
72
+
73
+ if verbose: print("Checking available models.")
74
+
75
+ selected_model_id = get_available_model()
76
+
77
  final_answer = FinalAnswerTool()
78
  model = HfApiModel(
79
  max_tokens=2096,
80
  temperature=0.5,
81
+ model_id= selected_model_id,#'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
82
  custom_role_conversions=None,
83
  )
84