shlomoc commited on
Commit
4801024
·
verified ·
1 Parent(s): 9f91167

Update app.py

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