Skip to content

HuggingFaceBackendAdapter

Defined in: backend/src/providers/huggingface.ts:108

Backend adapter for Hugging Face Inference API.

Supports text generation models from Hugging Face Hub.

import { HuggingFaceBackendAdapter } from 'ai.matey';
const adapter = new HuggingFaceBackendAdapter({
apiKey: process.env.HUGGINGFACE_API_KEY,
});
const adapter = new HuggingFaceBackendAdapter({
apiKey: process.env.HUGGINGFACE_API_KEY,
});
const response = await adapter.execute({
messages: [{ role: 'user', content: 'Hello!' }],
parameters: {
model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
},
});
const adapter = new HuggingFaceBackendAdapter({
apiKey: process.env.HUGGINGFACE_API_KEY,
baseURL: 'https://your-endpoint.aws.endpoints.huggingface.cloud',
});

new HuggingFaceBackendAdapter(config): HuggingFaceBackendAdapter

Defined in: backend/src/providers/huggingface.ts:116

BackendAdapterConfig

HuggingFaceBackendAdapter

readonly metadata: AdapterMetadata

Defined in: backend/src/providers/huggingface.ts:112

Adapter metadata for identification and capabilities.

BackendAdapter.metadata

estimateCost(request): Promise<number | null>

Defined in: backend/src/providers/huggingface.ts:256

Estimate cost for Hugging Face.

IRChatRequest

Promise<number | null>

BackendAdapter.estimateCost


execute(request, signal?): Promise<IRChatResponse>

Defined in: backend/src/providers/huggingface.ts:148

Execute non-streaming chat completion request.

IRChatRequest

AbortSignal

Promise<IRChatResponse>

BackendAdapter.execute


executeStream(request, _signal?): IRChatStream

Defined in: backend/src/providers/huggingface.ts:187

Execute streaming chat completion request.

IRChatRequest

AbortSignal

IRChatStream

BackendAdapter.executeStream


fromIR(request): HuggingFaceRequest

Defined in: backend/src/providers/huggingface.ts:279

Convert IR request to Hugging Face format.

Public method for testing and debugging - see what will be sent to Hugging Face.

IRChatRequest

HuggingFaceRequest

BackendAdapter.fromIR


healthCheck(): Promise<boolean>

Defined in: backend/src/providers/huggingface.ts:238

Health check for Hugging Face API.

Promise<boolean>

BackendAdapter.healthCheck


toIR(response, originalRequest, latencyMs): IRChatResponse

Defined in: backend/src/providers/huggingface.ts:320

Convert Hugging Face response to IR format.

Public method for testing and debugging - parse Hugging Face responses manually.

HuggingFaceResponse | HuggingFaceResponse[]

IRChatRequest

number

IRChatResponse

BackendAdapter.toIR