huggingface

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package huggingface implements the Hugging Face provider.

Index

Constants

View Source
const Name = "huggingface"

Name of the provider.

Variables

This section is empty.

Functions

func Get

func Get() provider.IProvider

Get returns a setup MongoDB, or set it up.

func ProcessResponse

func ProcessResponse(resp ResponseBody) (string, error)

ProcessResponse processes the response from the API.

func Set

func Set(s provider.IProvider)

Set sets the provider, primarily used for testing.

Types

type Choice

type Choice struct {
	FinishReason string          `json:"finish_reason"`
	Index        int             `json:"index"`
	Message      message.Message `json:"message"`
}

Choice HuggingFace API definition.

type HuggingFace

type HuggingFace struct {
	*provider.Provider

	// Endpoint of the LLM provider.
	Endpoint string `json:"url" validate:"required"`

	// Token of the LLM provider.
	Token string `json:"-" validate:"required"`
	// contains filtered or unexported fields
}

HuggingFace provider definition.

func New

func New(
	options ...provider.ClientFunc,
) (*HuggingFace, error)

New creates a new HuggingFace provider.

func NewDefault

func NewDefault(options ...provider.ClientFunc) (*HuggingFace, error)

NewDefault creates a new HuggingFace provider with default values.

func (*HuggingFace) Completion

func (p *HuggingFace) Completion(ctx context.Context, options ...provider.Func) (string, error)

Completion generates a completion using the provider API. Optionally pass WithResponseBody to unmarshal the response body. It will always return the original, unparsed response body, if no error.

NOTE: Not all options are available for all providers.

func (*HuggingFace) GetClient

func (p *HuggingFace) GetClient() any

GetClient returns the client.

type RequestBody

type RequestBody struct {
	Messages []message.Message `json:"messages"`
	Model    string            `json:"model"`
	Stream   bool              `json:"stream"`

	MaxTokens   int     `json:"max_tokens,omitempty"`
	Seed        int     `json:"seed,omitempty"`
	Temperature float64 `json:"temperature,omitempty"`
	TopP        float64 `json:"top_p,omitempty"`
}

RequestBody represents the request body for the API.

type ResponseBody

type ResponseBody struct {
	Choices []Choice `json:"choices"`
	Created int64    `json:"created"`
	ID      string   `json:"id"`
	Model   string   `json:"model"`
	Object  string   `json:"object"`
	Usage   Usage    `json:"usage"`
}

ResponseBody represents the response body from the HuggingFace API.

type Usage

type Usage struct {
	CompletionTokens int `json:"completion_tokens"`
	PromptTokens     int `json:"prompt_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Usage HuggingFace API definition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址