Skip to content

Commit 9ef2764

Browse files
icecrasher321Vikhyath Mondreti
andauthored
feat(tools): add huggingface tools/blcok (#472)
* add hugging face tool * docs: add Hugging Face tool documentation * fix: format and lint Hugging Face integration files * docs: add manual intro section to Hugging Face documentation * feat: replace Record<string, any> with proper HuggingFaceRequestBody interface * accidental local files added * restore some docs * make layout full for model field * change huggingface logo * add manual content * fix lint --------- Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-MacBook-Air.local>
1 parent 3d9c993 commit 9ef2764

File tree

9 files changed

+507
-0
lines changed

9 files changed

+507
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Hugging Face
3+
description: Use Hugging Face Inference API
4+
---
5+
6+
import { BlockInfoCard } from "@/components/ui/block-info-card"
7+
8+
<BlockInfoCard
9+
type="huggingface"
10+
color="#FFD21E"
11+
icon={true}
12+
iconSvg={`<svg className="block-icon"
13+
14+
15+
16+
viewBox='0 0 24 24'
17+
fill='none'
18+
xmlns='http://www.w3.org/2000/svg'
19+
>
20+
<path
21+
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'
22+
fill='currentColor'
23+
/>
24+
</svg>`}
25+
/>
26+
27+
{/* MANUAL-CONTENT-START:intro */}
28+
[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.
29+
With HuggingFace, you can:
30+
31+
Access pre-trained models: Utilize models for text generation, translation, image processing, and more
32+
Generate AI completions: Create content using state-of-the-art language models through the Inference API
33+
Natural language processing: Process and analyze text with specialized NLP models
34+
Deploy at scale: Host and serve models for production applications
35+
Customize models: Fine-tune existing models for specific use cases
36+
37+
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.
38+
{/* MANUAL-CONTENT-END */}
39+
40+
## Usage Instructions
41+
42+
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.
43+
44+
45+
## Tools
46+
47+
### `huggingface_chat`
48+
49+
Generate completions using Hugging Face Inference API
50+
51+
#### Input
52+
53+
| Parameter | Type | Required | Description |
54+
| --------- | ---- | -------- | ----------- |
55+
| `apiKey` | string | Yes | Hugging Face API token |
56+
| `provider` | string | Yes | The provider to use for the API request \(e.g., novita, cerebras, etc.\) |
57+
| `model` | string | Yes | Model to use for chat completions \(e.g., deepseek/deepseek-v3-0324\) |
58+
| `content` | string | Yes | The user message content to send to the model |
59+
| `systemPrompt` | string | No | System prompt to guide the model behavior |
60+
| `maxTokens` | number | No | Maximum number of tokens to generate |
61+
| `temperature` | number | No | Sampling temperature \(0-2\). Higher values make output more random |
62+
| `stream` | boolean | No | Whether to stream the response |
63+
64+
#### Output
65+
66+
| Parameter | Type |
67+
| --------- | ---- |
68+
| `content` | string |
69+
| `model` | string |
70+
| `usage` | string |
71+
| `completion_tokens` | string |
72+
| `total_tokens` | string |
73+
74+
75+
76+
## Block Configuration
77+
78+
### Input
79+
80+
| Parameter | Type | Required | Description |
81+
| --------- | ---- | -------- | ----------- |
82+
| `systemPrompt` | string | No | System Prompt - Enter system prompt to guide the model behavior... |
83+
84+
85+
86+
### Outputs
87+
88+
| Output | Type | Description |
89+
| ------ | ---- | ----------- |
90+
| `response` | object | Output from response |
91+
|`content` | string | content of the response |
92+
|`model` | string | model of the response |
93+
|`usage` | json | usage of the response |
94+
95+
96+
## Notes
97+
98+
- Category: `tools`
99+
- Type: `huggingface`

apps/docs/content/docs/tools/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"google_search",
2020
"google_sheets",
2121
"guesty",
22+
"huggingface",
2223
"image_generator",
2324
"jina",
2425
"jira",
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { HuggingFaceIcon } from '@/components/icons'
2+
import type { HuggingFaceChatResponse } from '@/tools/huggingface/types'
3+
import type { BlockConfig } from '../types'
4+
5+
export const HuggingFaceBlock: BlockConfig<HuggingFaceChatResponse> = {
6+
type: 'huggingface',
7+
name: 'Hugging Face',
8+
description: 'Use Hugging Face Inference API',
9+
longDescription:
10+
'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.',
11+
docsLink: 'https://docs.simstudio.ai/tools/huggingface',
12+
category: 'tools',
13+
bgColor: '#181C1E',
14+
icon: HuggingFaceIcon,
15+
subBlocks: [
16+
{
17+
id: 'systemPrompt',
18+
title: 'System Prompt',
19+
type: 'long-input',
20+
layout: 'full',
21+
placeholder: 'Enter system prompt to guide the model behavior...',
22+
rows: 3,
23+
},
24+
{
25+
id: 'content',
26+
title: 'User Prompt',
27+
type: 'long-input',
28+
layout: 'full',
29+
placeholder: 'Enter your message here...',
30+
rows: 3,
31+
},
32+
{
33+
id: 'provider',
34+
title: 'Provider',
35+
type: 'dropdown',
36+
layout: 'half',
37+
options: [
38+
{ label: 'Novita', id: 'novita' },
39+
{ label: 'Cerebras', id: 'cerebras' },
40+
{ label: 'Cohere', id: 'cohere' },
41+
{ label: 'Fal AI', id: 'fal' },
42+
{ label: 'Fireworks', id: 'fireworks' },
43+
{ label: 'Hyperbolic', id: 'hyperbolic' },
44+
{ label: 'HF Inference', id: 'hf-inference' },
45+
{ label: 'Nebius', id: 'nebius' },
46+
{ label: 'Nscale', id: 'nscale' },
47+
{ label: 'Replicate', id: 'replicate' },
48+
{ label: 'SambaNova', id: 'sambanova' },
49+
{ label: 'Together', id: 'together' },
50+
],
51+
value: () => 'novita',
52+
},
53+
{
54+
id: 'model',
55+
title: 'Model',
56+
type: 'short-input',
57+
layout: 'full',
58+
placeholder:
59+
'e.g., deepseek/deepseek-v3-0324, llama3.1-8b, meta-llama/Llama-3.2-3B-Instruct-Turbo',
60+
description: 'The model must be available for the selected provider.',
61+
},
62+
{
63+
id: 'temperature',
64+
title: 'Temperature',
65+
type: 'slider',
66+
layout: 'half',
67+
min: 0,
68+
max: 2,
69+
value: () => '0.7',
70+
},
71+
{
72+
id: 'maxTokens',
73+
title: 'Max Tokens',
74+
type: 'short-input',
75+
layout: 'half',
76+
placeholder: 'e.g., 1000',
77+
},
78+
{
79+
id: 'apiKey',
80+
title: 'API Token',
81+
type: 'short-input',
82+
layout: 'full',
83+
placeholder: 'Enter your Hugging Face API token',
84+
password: true,
85+
},
86+
],
87+
tools: {
88+
access: ['huggingface_chat'],
89+
config: {
90+
tool: () => 'huggingface_chat',
91+
params: (params) => {
92+
const toolParams = {
93+
apiKey: params.apiKey,
94+
provider: params.provider,
95+
model: params.model,
96+
content: params.content,
97+
systemPrompt: params.systemPrompt,
98+
temperature: params.temperature ? Number.parseFloat(params.temperature) : undefined,
99+
maxTokens: params.maxTokens ? Number.parseInt(params.maxTokens) : undefined,
100+
stream: false, // Always false
101+
}
102+
103+
return toolParams
104+
},
105+
},
106+
},
107+
inputs: {
108+
systemPrompt: { type: 'string', required: false },
109+
content: { type: 'string', required: true },
110+
provider: { type: 'string', required: true },
111+
model: { type: 'string', required: true },
112+
temperature: { type: 'string', required: false },
113+
maxTokens: { type: 'string', required: false },
114+
apiKey: { type: 'string', required: true },
115+
},
116+
outputs: {
117+
response: {
118+
type: {
119+
content: 'string',
120+
model: 'string',
121+
usage: 'json',
122+
},
123+
},
124+
},
125+
}

apps/sim/blocks/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { GoogleCalendarBlock } from './blocks/google_calendar'
2525
import { GoogleDocsBlock } from './blocks/google_docs'
2626
import { GoogleDriveBlock } from './blocks/google_drive'
2727
import { GoogleSheetsBlock } from './blocks/google_sheets'
28+
import { HuggingFaceBlock } from './blocks/huggingface'
2829
// import { GuestyBlock } from './blocks/guesty'
2930
import { ImageGeneratorBlock } from './blocks/image_generator'
3031
import { JinaBlock } from './blocks/jina'
@@ -124,6 +125,7 @@ export const registry: Record<string, BlockConfig> = {
124125
whatsapp: WhatsAppBlock,
125126
x: XBlock,
126127
youtube: YouTubeBlock,
128+
huggingface: HuggingFaceBlock,
127129
}
128130

129131
// Helper functions to access the registry

apps/sim/components/icons.tsx

Lines changed: 43 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)