(
prompt: str,
tools: list[str],
model_type: str,
model_id: str,
api_base: str | None = None,
api_key: str | None = None,
imports: list[str] | None = None,
provider: str | None = None,
action_type: str = "code",
)
| 217 | |
| 218 | |
| 219 | def run_smolagent( |
| 220 | prompt: str, |
| 221 | tools: list[str], |
| 222 | model_type: str, |
| 223 | model_id: str, |
| 224 | api_base: str | None = None, |
| 225 | api_key: str | None = None, |
| 226 | imports: list[str] | None = None, |
| 227 | provider: str | None = None, |
| 228 | action_type: str = "code", |
| 229 | ) -> None: |
| 230 | load_dotenv() |
| 231 | |
| 232 | model = load_model(model_type, model_id, api_base=api_base, api_key=api_key, provider=provider) |
| 233 | |
| 234 | available_tools = [] |
| 235 | |
| 236 | for tool_name in tools: |
| 237 | if "/" in tool_name: |
| 238 | space_name = tool_name.split("/")[-1].lower().replace("-", "_").replace(".", "_") |
| 239 | description = f"Tool loaded from Hugging Face Space: {tool_name}" |
| 240 | available_tools.append(Tool.from_space(space_id=tool_name, name=space_name, description=description)) |
| 241 | else: |
| 242 | if tool_name in TOOL_MAPPING: |
| 243 | available_tools.append(TOOL_MAPPING[tool_name]()) |
| 244 | else: |
| 245 | raise ValueError(f"Tool {tool_name} is not recognized either as a default tool or a Space.") |
| 246 | |
| 247 | if action_type == "code": |
| 248 | agent = CodeAgent( |
| 249 | tools=available_tools, |
| 250 | model=model, |
| 251 | additional_authorized_imports=imports, |
| 252 | stream_outputs=True, |
| 253 | ) |
| 254 | elif action_type == "tool_calling": |
| 255 | agent = ToolCallingAgent(tools=available_tools, model=model, stream_outputs=True) |
| 256 | else: |
| 257 | raise ValueError(f"Unsupported action type: {action_type}") |
| 258 | |
| 259 | agent.run(prompt) |
| 260 | |
| 261 | |
| 262 | def main() -> None: |
searching dependent graphs…