-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add Hugging Face as LLM provider (#8182)
* add hugging face provider * Update _huggingface.md * add prerequisite * Update app/_hub/kong-inc/ai-proxy-advanced/how-to/llm-provider-integration-guides/_huggingface.md Co-authored-by: lena-larionova <[email protected]> * update tables --------- Co-authored-by: lena-larionova <[email protected]>
- Loading branch information
1 parent
0dd5afe
commit 970435e
Showing
7 changed files
with
191 additions
and
18 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...ng-inc/ai-proxy-advanced/how-to/llm-provider-integration-guides/_huggingface.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
nav_title: Hugging Face | ||
title: Set up AI Proxy Advanced with Hugging Face | ||
minimum_version: 3.9.x | ||
--- | ||
|
||
This guide walks you through setting up the AI Proxy plugin with [Hugging Face](https://huggingface.co/). | ||
|
||
{% include_cached /md/plugins-hub/ai-providers-prereqs-advanced.md snippet='intro' %} | ||
|
||
## Prerequisites | ||
|
||
{% include_cached /md/plugins-hub/ai-providers-prereqs-advanced.md snippet='service' provider='Hugging Face' %} | ||
* Hugging Face access token with permissions to make calls to the Inference API | ||
* [Text-generation model](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending) from Hugging Face | ||
|
||
## Provider configuration | ||
|
||
### Set up route and plugin | ||
|
||
Create the route: | ||
|
||
```bash | ||
curl -X POST http://localhost:8001/services/ai-proxy-advanced/routes \ | ||
--data "name=huggingface-chat" \ | ||
--data "paths[]=~/huggingface-chat$" | ||
``` | ||
|
||
Enable and configure the AI Proxy Advanced plugin for Hugging Face, replacing the `<huggingface_token>` with your own access token and `<huggingface_model>` with the name of the model to use. | ||
|
||
<!--vale off--> | ||
{% plugin_example %} | ||
plugin: kong-inc/ai-proxy-advanced | ||
name: ai-proxy-advanced | ||
config: | ||
targets: | ||
- route_type: "llm/v1/chat" | ||
auth: | ||
header_name: Authorization | ||
header_value: "Bearer <huggingface_token>" | ||
model: | ||
provider: huggingface | ||
name: <huggingface_model> | ||
options: | ||
max_tokens: 512 | ||
temperature: 1.0 | ||
top_p: 256 | ||
top_k: 0.5 | ||
targets: | ||
- route | ||
formats: | ||
- curl | ||
- konnect | ||
- yaml | ||
- kubernetes | ||
- terraform | ||
{% endplugin_example %} | ||
<!--vale on--> | ||
|
||
### Test the configuration | ||
|
||
Make an `llm/v1/chat` type request to test your new endpoint: | ||
|
||
```bash | ||
curl -X POST http://localhost:8000/huggingface-chat \ | ||
-H 'Content-Type: application/json' \ | ||
--data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }' | ||
``` |
10 changes: 5 additions & 5 deletions
10
...ub/kong-inc/ai-proxy-advanced/how-to/llm-provider-integration-guides/_openai.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
app/_hub/kong-inc/ai-proxy/how-to/llm-provider-integration-guides/_huggingface.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
nav_title: Hugging Face | ||
title: Set up AI Proxy with Hugging Face | ||
minimum_version: 3.9.x | ||
--- | ||
|
||
This guide walks you through setting up the AI Proxy plugin with [Hugging Face](https://huggingface.co/). | ||
|
||
{% include_cached /md/plugins-hub/ai-providers-prereqs.md snippet='intro' %} | ||
|
||
## Prerequisites | ||
|
||
{% include_cached /md/plugins-hub/ai-providers-prereqs.md snippet='service' provider='Hugging Face' %} | ||
* Hugging Face access token with permissions to make calls to the Inference API | ||
* [Text-generation model](https://huggingface.co/models?pipeline_tag=text-generation&sort=trending) from Hugging Face | ||
|
||
## Provider configuration | ||
|
||
### Set up route and plugin | ||
|
||
{% navtabs %} | ||
{% navtab Kong Admin API %} | ||
|
||
Create the route: | ||
|
||
```bash | ||
curl -X POST http://localhost:8001/services/ai-proxy/routes \ | ||
--data "name=huggingface-chat" \ | ||
--data "paths[]=~/huggingface-chat$" | ||
``` | ||
|
||
Enable and configure the AI Proxy plugin for Hugging Face, replacing the `<huggingface_token>` with your access token and `<huggingface_model>` with the name of the model to use: | ||
|
||
```bash | ||
curl -X POST http://localhost:8001/routes/huggingface-chat/plugins \ | ||
--data "name=ai-proxy" \ | ||
--data "config.route_type=llm/v1/chat" \ | ||
--data "config.auth.header_name=Authorization" \ | ||
--data "config.auth.header_value= Bearer <huggingface_token>" \ | ||
--data "config.model.provider=huggingface" \ | ||
--data "config.model.name=<huggingface_model>" \ | ||
--data "config.model.options.max_tokens=512" \ | ||
--data "config.model.options.temperature=1.0" \ | ||
--data "config.model.options.top_p=256" \ | ||
--data "config.model.options.top_k=0.5" | ||
``` | ||
|
||
{% endnavtab %} | ||
{% navtab YAML %} | ||
```yaml | ||
routes: | ||
- name: huggingface-chat | ||
service: | ||
name: ai-proxy | ||
paths: | ||
- "~/huggingface-chat$" | ||
methods: | ||
- POST | ||
plugins: | ||
- name: ai-proxy | ||
config: | ||
route_type: "llm/v1/chat" | ||
auth: | ||
header_name: "Authorization" | ||
header_value: "Bearer <huggingface_token>" # add your Hugging Face access token | ||
model: | ||
provider: "huggingface" | ||
name: "<huggingface_model>" # add the Hugging Face model to use | ||
options: | ||
max_tokens: 512 | ||
temperature: 1.0 | ||
top_p: 256 | ||
top_k: 0.5 | ||
``` | ||
{% endnavtab %} | ||
{% endnavtabs %} | ||
### Test the configuration | ||
Make an `llm/v1/chat` type request to test your new endpoint: | ||
|
||
```bash | ||
curl -X POST http://localhost:8000/huggingface-chat \ | ||
-H 'Content-Type: application/json' \ | ||
--data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters