Melatonini commited on
Commit
bbd5752
·
1 Parent(s): 79a9a31

Use inference providers router with Llama 3.1 default model.

Browse files

Fix model_not_supported by routing through HF Inference Providers (auto) instead of assuming Qwen on hf-inference.

Files changed (2) hide show
  1. agent.py +8 -3
  2. tools.py +8 -4
agent.py CHANGED
@@ -114,10 +114,15 @@ class BasicAgent:
114
  """Full GAIA agent with search, web, and multimodal file tools."""
115
 
116
  def __init__(self):
117
- model_id = os.getenv("HF_MODEL_ID", "Qwen/Qwen2.5-7B-Instruct")
 
118
  token = os.getenv("HF_TOKEN")
119
 
120
- model = InferenceClientModel(model_id=model_id, token=token)
 
 
 
 
121
  wiki_tool = WikipediaSearchTool(
122
  user_agent="HF-Agents-Course-Student (https://huggingface.co/agents-course)",
123
  language="en",
@@ -139,7 +144,7 @@ class BasicAgent:
139
  additional_authorized_imports=["re", "json", "math"],
140
  )
141
  tool_names = [getattr(t, "name", str(t)) for t in toolset]
142
- print(f"BasicAgent initialized (model={model_id}, tools={tool_names}).")
143
 
144
  def __call__(
145
  self,
 
114
  """Full GAIA agent with search, web, and multimodal file tools."""
115
 
116
  def __init__(self):
117
+ model_id = os.getenv("HF_MODEL_ID", "meta-llama/Meta-Llama-3.1-8B-Instruct")
118
+ provider = os.getenv("HF_INFERENCE_PROVIDER", "auto")
119
  token = os.getenv("HF_TOKEN")
120
 
121
+ model = InferenceClientModel(
122
+ model_id=model_id,
123
+ provider=provider,
124
+ token=token,
125
+ )
126
  wiki_tool = WikipediaSearchTool(
127
  user_agent="HF-Agents-Course-Student (https://huggingface.co/agents-course)",
128
  language="en",
 
144
  additional_authorized_imports=["re", "json", "math"],
145
  )
146
  tool_names = [getattr(t, "name", str(t)) for t in toolset]
147
+ print(f"BasicAgent initialized (model={model_id}, provider={provider}, tools={tool_names}).")
148
 
149
  def __call__(
150
  self,
tools.py CHANGED
@@ -15,13 +15,17 @@ from smolagents import tool
15
  from youtube_transcript_api import YouTubeTranscriptApi
16
 
17
 
18
- def _hf_client() -> InferenceClient:
19
  token = os.getenv("HF_TOKEN")
20
- return InferenceClient(token=token)
 
 
 
 
21
 
22
 
23
  def _vision_model() -> str:
24
- return os.getenv("HF_VISION_MODEL", "Qwen/Qwen2-VL-7B-Instruct")
25
 
26
 
27
  def _asr_model() -> str:
@@ -132,7 +136,7 @@ def analyze_image(file_path: str, question: str) -> str:
132
  }.get(path.suffix.lower(), "image/png")
133
 
134
  encoded = base64.b64encode(path.read_bytes()).decode("ascii")
135
- client = _hf_client()
136
  response = client.chat_completion(
137
  model=_vision_model(),
138
  messages=[
 
15
  from youtube_transcript_api import YouTubeTranscriptApi
16
 
17
 
18
+ def _hf_client(*, for_chat: bool = False) -> InferenceClient:
19
  token = os.getenv("HF_TOKEN")
20
+ if for_chat:
21
+ provider = os.getenv("HF_INFERENCE_PROVIDER", "auto")
22
+ else:
23
+ provider = os.getenv("HF_INFERENCE_PROVIDER", "hf-inference")
24
+ return InferenceClient(token=token, provider=provider)
25
 
26
 
27
  def _vision_model() -> str:
28
+ return os.getenv("HF_VISION_MODEL", "meta-llama/Llama-3.2-11B-Vision-Instruct")
29
 
30
 
31
  def _asr_model() -> str:
 
136
  }.get(path.suffix.lower(), "image/png")
137
 
138
  encoded = base64.b64encode(path.read_bytes()).decode("ascii")
139
+ client = _hf_client(for_chat=True)
140
  response = client.chat_completion(
141
  model=_vision_model(),
142
  messages=[