翻篇收录说明
翻篇网页快照

Models · Hugging Face

https://huggingface.co/docs/smolagents/reference/models

最近抓取:2026-12-01 11:18:25(北京时间)

最近内容变化:2026-12-01 11:18:25(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

We’re on a journey to advance and democratize artificial intelligence through open source and open science.

正文摘录

smolagents documentation Models smolagents 🏡 View all docsAWS Trainium & InferentiaAccelerateBitsandbytesCLIChat UIDataset viewerDatasetsDeploying on AWSDiffusersGoogle CloudGoogle TPUsGradioHubHub Python LibraryHuggingface.jsInference Endpoints (dedicated)Inference ProvidersKernelsLeRobotLeaderboardsLightevalMicrosoft AzureOpenEnvOptimumPEFTReachy MiniSafetensorsSentence TransformersTRLTasksText Embeddings InferenceTokenizersTrackioTransformersTransformers.jsXetsmolagentstimm Search documentation mainv1.26.0v1.25.0v1.24.0v1.23.0v1.22.0v1.21.2v1.20.0v1.19.0v1.18.0v1.17.0v1.16.1v1.15.0v1.14.0v1.13.0v1.12.0v1.11.0v1.10.0v1.9.2v1.8.1v1.7.0v1.6.0v1.5.1v1.4.1v1.3.0v1.2.2v1.1.0v0.1.3 ENHIKOZH Join the Hugging Face community and get access to the augmented documentation experience Collaborate on models, datasets and Spaces Faster examples with accelerated inference Switch between documentation themes Sign Up to get started Copy page Models Smolagents is an experimental API which is subject to change at any time. Results returned by the agents can vary as the APIs or underlying models are prone to change. To learn more about agents and tools make sure to read the introductory guide. This page contains the API docs for the underlying classes. Models All model classes in smolagents support passing additional keyword arguments (like temperature, max_tokens, top_p, etc.) directly at instantiation time. These parameters are automatically forwarded to the underlying model’s completion calls, allowing you to configure model behavior such as creativity, response length, and sampling strategies. Base Model The Model class serves as the foundation for all model implementations, providing the core interface that custom models must implement to work with agents. class smolagents.Model < source > ( flatten_messages_as_text: bool = False tool_name_key: str = 'name' tool_arguments_key: str = 'arguments' model_id: str | None = None **kwargs ) Parameters flatten_messages_as_text (bool, default False) — Whether to flatten complex message content into plain text format. tool_name_key (str, default "name") — The key used to extract tool names from model responses. tool_arguments_key (str, default "arguments") — The key used to extract tool arguments from model responses. model_id (str, optional) — Identifier for the specific model being used. **kwargs — Additional keyword arguments to forward to the underlying model completion call. Base class for all language model implementations. This abstract class defines the core interface that all model implementations must follow to work with agents. It provides common functionality for message handling, tool integration, and model configuration while allowing subclasses to implement their specific generation logic. Note: This is an abstract base class. Subclasses must implement the generate() method to provide actual model inference capabilities. Example: Copied class CustomModel(Model): def generate(self, messages, **kwargs): # Implementation specific to your model pass generate < source > ( messages: list stop_sequences: list[str] | None = None response_format: dict[str, str] | None = None tools_to_call_from: list[smolagents.tools.Tool] | None = None **kwargs ) → ChatMessage Parameters messages (list[dict[str, str | list[dict]]] | list[ChatMessage]) — A list of message dictionaries to be processed. Each dictionary should have the structure {"role": "user/system", "content": "message content"}. stop_sequences (List[str], optional) — A list of strings that will stop the generation if encountered in the model’s output. response_format (dict[str, str], optional) — The response format to use in the model’s response. tools_to_call_from (List[Tool], optional) — A list of tools that the model can use to generate responses. **kwargs — Additional keyword arguments to be passed to the underlying model. Returns ChatMessage A chat message object containing the model’s response. Process the input messages and return the model’s response. parse_tool_calls < source > ( message: ChatMessage ) Sometimes APIs do not return the tool call as a specific object, so we need to parse it. to_dict < source > ( ) Converts the model into a JSON-compatible dictionary. API Model The ApiModel class serves as the foundation for all API-based model implementations, providing common functionality for external API interactions, rate limiting, and client management that API-specific models inherit. class smolagents.ApiModel < source > ( model_id: str custom_role_conversions: dict[str, str] | None = None client: typing.Optional[typing.Any] = None requests_per_minute: float | None = None retry: bool = True **kwargs ) Parameters model_id (str) — The identifier for the model to be used with the API. custom_role_conversions (dict[str, str], optional) — Mapping to convert between internal role names and API-specific role names. Defaults to None. client (Any, optional) — Pre-configured API client instance. If not provided, a default client will be created. Defaults to None. requests_per_minute (float, optional) — Rate limit in requests per minute. retry (bool, optional) — Whether to retry on rate limit errors, up to RETRY_MAX_ATTEMPTS times. Defaults to True. **kwargs — Additional keyword arguments to forward to the underlying model completion call. Base class for API-based language models. This class serves as a foundation for implementing models that interact with external APIs. It handles the common functionality for managing model IDs, custom role mappings, and API client connections. create_client < source > ( ) Create the API client for the specific service. TransformersModel For convenience, we have added a TransformersModel that implements the points above by building a local transformers pipeline for the model_id given at initialization. Copied from smolagents import TransformersModel model = TransformersModel(model_id="HuggingFaceTB/SmolLM-135M-Instruct") print(model([{"role": "user", "content": [{"type": "text", "text": "Ok!"}]}], stop_sequences=["great"])) Copied >>> What a You can pass any keyword arguments supported by the underlying model (such as temperature, max_new_tokens, top_p, etc.) directly at instantiation time. These are forwarded to the model completion call: Copied model = TransformersModel( model_id="HuggingFaceTB/SmolLM-135M-Instruct", temperature=0.7, max_new_tokens=1000 ) You must have transformers and torch installed on your machine. Please run pip install 'smolagents[transformers]' if it’s not the case. class smolagents.TransformersModel < source > ( model_id: str | None = None device_map: str | None = None torch_dtype: str | None = None trust_remote_code: bool = False model_kwargs: dict[str, typing.Any] | None = None max_new_tokens: int = 4096 max_tokens: int | None = None apply_chat_template_kwargs: dict[str, typing.Any] | None = None **kwargs ) Parameters model_id (str) — The Hugging Face model ID to be used for inference. This can be a path or model identifier from the Hugging Face model hub. For example, "Qwen/Qwen3-Next-80B-A3B-Thinking". device_map (str, optional) — The device_map to initialize your model with. torch_dtype (str, optional) — The torch_dtype to initialize your model with. trust_remote_code (bool, default False) — Some models on the Hub require running remote code: for this model, you would have to set this flag to True. model_kwargs (dict[str, Any], optional) — Additional keyword arguments to pass to AutoModel.from_pretrained (like revision, model_args, config, etc.). max_new_tokens (int, default 4096) — Maximum number of new tokens to generate, ignoring the number of tokens in the prompt. max_tokens (int, optional) — Alias for max_new_tokens. If provided, this value takes precedence. apply_chat_template_kwargs (dict, optional) — Additional keyword arguments to pass to the apply_chat_template method of the tokenizer. **kwargs — Additional keyword arguments to forward to the underlying Transformers model generate call, such as device. Raises ValueError ValueError — If the model name is not provided. A class that uses Hugging Face’s Transformers library for language model interaction. This model allows you to load and use Hugging Face’s models locally using the Transformers library. It supports features like stop sequences and grammar customization. You must have transformers and torch installed on your machine. Please run pip install 'smolagents[transformers]' if it’s not the case. Example: Copied >>> engine = TransformersModel( ... model_id="Qwen/Qwen3-Next-80B-A3B-Thinking", ... device="cuda", ... max_new_tokens=5000, ... ) >>> messages = [{"role": "user", "content": "Explain quantum mechanics in simple terms."}] >>> response = engine(messages, stop_sequences=["END"]) >>> print(response) "Quantum mechanics is the branch of physics that studies..." InferenceClientModel The InferenceClientModel wraps huggingface_hub’s InferenceClient for the execution of the LLM. It supports all Inference Providers available on the Hub: Cerebras, Cohere, Fal, Fireworks, HF-Inference, Hyperbolic, Nebius, Novita, Replicate, SambaNova, Together, and more. You can also set a rate limit in requests per minute by using the requests_per_minute argument: Copied from smolagents import InferenceClientModel messages = [ {"role": "user", "content": [{"type": "text", "text": "Hello, how are you?"}]} ] model = InferenceClientModel(provider="novita", requests_per_minute=60) print(model(messages)) Copied >>> Of course! If you change your mind, feel free to reach out. Take care! You can pass any keyword arguments supported by the underlying model (such as temperature, max_tokens, top_p, etc.) directly at instantiation time. These are forwarded to the model completion call: Copied model = InferenceClientModel( provider="novita", requests_per_minute=60, temperature=0.8, max_tokens=500 ) class smolagents.InferenceClientModel < source > ( model_id: str = 'Qwen/Qwen3-Next-80B-A3B-Thinking' provider: str | None = None toke