tool

hugging face model.

Functions

get_lc_hf

Get a hugging face langchain base chat model.

get_transformers_pipeline

Create a text generation pipeline using a specified pre-trained language model.

Classes

class HFChat(pipeline, **kwargs)[source]

Bases: SimpleChatModel

Parameters:
  • pipeline (Any)

  • name (str | None)

  • cache (BaseCache | bool | None)

  • verbose (bool)

  • callbacks (list[BaseCallbackHandler] | BaseCallbackManager | None)

  • tags (list[str] | None)

  • metadata (dict[str, Any] | None)

  • custom_get_token_ids (Callable[[str], list[int]] | None)

  • callback_manager (BaseCallbackManager | None)

  • rate_limiter (BaseRateLimiter | None)

  • disable_streaming (bool | Literal['tool_calling'])

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'ignore', 'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

get_lc_hf(**kwargs)[source]

Get a hugging face langchain base chat model.

Parameters:

kwargs – Key value argument to pass on.

Return type:

BaseChatModel

Returns:

A hugging face langchain base chat model.

get_transformers_pipeline(model, api_key=None, quantization=None, model_kwargs=None, max_new_tokens=None, pipeline_kwargs=None)[source]

Create a text generation pipeline using a specified pre-trained language model.

Parameters:

model (str): The name or path of the pre-trained language model. api_key (str, optional): HuggingFace token for authentification. Default is None. quantization (str, optional): The quantization type to apply to the model. Options are ‘4bit’, ‘8bit’, or None. Default is None. model_kwargs (dict, optional): Additional keyword arguments to pass to the model during initialization. Default is None. max_new_tokens (int, optional): The maximum number of new tokens to generate. Default is None. pipeline_kwargs (dict, optional): Additional keyword arguments to pass to the pipeline during initialization. Default is None.

Returns:

pipeline object: A text generation pipeline initialized with the specified model, tokenizer, and pipeline arguments.

Parameters:
  • model (str)

  • api_key (str | None)

  • quantization (str | None)

  • model_kwargs (dict | None)

  • max_new_tokens (int | None)

  • pipeline_kwargs (dict | None)