HuggingFaceBackendAdapter
Defined in: backend/src/providers/huggingface.ts:108
Backend adapter for Hugging Face Inference API.
Supports text generation models from Hugging Face Hub.
Examples
Section titled “Examples”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',});Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new HuggingFaceBackendAdapter(
config):HuggingFaceBackendAdapter
Defined in: backend/src/providers/huggingface.ts:116
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”HuggingFaceBackendAdapter
Properties
Section titled “Properties”metadata
Section titled “metadata”
readonlymetadata:AdapterMetadata
Defined in: backend/src/providers/huggingface.ts:112
Adapter metadata for identification and capabilities.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”estimateCost()
Section titled “estimateCost()”estimateCost(
request):Promise<number|null>
Defined in: backend/src/providers/huggingface.ts:256
Estimate cost for Hugging Face.
Parameters
Section titled “Parameters”request
Section titled “request”Returns
Section titled “Returns”Promise<number | null>
Implementation of
Section titled “Implementation of”execute()
Section titled “execute()”execute(
request,signal?):Promise<IRChatResponse>
Defined in: backend/src/providers/huggingface.ts:148
Execute non-streaming chat completion request.
Parameters
Section titled “Parameters”request
Section titled “request”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Promise<IRChatResponse>
Implementation of
Section titled “Implementation of”executeStream()
Section titled “executeStream()”executeStream(
request,_signal?):IRChatStream
Defined in: backend/src/providers/huggingface.ts:187
Execute streaming chat completion request.
Parameters
Section titled “Parameters”request
Section titled “request”_signal?
Section titled “_signal?”AbortSignal
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”fromIR()
Section titled “fromIR()”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.
Parameters
Section titled “Parameters”request
Section titled “request”Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”healthCheck()
Section titled “healthCheck()”healthCheck():
Promise<boolean>
Defined in: backend/src/providers/huggingface.ts:238
Health check for Hugging Face API.
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”toIR()
Section titled “toIR()”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.
Parameters
Section titled “Parameters”response
Section titled “response”HuggingFaceResponse | HuggingFaceResponse[]
originalRequest
Section titled “originalRequest”latencyMs
Section titled “latencyMs”number