perplexity

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKeyEnvVar = "PERPLEXITY_API_KEY"

	EncodingFormatBase64Int8 = "base64_int8"
)

Variables

This section is empty.

Functions

func ContextWithModel

func ContextWithModel(ctx context.Context, model string) context.Context

Types

type CreateEmbeddingRequest

type CreateEmbeddingRequest struct {
	Model          string           `json:"model"`
	Input          *EmbeddingInputs `json:"input"`
	Dimensions     *int             `json:"dimensions,omitempty"`
	EncodingFormat string           `json:"encoding_format"`
}

func (*CreateEmbeddingRequest) JSON

func (c *CreateEmbeddingRequest) JSON() (string, error)

type CreateEmbeddingResponse

type CreateEmbeddingResponse struct {
	Object string            `json:"object"`
	Data   []EmbeddingResult `json:"data"`
	Model  string            `json:"model"`
	Usage  *UsageResult      `json:"usage,omitempty"`
}

type EmbeddingInputs

type EmbeddingInputs struct {
	Input  string
	Inputs []string
}

func (*EmbeddingInputs) MarshalJSON

func (e *EmbeddingInputs) MarshalJSON() ([]byte, error)

type EmbeddingResult

type EmbeddingResult struct {
	Object    string               `json:"object"`
	Embedding *EmbeddingTypeResult `json:"embedding"`
	Index     int                  `json:"index"`
}

type EmbeddingTypeResult

type EmbeddingTypeResult struct {
	Floats []float32
}

func (*EmbeddingTypeResult) UnmarshalJSON

func (e *EmbeddingTypeResult) UnmarshalJSON(data []byte) error

type Option

type Option func(p *PerplexityClient) error

func WithAPIKey

func WithAPIKey(apiKey string) Option

func WithAPIKeyFromEnvVar

func WithAPIKeyFromEnvVar(envVar string) Option

WithAPIKeyFromEnvVar sets the API key for the client from a specified environment variable.

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithDimensions

func WithDimensions(dimensions int) Option

func WithEnvAPIKey

func WithEnvAPIKey() Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithInsecure

func WithInsecure() Option

WithInsecure allows the client to connect to HTTP endpoints without TLS. This should only be used for local development or testing.

func WithModel

func WithModel(model embeddings.EmbeddingModel) Option

type PerplexityClient

type PerplexityClient struct {
	APIKey embeddings.Secret `json:"-" validate:"required"`
	// contains filtered or unexported fields
}

func NewPerplexityClient

func NewPerplexityClient(opts ...Option) (*PerplexityClient, error)

func (*PerplexityClient) CreateEmbedding

type PerplexityEmbeddingFunction

type PerplexityEmbeddingFunction struct {
	// contains filtered or unexported fields
}

func NewPerplexityEmbeddingFunction

func NewPerplexityEmbeddingFunction(opts ...Option) (*PerplexityEmbeddingFunction, error)

func (*PerplexityEmbeddingFunction) DefaultSpace

func (*PerplexityEmbeddingFunction) EmbedDocuments

func (e *PerplexityEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]embeddings.Embedding, error)

func (*PerplexityEmbeddingFunction) EmbedQuery

func (*PerplexityEmbeddingFunction) GetConfig

func (*PerplexityEmbeddingFunction) Name

func (*PerplexityEmbeddingFunction) SupportedSpaces

func (e *PerplexityEmbeddingFunction) SupportedSpaces() []embeddings.DistanceMetric

type UsageResult

type UsageResult struct {
	PromptTokens int `json:"prompt_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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