feat: hugging face supports embeddings. (#19)

pull/21/head
Garfield Dai 2023-09-24 23:03:55 +08:00 committed by GitHub
parent 47af2d5740
commit beb1354f54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

View File

@ -1,17 +1,22 @@
# Hugging Face
Dify supports models of the [text-generation](https://huggingface.co/models?pipeline_tag=text-generation\&sort=trending) and [text2text-generation](https://huggingface.co/models?pipeline_tag=text2text-generation\&sort=trending) types on the Hugging Face. Specific steps are as follows:
Dify supports Text-Generation and Embeddings. Below are the corresponding Hugging Face model types:
* Text-Generation[text-generation](https://huggingface.co/models?pipeline\_tag=text-generation\&sort=trending)[text2text-generation](https://huggingface.co/models?pipeline\_tag=text2text-generation\&sort=trending) 
* Embeddings[feature-extraction](https://huggingface.co/models?pipeline\_tag=feature-extraction\&sort=trending)
The specific steps are as follows:
1. You need a Hugging Face account ([registered address](https://huggingface.co/join)).
2. Set the API key of Hugging Face ([obtain address](https://huggingface.co/settings/tokens)).
3. Select a model to enter the [Hugging Face model list page](https://huggingface.co/models?pipeline_tag=text-generation\&sort=trending), and filter the models with [text-generation](https://huggingface.co/models?pipeline_tag=text-generation\&sort=trending) and [text2text-generation](https://huggingface.co/models?pipeline_tag=text2text-generation\&sort=trending).
3. Select a model to enter the [Hugging Face model list page](https://huggingface.co/models?pipeline_tag=text-generation\&sort=trending).
<figure><img src="../../.gitbook/assets/image (74).png" alt=""><figcaption></figcaption></figure>
Dify supports accessing models on Hugging Face in two ways:
1. Hosted Inference API. This method uses the model officially deployed by Hugging Face. No fee is required. But the downside is that only a small number of models support this approach.
2. Inference Endpiont. This method uses resources such as AWS accessed by the Hugging Face to deploy the model and requires payment.
2. Inference Endpoint. This method uses resources such as AWS accessed by the Hugging Face to deploy the model and requires payment.
### Models that access the Hosted Inference API
@ -27,9 +32,9 @@ On the model details page, you can get the name of the model.
#### 2 Using access models in Dify
Select Hosted Inference API for Endpoint Type in `Settings > Model Provider > Hugging Face`. As shown below:
Select Hosted Inference API for Endpoint Type in `Settings > Model Provider > Hugging Face > Model Type`. As shown below:
<figure><img src="../../.gitbook/assets/image (77).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (85).png" alt=""><figcaption></figcaption></figure>
API Token is the API Key set at the beginning of the article. The model name is the model name obtained in the previous step.
@ -39,7 +44,7 @@ API Token is the API Key set at the beginning of the article. The model name is
#### 1 Select the model to deploy
Inference Endpiont is only supported for models with the Inference Endpionts option under the Deploy button on the right side of the model details page. As shown below:
Inference Endpoint is only supported for models with the Inference Endpoints option under the Deploy button on the right side of the model details page. As shown below:
<figure><img src="../../.gitbook/assets/image (78).png" alt=""><figcaption></figcaption></figure>
@ -47,7 +52,7 @@ Inference Endpiont is only supported for models with the Inference Endpionts opt
#### 2 Deployment model
Click the Deploy button for the model and select the Inference Endpiont option. If you have not bound a bank card before, you will need to bind the card. Just follow the process. After binding the card, the following interface will appear: modify the configuration according to the requirements, and click Create Endpoint in the lower left corner to create an Inference Endpoint.
Click the Deploy button for the model and select the Inference Endpoint option. If you have not bound a bank card before, you will need to bind the card. Just follow the process. After binding the card, the following interface will appear: modify the configuration according to the requirements, and click Create Endpoint in the lower left corner to create an Inference Endpoint.
<figure><img src="../../.gitbook/assets/image (79).png" alt=""><figcaption></figcaption></figure>
@ -57,8 +62,12 @@ After the model is deployed, you can see the Endpoint URL.
#### 3 Using access models in Dify
Select Inference Endpoints for Endpoint Type in `Settings > Model Provider > Hugging face`. As shown below:
Select Inference Endpoints for Endpoint Type in `Settings > Model Provider > Hugging face > Model Type`. As shown below:
<figure><img src="../../.gitbook/assets/image (81).png" alt=""><figcaption></figcaption></figure>
<figure><img src="../../.gitbook/assets/image (87).png" alt=""><figcaption></figcaption></figure>
API Token is the API Key set at the beginning of the article. The name of the model is arbitrary. Endpoint URL is the Endpoint URL obtained after successfully deploying the model in the previous step.
The API Token is the API Key set at the beginning of the article. ```The name of the Text-Generation model can be arbitrary, but the name of the Embeddings model needs to be consistent with Hugging Face.``` The Endpoint URL is the Endpoint URL obtained after the successful deployment of the model in the previous step.
<figure><img src="../../.gitbook/assets/image (86).png" alt=""><figcaption></figcaption></figure>
> Note: The "User name / Organization Name" for Embeddings needs to be filled in according to your deployment method on Hugging Face's [Inference Endpoints](https://huggingface.co/docs/inference-endpoints/guides/access), with either the ''[User name](https://huggingface.co/settings/account)'' or the "[Organization Name](https://ui.endpoints.huggingface.co/)".