Hugging Face 프로바이더
Hugging Face 프로바이더
Hugging Face Inference Providers를 통해 수천 개의 언어 모델을 AI SDK에서 쓸 수 있게 해주는 프로바이더예요. Meta, DeepSeek, Qwen 등의 모델을 포함해요.
출처: 문서
본문
Hugging Face 프로바이더는 Hugging Face Inference Providers를 통해 Meta, DeepSeek, Qwen 등의 수천 개 언어 모델에 대한 접근을 제공해요.
API 키는 Hugging Face Settings에서 얻을 수 있어요.
설정 (Setup)
Hugging Face 프로바이더는 @ai-sdk/huggingface 모듈로 제공돼요. 다음과 같이 설치할 수 있어요:
프로바이더 인스턴스 (Provider Instance)
@ai-sdk/huggingface에서 기본 프로바이더 인스턴스 huggingFace를 불러올 수 있어요:
import { huggingFace } from '@ai-sdk/huggingface';
커스텀 구성이 필요하다면 createHuggingFace를 불러와 원하는 설정으로 프로바이더 인스턴스를 만들 수 있어요:
import { createHuggingFace } from '@ai-sdk/huggingface';
const huggingFace = createHuggingFace({
apiKey: process.env.HUGGINGFACE_API_KEY ?? '',
});
Hugging Face 프로바이더 인스턴스를 커스터마이즈할 때 사용할 수 있는 선택적 설정은 다음과 같아요:
-
baseURL string
API 호출에 다른 URL 접두사를 사용해요. 예를 들어 프록시 서버를 쓸 때 유용해요. 기본 접두사는
https://router.huggingface.co/v1이에요. -
apiKey string
Authorization헤더로 보내는 API 키예요. 기본값은HUGGINGFACE_API_KEY환경 변수예요. API 키는 Hugging Face Settings에서 얻을 수 있어요. -
headers Record<string,string>
요청에 포함할 커스텀 헤더예요.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
커스텀 fetch 구현이에요.
언어 모델 (Language Models)
프로바이더 인스턴스로 언어 모델을 만들 수 있어요:
import { huggingFace } from '@ai-sdk/huggingface';
import { generateText } from 'ai';
const { text } = await generateText({
model: huggingFace('deepseek-ai/DeepSeek-V3-0324'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
.responses() 또는 .languageModel() 팩토리 메서드도 사용할 수 있어요:
const model = huggingFace.responses('deepseek-ai/DeepSeek-V3-0324');
// or
const model = huggingFace.languageModel('moonshotai/Kimi-K2-Instruct');
Hugging Face 언어 모델은 streamText 함수에서 사용할 수 있어요 (AI SDK Core 참고).
최신 및 트렌드 모델을 능력, 컨텍스트 크기, 처리량, 가격과 함께 Hugging Face Inference Models 페이지에서 탐색할 수 있어요.
프로바이더 옵션 (Provider Options)
Hugging Face 언어 모델은 providerOptions.huggingface로 전달할 수 있는 프로바이더별 옵션을 지원해요:
import { huggingFace } from '@ai-sdk/huggingface';
import { generateText } from 'ai';
const { text } = await generateText({
model: huggingFace('deepseek-ai/DeepSeek-R1'),
prompt: 'Explain the theory of relativity.',
providerOptions: {
huggingface: {
reasoningEffort: 'high',
instructions: 'Respond in a clear and educational manner.',
},
},
});
다음 프로바이더 옵션을 사용할 수 있어요:
-
metadata Record<string, string>
요청에 포함할 추가 메타데이터예요.
-
instructions string
모델에 대한 지시사항이에요. 추가 컨텍스트나 안내를 제공하는 데 사용할 수 있어요.
-
strictJsonSchema boolean
구조화된 출력에 엄격한 JSON 스키마 검증을 사용할지 여부예요. 기본값은
false. -
reasoningEffort string
DeepSeek-R1 같은 추론 모델의 reasoning effort를 제어해요. 값이 높을수록 더 철저한 추론을 수행해요.
추론 출력 (Reasoning Output)
deepseek-ai/DeepSeek-R1 같은 추론 모델에서 reasoning effort를 제어하고 응답에서 모델의 추론 과정에 접근할 수 있어요:
import { huggingFace } from '@ai-sdk/huggingface';
import { streamText } from 'ai';
const result = streamText({
model: huggingFace('deepseek-ai/DeepSeek-R1'),
prompt: 'How many r letters are in the word strawberry?',
providerOptions: {
huggingface: {
reasoningEffort: 'high',
},
},
});
for await (const part of result.stream) {
if (part.type === 'reasoning') {
console.log(`Reasoning: ${part.textDelta}`);
} else if (part.type === 'text-delta') {
process.stdout.write(part.textDelta);
}
}
generateText를 사용한 비스트리밍 호출의 경우 추론 콘텐츠는 응답의 reasoning 필드에서 사용할 수 있어요:
import { huggingFace } from '@ai-sdk/huggingface';
import { generateText } from 'ai';
const result = await generateText({
model: huggingFace('deepseek-ai/DeepSeek-R1'),
prompt: 'What is 25 * 37?',
providerOptions: {
huggingface: {
reasoningEffort: 'medium',
},
},
});
console.log('Reasoning:', result.reasoning);
console.log('Answer:', result.text);
이미지 입력 (Image Input)
Qwen/Qwen2.5-VL-7B-Instruct 같은 비전 지원 모델의 경우 메시지 콘텐츠의 일부로 이미지를 전달할 수 있어요:
import { huggingFace } from '@ai-sdk/huggingface';
import { generateText } from 'ai';
import { readFileSync } from 'fs';
const result = await generateText({
model: huggingFace('Qwen/Qwen2.5-VL-7B-Instruct'),
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Describe this image in detail.' },
{
type: 'file',
mediaType: 'image',
data: readFileSync('./image.png'),
},
],
},
],
});
이미지 URL도 전달할 수 있어요:
{
type: 'file',
mediaType: 'image',
data: 'https://example.com/image.png',
}
모델 기능 (Model Capabilities)
| 모델 | 이미지 입력 | 객체 생성 | 툴 사용 | 툴 스트리밍 |
|---|---|---|---|---|
meta-llama/Llama-3.1-8B-Instruct |
||||
meta-llama/Llama-3.1-70B-Instruct |
||||
meta-llama/Llama-3.3-70B-Instruct |
||||
meta-llama/Llama-4-Maverick-17B-128E-Instruct |
||||
deepseek-ai/DeepSeek-V3.1 |
||||
deepseek-ai/DeepSeek-V3-0324 |
||||
deepseek-ai/DeepSeek-R1 |
||||
deepseek-ai/DeepSeek-R1-Distill-Llama-70B |
||||
Qwen/Qwen3-32B |
||||
Qwen/Qwen3-Coder-480B-A35B-Instruct |
||||
Qwen/Qwen2.5-VL-7B-Instruct |
||||
google/gemma-3-27b-it |
||||
moonshotai/Kimi-K2-Instruct |
더 알아보기 (Learn more)
- AI Gateway
- xAI Grok
- OpenAI
- Azure OpenAI
- Anthropic
- Open Responses
- Claude Platform on AWS
- Amazon Bedrock
- Groq
- Fal
- AssemblyAI
- GMI Cloud
- TypeSafe
- DeepInfra
- Deepgram
- Black Forest Labs
- Gladia
- Hume
- Google Vertex AI
- Rev.ai
- Baseten
- Hugging Face
- QuiverAI
- Fish Audio
- Mistral AI
- Z.AI
- Together.ai
- Cohere
- Fireworks
- Voyage AI
- DeepSeek
- Moonshot AI
- Alibaba
- MiniMax
- Cerebras
- Replicate
- Prodia
- Perplexity
- Luma
- ByteDance
- Kling AI
- ElevenLabs
- Cartesia