perplexity

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultModel = "sonar-pro"

DefaultModel is the default model for the Perplexity API.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for the Perplexity API.

View Source
const DefaultURL = "https://api.perplexity.ai/chat/completions"

DefaultURL is the default endpoint for the Perplexity API.

Variables

View Source
var Transformer = func(e Event) (*prompts.ChatCompletionResponse, error) {
	resp := &prompts.ChatCompletionResponse{}

	if err := json.Unmarshal(e.Data, &resp); err != nil {
		return nil, err
	}

	return resp, nil
}

Transformer is a function that transforms an event into a response.

Functions

func NewDecoder

func NewDecoder(res *http.Response) prompts.Decoder[Event]

NewDecoder creates a new Decoder based on the content type of the response.

Types

type Event

type Event struct {
	// Type is the type of the event.
	Type string `json:"type"`
	// Data is the data of the event.
	Data []byte `json:"data"`
}

Event is the structure of the event received from the server.

type Opt

type Opt func(*Opts)

Opt ...

func WithApiKey

func WithApiKey(apiKey string) Opt

WithApiKey configures the API key.

func WithBaseURL

func WithBaseURL(url string) Opt

WithBaseURL configures the base URL.

func WithClient

func WithClient(client *http.Client) Opt

WithClient configures the HTTP client.

func WithTimeout

func WithTimeout(timeout time.Duration) Opt

WithTimeout configures the timeout.

func WithURL

func WithURL(url string) Opt

WithURL configures the base URL.

type Opts

type Opts struct {
	// BaseURL is the base URL.
	BaseURL string `json:"base_url"`
	// ApiKey is the API key.
	ApiKey string `json:"api_key"`
	// Timeout is the timeout.
	Timeout time.Duration `json:"timeout"`
	// Client is the HTTP client.
	Client *http.Client `json:"-"`
}

Opts ...

func Defaults

func Defaults() *Opts

Defaults is the default options.

type Perplexity

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

Perplexity is a chat model.

func New

func New(opts ...Opt) *Perplexity

New returns a new Perplexity.

func (*Perplexity) SendCompletionRequest

SendCompletionRequest sends a completion request to the Perplexity API.

func (*Perplexity) SendStreamCompletionRequest

func (p *Perplexity) SendStreamCompletionRequest(ctx context.Context, req *prompts.ChatCompletionRequest, cb ...func(res *prompts.ChatCompletionResponse) error) error

SendStreamCompletionRequest sends a streamed completion request to the Perplexity API. nolint:gocyclo

Jump to

Keyboard shortcuts

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