Edmundoogaz commited on
Commit
a75ece5
·
verified ·
1 Parent(s): 85a75f7

get available model

Browse files
Files changed (1) hide show
  1. app.py +43 -5
app.py CHANGED
@@ -44,11 +44,49 @@ final_answer = FinalAnswerTool()
44
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
45
  # model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  model = HfApiModel(
48
- max_tokens=2096,
49
- temperature=0.5,
50
- model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
51
- custom_role_conversions=None,
52
  )
53
 
54
 
@@ -60,7 +98,7 @@ with open("prompts.yaml", 'r') as stream:
60
 
61
  agent = CodeAgent(
62
  model=model,
63
- tools=[image_generation_tool,final_answer], ## add your tools here (don't remove final answer)
64
  max_steps=6,
65
  verbosity_level=1,
66
  grammar=None,
 
44
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
45
  # model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
 
47
+ MODEL_IDS = [
48
+ #'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud/',
49
+ #'https://jc26mwg228mkj8dw.us-east-1.aws.endpoints.huggingface.cloud/',
50
+ #'meta-llama/Llama-3.2-1B-Instruct', ## Does a poor job of interpreting my questions and matching them to the tools
51
+ 'Qwen/Qwen2.5-Coder-32B-Instruct',
52
+ 'Qwen/Qwen2.5-Coder-14B-Instruct',
53
+ 'Qwen/Qwen2.5-Coder-7B-Instruct',
54
+ 'Qwen/Qwen2.5-Coder-3B-Instruct',
55
+ 'Qwen/Qwen2.5-Coder-1.5B-Instruct'
56
+ # Add here wherever model is working for you
57
+ ]
58
+
59
+ def is_model_overloaded(model_url):
60
+ """Verify if the model is overloaded doing a test call."""
61
+ try:
62
+ response = requests.post(model_url, json={"inputs": "Test"})
63
+ if verbose:
64
+ print(response.status_code)
65
+ if response.status_code == 503: # 503 Service Unavailable = Overloaded
66
+ return True
67
+ if response.status_code == 404: # 404 Client Error: Not Found
68
+ return True
69
+ if response.status_code == 424: # 424 Client Error: Failed Dependency for url:
70
+ return True
71
+ return False
72
+ except requests.RequestException:
73
+ return True # if there are an error is overloaded
74
+
75
+ def get_available_model():
76
+ """Select the first model available from the list."""
77
+ for model_url in MODEL_IDS:
78
+ print("trying",model_url)
79
+ if not is_model_overloaded(model_url):
80
+ return model_url
81
+ return MODEL_IDS[0] # if all are failing, use the first model by dfault
82
+
83
+ selected_model_id = get_available_model()
84
+
85
  model = HfApiModel(
86
+ max_tokens=2096,
87
+ temperature=0.5,
88
+ model_id=selected_model_id,
89
+ custom_role_conversions=None,
90
  )
91
 
92
 
 
98
 
99
  agent = CodeAgent(
100
  model=model,
101
+ tools=[final_answer], ## add your tools here (don't remove final answer)
102
  max_steps=6,
103
  verbosity_level=1,
104
  grammar=None,