Skip to main content

Class: HuggingFaceInferenceAPI

Wrapper on the Hugging Face's Inference API. API Docs: https://huggingface.co/docs/huggingface.js/inference/README List of tasks with models: huggingface.co/api/tasks

Note that Conversational API is not yet supported by the Inference API. They recommend using the text generation API instead. See: https://github.com/huggingface/huggingface.js/issues/586#issuecomment-2024059308

Extends

Constructors

new HuggingFaceInferenceAPI()

new HuggingFaceInferenceAPI(init): HuggingFaceInferenceAPI

Parameters

init: HFConfig

Returns

HuggingFaceInferenceAPI

Overrides

BaseLLM . constructor

Source

packages/llamaindex/src/llm/huggingface.ts:88

Properties

contextWindow

contextWindow: number

Source

packages/llamaindex/src/llm/huggingface.ts:85


hf

hf: HfInference

Source

packages/llamaindex/src/llm/huggingface.ts:86


maxTokens?

optional maxTokens: number

Source

packages/llamaindex/src/llm/huggingface.ts:84


model

model: string

Source

packages/llamaindex/src/llm/huggingface.ts:81


temperature

temperature: number

Source

packages/llamaindex/src/llm/huggingface.ts:82


topP

topP: number

Source

packages/llamaindex/src/llm/huggingface.ts:83

Accessors

metadata

get metadata(): LLMMetadata

Returns

LLMMetadata

Source

packages/llamaindex/src/llm/huggingface.ts:109

Methods

chat()

chat(params)

chat(params): Promise<AsyncIterable <ChatResponseChunk>>

Get a chat response from the LLM

Parameters

params: LLMChatParamsStreaming<object, object>

Returns

Promise<AsyncIterable <ChatResponseChunk>>

Overrides

BaseLLM . chat

Source

packages/llamaindex/src/llm/huggingface.ts:120

chat(params)

chat(params): Promise <ChatResponse<object>>

Parameters

params: LLMChatParamsNonStreaming<object, object>

Returns

Promise <ChatResponse<object>>

Overrides

BaseLLM . chat

Source

packages/llamaindex/src/llm/huggingface.ts:123


complete()

complete(params)

complete(params): Promise<AsyncIterable <CompletionResponse>>

Get a prompt completion from the LLM

Parameters

params: LLMCompletionParamsStreaming

Returns

Promise<AsyncIterable <CompletionResponse>>

Inherited from

BaseLLM . complete

Source

packages/core/dist/llms/index.d.ts:168

complete(params)

complete(params): Promise <CompletionResponse>

Parameters

params: LLMCompletionParamsNonStreaming

Returns

Promise <CompletionResponse>

Inherited from

BaseLLM . complete

Source

packages/core/dist/llms/index.d.ts:169


messagesToPrompt()

private messagesToPrompt(messages): string

Parameters

messages: ChatMessage <ToolCallLLMMessageOptions>[]

Returns

string

Source

packages/llamaindex/src/llm/huggingface.ts:132


nonStreamChat()

protected nonStreamChat(params): Promise <ChatResponse<object>>

Parameters

params: LLMChatParamsNonStreaming<object, object>

Returns

Promise <ChatResponse<object>>

Source

packages/llamaindex/src/llm/huggingface.ts:152


streamChat()

protected streamChat(params): AsyncIterable <ChatResponseChunk>

Parameters

params: LLMChatParamsStreaming<object, object>

Returns

AsyncIterable <ChatResponseChunk>

Source

packages/llamaindex/src/llm/huggingface.ts:169