huggingfaceclient

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken  = errors.New("invalid token")
	ErrEmptyResponse = errors.New("empty response")
)
View Source
var ErrUnexpectedStatusCode = errors.New("unexpected status code")

Functions

This section is empty.

Types

type Client

type Client struct {
	Token string
	Model string
	// contains filtered or unexported fields
}

func New

func New(token string, model string) (*Client, error)

func (*Client) CreateEmbedding

func (c *Client) CreateEmbedding(
	ctx context.Context,
	model string,
	task string,
	r *EmbeddingRequest,
) ([][]float64, error)

CreateEmbedding creates embeddings.

func (*Client) RunInference

func (c *Client) RunInference(ctx context.Context, request *InferenceRequest) (*InferenceResponse, error)

type EmbeddingRequest

type EmbeddingRequest struct {
	Options map[string]any `json:"options"`
	Inputs  []string       `json:"inputs"`
}

EmbeddingRequest is a request to create an embedding.

type InferenceRequest

type InferenceRequest struct {
	Model             string        `json:"repositoryId"`
	Prompt            string        `json:"prompt"`
	Task              InferenceTask `json:"task"`
	Temperature       float64       `json:"temperature,omitempty"`
	TopP              float64       `json:"top_p,omitempty"`
	TopK              int           `json:"top_k,omitempty"`
	MinLength         int           `json:"min_length,omitempty"`
	MaxLength         int           `json:"max_length,omitempty"`
	RepetitionPenalty float64       `json:"repetition_penalty,omitempty"`
	Seed              int           `json:"seed,omitempty"`
}

type InferenceResponse

type InferenceResponse struct {
	Text string `json:"generated_text"`
}

type InferenceTask

type InferenceTask string

InferenceTask is the type of inference task to run.

const (
	InferenceTaskTextGeneration      InferenceTask = "text-generation"
	InferenceTaskText2TextGeneration InferenceTask = "text2text-generation"
)

Jump to

Keyboard shortcuts

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