-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(huggingface): add hugging face integration #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a47476c
add hugging face tool
c7c7a1a
docs: add Hugging Face tool documentation
887a04f
fix: format and lint Hugging Face integration files
5c28a4f
docs: add manual intro section to Hugging Face documentation
0d81f90
feat: replace Record<string, any> with proper HuggingFaceRequestBody …
8dc4e8b
accidental local files added
d4b178c
restore some docs
33db17a
make layout full for model field
ac04733
change huggingface logo
3aaaaaf
add manual content
cf5e359
fix lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,99 @@ | ||
| --- | ||
| title: Hugging Face | ||
| description: Use Hugging Face Inference API | ||
| --- | ||
|
|
||
| import { BlockInfoCard } from "@/components/ui/block-info-card" | ||
|
|
||
| <BlockInfoCard | ||
| type="huggingface" | ||
| color="#FFD21E" | ||
| icon={true} | ||
| iconSvg={`<svg className="block-icon" | ||
|
|
||
|
|
||
|
|
||
| viewBox='0 0 24 24' | ||
| fill='none' | ||
| xmlns='http://www.w3.org/2000/svg' | ||
| > | ||
| <path | ||
| d='M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM7 10.5C7.83 10.5 8.5 9.83 8.5 9C8.5 8.17 7.83 7.5 7 7.5C6.17 7.5 5.5 8.17 5.5 9C5.5 9.83 6.17 10.5 7 10.5ZM17 10.5C17.83 10.5 18.5 9.83 18.5 9C18.5 8.17 17.83 7.5 17 7.5C16.17 7.5 15.5 8.17 15.5 9C15.5 9.83 16.17 10.5 17 10.5ZM12 17.5C9.79 17.5 8 15.71 8 13.5H16C16 15.71 14.21 17.5 12 17.5Z' | ||
| fill='currentColor' | ||
| /> | ||
| </svg>`} | ||
| /> | ||
|
|
||
| {/* MANUAL-CONTENT-START:intro */} | ||
| [HuggingFace](https://huggingface.co/) is a leading AI platform that provides access to thousands of pre-trained machine learning models and powerful inference capabilities. With its extensive model hub and robust API, HuggingFace offers comprehensive tools for both research and production AI applications. | ||
| With HuggingFace, you can: | ||
|
|
||
| Access pre-trained models: Utilize models for text generation, translation, image processing, and more | ||
| Generate AI completions: Create content using state-of-the-art language models through the Inference API | ||
| Natural language processing: Process and analyze text with specialized NLP models | ||
| Deploy at scale: Host and serve models for production applications | ||
| Customize models: Fine-tune existing models for specific use cases | ||
|
|
||
| In Sim Studio, the HuggingFace integration enables your agents to programmatically generate completions using the HuggingFace Inference API. This allows for powerful automation scenarios such as content generation, text analysis, code completion, and creative writing. Your agents can generate completions with natural language prompts, access specialized models for different tasks, and integrate AI-generated content into workflows. This integration bridges the gap between your AI workflows and machine learning capabilities, enabling seamless AI-powered automation with one of the world's most comprehensive ML platforms. | ||
| {/* MANUAL-CONTENT-END */} | ||
|
|
||
| ## Usage Instructions | ||
|
|
||
| Generate completions using Hugging Face Inference API with access to various open-source models. Leverage cutting-edge AI models for chat completions, content generation, and AI-powered conversations with customizable parameters. | ||
|
|
||
|
|
||
| ## Tools | ||
|
|
||
| ### `huggingface_chat` | ||
|
|
||
| Generate completions using Hugging Face Inference API | ||
|
|
||
| #### Input | ||
|
|
||
| | Parameter | Type | Required | Description | | ||
| | --------- | ---- | -------- | ----------- | | ||
| | `apiKey` | string | Yes | Hugging Face API token | | ||
| | `provider` | string | Yes | The provider to use for the API request \(e.g., novita, cerebras, etc.\) | | ||
| | `model` | string | Yes | Model to use for chat completions \(e.g., deepseek/deepseek-v3-0324\) | | ||
| | `content` | string | Yes | The user message content to send to the model | | ||
| | `systemPrompt` | string | No | System prompt to guide the model behavior | | ||
| | `maxTokens` | number | No | Maximum number of tokens to generate | | ||
| | `temperature` | number | No | Sampling temperature \(0-2\). Higher values make output more random | | ||
| | `stream` | boolean | No | Whether to stream the response | | ||
|
|
||
| #### Output | ||
|
|
||
| | Parameter | Type | | ||
| | --------- | ---- | | ||
| | `content` | string | | ||
| | `model` | string | | ||
| | `usage` | string | | ||
| | `completion_tokens` | string | | ||
| | `total_tokens` | string | | ||
|
|
||
|
|
||
|
|
||
| ## Block Configuration | ||
|
|
||
| ### Input | ||
|
|
||
| | Parameter | Type | Required | Description | | ||
| | --------- | ---- | -------- | ----------- | | ||
| | `systemPrompt` | string | No | System Prompt - Enter system prompt to guide the model behavior... | | ||
|
|
||
|
|
||
|
|
||
| ### Outputs | ||
|
|
||
| | Output | Type | Description | | ||
| | ------ | ---- | ----------- | | ||
| | `response` | object | Output from response | | ||
| | ↳ `content` | string | content of the response | | ||
| | ↳ `model` | string | model of the response | | ||
| | ↳ `usage` | json | usage of the response | | ||
|
|
||
|
|
||
| ## Notes | ||
|
|
||
| - Category: `tools` | ||
| - Type: `huggingface` | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| "google_search", | ||
| "google_sheets", | ||
| "guesty", | ||
| "huggingface", | ||
| "image_generator", | ||
| "jina", | ||
| "jira", | ||
|
|
||
This file contains hidden or 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,125 @@ | ||
| import { HuggingFaceIcon } from '@/components/icons' | ||
| import type { HuggingFaceChatResponse } from '@/tools/huggingface/types' | ||
| import type { BlockConfig } from '../types' | ||
|
|
||
| export const HuggingFaceBlock: BlockConfig<HuggingFaceChatResponse> = { | ||
| type: 'huggingface', | ||
| name: 'Hugging Face', | ||
| description: 'Use Hugging Face Inference API', | ||
| longDescription: | ||
| 'Generate completions using Hugging Face Inference API with access to various open-source models. Leverage cutting-edge AI models for chat completions, content generation, and AI-powered conversations with customizable parameters.', | ||
| docsLink: 'https://docs.simstudio.ai/tools/huggingface', | ||
| category: 'tools', | ||
| bgColor: '#181C1E', | ||
| icon: HuggingFaceIcon, | ||
| subBlocks: [ | ||
| { | ||
| id: 'systemPrompt', | ||
| title: 'System Prompt', | ||
| type: 'long-input', | ||
| layout: 'full', | ||
| placeholder: 'Enter system prompt to guide the model behavior...', | ||
| rows: 3, | ||
| }, | ||
| { | ||
| id: 'content', | ||
| title: 'User Prompt', | ||
| type: 'long-input', | ||
| layout: 'full', | ||
| placeholder: 'Enter your message here...', | ||
| rows: 3, | ||
| }, | ||
| { | ||
| id: 'provider', | ||
| title: 'Provider', | ||
| type: 'dropdown', | ||
| layout: 'half', | ||
| options: [ | ||
| { label: 'Novita', id: 'novita' }, | ||
| { label: 'Cerebras', id: 'cerebras' }, | ||
| { label: 'Cohere', id: 'cohere' }, | ||
| { label: 'Fal AI', id: 'fal' }, | ||
| { label: 'Fireworks', id: 'fireworks' }, | ||
| { label: 'Hyperbolic', id: 'hyperbolic' }, | ||
| { label: 'HF Inference', id: 'hf-inference' }, | ||
| { label: 'Nebius', id: 'nebius' }, | ||
| { label: 'Nscale', id: 'nscale' }, | ||
| { label: 'Replicate', id: 'replicate' }, | ||
| { label: 'SambaNova', id: 'sambanova' }, | ||
| { label: 'Together', id: 'together' }, | ||
| ], | ||
| value: () => 'novita', | ||
| }, | ||
| { | ||
| id: 'model', | ||
| title: 'Model', | ||
| type: 'short-input', | ||
| layout: 'full', | ||
| placeholder: | ||
| 'e.g., deepseek/deepseek-v3-0324, llama3.1-8b, meta-llama/Llama-3.2-3B-Instruct-Turbo', | ||
| description: 'The model must be available for the selected provider.', | ||
| }, | ||
| { | ||
| id: 'temperature', | ||
| title: 'Temperature', | ||
| type: 'slider', | ||
| layout: 'half', | ||
| min: 0, | ||
| max: 2, | ||
| value: () => '0.7', | ||
| }, | ||
| { | ||
| id: 'maxTokens', | ||
| title: 'Max Tokens', | ||
| type: 'short-input', | ||
| layout: 'half', | ||
| placeholder: 'e.g., 1000', | ||
| }, | ||
| { | ||
| id: 'apiKey', | ||
| title: 'API Token', | ||
| type: 'short-input', | ||
| layout: 'full', | ||
| placeholder: 'Enter your Hugging Face API token', | ||
| password: true, | ||
| }, | ||
| ], | ||
| tools: { | ||
| access: ['huggingface_chat'], | ||
| config: { | ||
| tool: () => 'huggingface_chat', | ||
| params: (params) => { | ||
| const toolParams = { | ||
| apiKey: params.apiKey, | ||
| provider: params.provider, | ||
| model: params.model, | ||
| content: params.content, | ||
| systemPrompt: params.systemPrompt, | ||
| temperature: params.temperature ? Number.parseFloat(params.temperature) : undefined, | ||
| maxTokens: params.maxTokens ? Number.parseInt(params.maxTokens) : undefined, | ||
| stream: false, // Always false | ||
| } | ||
|
|
||
| return toolParams | ||
| }, | ||
| }, | ||
| }, | ||
| inputs: { | ||
| systemPrompt: { type: 'string', required: false }, | ||
| content: { type: 'string', required: true }, | ||
| provider: { type: 'string', required: true }, | ||
| model: { type: 'string', required: true }, | ||
| temperature: { type: 'string', required: false }, | ||
| maxTokens: { type: 'string', required: false }, | ||
| apiKey: { type: 'string', required: true }, | ||
| }, | ||
| outputs: { | ||
| response: { | ||
| type: { | ||
| content: 'string', | ||
| model: 'string', | ||
| usage: 'json', | ||
| }, | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.