Hugging Face
与Hugging Face平台相关的所有功能。
安装
大多数 Hugging Face 集成都可在 langchain-huggingface 包中使用。
pip install langchain-huggingface
聊天模型
ChatHuggingFace
我们可以使用 Hugging Face LLM 类或直接使用 ChatHuggingFace 类。
查看一个 使用示例。
from langchain_huggingface import ChatHuggingFace
LLMs
HuggingFaceEndpoint
查看一个 使用示例。
from langchain_huggingface import HuggingFaceEndpoint
HuggingFacePipeline
Hugging Face模型可以通过HuggingFacePipeline类在本地运行。
查看一个 使用示例。
from langchain_huggingface import HuggingFacePipeline
嵌入模型
HuggingFaceEmbeddings
查看一个 使用示例。
from langchain_huggingface import HuggingFaceEmbeddings
HuggingFaceEndpointEmbeddings
查看一个 使用示例。
from langchain_huggingface import HuggingFaceEndpointEmbeddings
HuggingFaceInferenceAPIEmbeddings
查看一个 使用示例。
from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
HuggingFaceInstructEmbeddings
查看一个 使用示例。
from langchain_community.embeddings import HuggingFaceInstructEmbeddings
HuggingFaceBgeEmbeddings
BGE models on the HuggingFace are one of the best open-source embedding models. BGE model is created by the Beijing Academy of Artificial Intelligence (BAAI).
BAAIis a private non-profit organization engaged in AI research and development.
查看一个 使用示例。
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
文档加载器
Hugging Face数据集
Hugging Face Hub is home to over 75,000 datasets in more than 100 languages that can be used for a broad range of tasks across NLP, Computer Vision, and Audio. They used for a diverse range of tasks such as translation, automatic speech recognition, and image classification.
我们需要安装 datasets 个 Python 包。
pip install datasets
查看一个 使用示例。
from langchain_community.document_loaders.hugging_face_dataset import HuggingFaceDatasetLoader
Hugging Face模型加载器
Load model information from
Hugging Face Hub, including README content.This loader interfaces with the
Hugging Face Models APIto fetch and load model metadata and README files. The API allows you to search and filter models based on specific criteria such as model tags, authors, and more.
from langchain_community.document_loaders import HuggingFaceModelLoader
图片说明
它使用 Hugging Face 模型来自动生成图像描述。
我们需要安装几个 Python 包。
pip install transformers pillow
查看一个 使用示例。
from langchain_community.document_loaders import ImageCaptionLoader
工具
Hugging Face Hub 工具
Hugging Face Tools support text I/O and are loaded using the
load_huggingface_toolfunction.
我们需要安装几个 Python 包。
pip install transformers huggingface_hub
查看一个 使用示例。
from langchain_community.agent_toolkits.load_tools import load_huggingface_tool
Hugging Face 文本转语音模型推理。
It is a wrapper around
OpenAI Text-to-Speech API.
from langchain_community.tools.audio import HuggingFaceTextToSpeechModelInference