perplexity

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package providers implements various LLM providers and their utility functions. This file contains the Perplexity provider implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MediaResponse

type MediaResponse struct {
	Overrides MediaResponseOverrides `json:"overrides,omitempty"` // Optional: Overrides for the media response
}

type MediaResponseOverrides

type MediaResponseOverrides struct {
	ReturnVideos *bool `json:"return_videos,omitempty"` // Optional: Return videos
	ReturnImages *bool `json:"return_images,omitempty"` // Optional: Return images
}

type PerplexityChatRequest

type PerplexityChatRequest struct {
	Model                   string                  `json:"model"`                                // Required: Model to use for chat completion
	Messages                []schemas.ChatMessage   `json:"messages"`                             // Required: Array of message objects
	SearchMode              *string                 `json:"search_mode"`                          // Required: Search mode
	ReasoningEffort         *string                 `json:"reasoning_effort"`                     // Required: Reasoning effort (low, medium, high)
	MaxTokens               *int                    `json:"max_tokens,omitempty"`                 // Optional: Maximum tokens to generate
	Temperature             *float64                `json:"temperature,omitempty"`                // Optional: Sampling temperature
	TopP                    *float64                `json:"top_p,omitempty"`                      // Optional: Top-p sampling
	LanguagePreference      *string                 `json:"language_preference,omitempty"`        // Optional: Language preference
	SearchDomainFilter      []string                `json:"search_domain_filter,omitempty"`       // Optional: Search domain filter
	ReturnImages            *bool                   `json:"return_images,omitempty"`              // Optional: Return images
	ReturnRelatedQuestions  *bool                   `json:"return_related_questions,omitempty"`   // Optional: Return related questions
	SearchRecencyFilter     *string                 `json:"search_recency_filter,omitempty"`      // Optional: Search recency filter
	SearchAfterDateFilter   *string                 `json:"search_after_date_filter,omitempty"`   // Optional: Search after date filter
	SearchBeforeDateFilter  *string                 `json:"search_before_date_filter,omitempty"`  // Optional: Search before date filter
	LastUpdatedAfterFilter  *string                 `json:"last_updated_after_filter,omitempty"`  // Optional: Last updated after filter
	LastUpdatedBeforeFilter *string                 `json:"last_updated_before_filter,omitempty"` // Optional: Last updated before filter
	TopK                    *int                    `json:"top_k,omitempty"`                      // Optional: Top-k sampling
	Stream                  *bool                   `json:"stream,omitempty"`                     // Optional: Enable streaming
	PresencePenalty         *float64                `json:"presence_penalty,omitempty"`           // Optional: Presence penalty
	FrequencyPenalty        *float64                `json:"frequency_penalty,omitempty"`          // Optional: Frequency penalty
	ResponseFormat          *interface{}            `json:"response_format,omitempty"`            // Format for the response
	DisableSearch           *bool                   `json:"disable_search,omitempty"`             // Optional: Disable search
	EnableSearchClassifier  *bool                   `json:"enable_search_classifier,omitempty"`   // Optional: Enable search classifier
	WebSearchOptions        []WebSearchOption       `json:"web_search_options,omitempty"`         // Optional: Web search options
	MediaResponse           *MediaResponse          `json:"media_response,omitempty"`             // Optional: Media response
	Tools                   []schemas.ChatTool      `json:"tools,omitempty"`                      // Optional: Tools available for the model
	ToolChoice              *schemas.ChatToolChoice `json:"tool_choice,omitempty"`                // Optional: Whether to call a tool
	ParallelToolCalls       *bool                   `json:"parallel_tool_calls,omitempty"`        // Optional: Enable parallel tool calls
	Stop                    []string                `json:"stop,omitempty"`                       // Optional: Stop sequences
	LogProbs                *bool                   `json:"logprobs,omitempty"`                   // Optional: Return log probabilities
	TopLogProbs             *int                    `json:"top_logprobs,omitempty"`               // Optional: Number of top log probabilities
	NumSearchResults        *int                    `json:"num_search_results,omitempty"`         // Optional: Number of search results
	NumImages               *int                    `json:"num_images,omitempty"`                 // Optional: Number of images
	SearchLanguageFilter    []string                `json:"search_language_filter,omitempty"`     // Optional: Search language filter
	ImageFormatFilter       []string                `json:"image_format_filter,omitempty"`        // Optional: Image format filter
	ImageDomainFilter       []string                `json:"image_domain_filter,omitempty"`        // Optional: Image domain filter
	SafeSearch              *bool                   `json:"safe_search,omitempty"`                // Optional: Enable safe search
	StreamMode              *string                 `json:"stream_mode,omitempty"`                // Optional: Stream mode
	ExtraParams             map[string]interface{}  `json:"-"`
}

PerplexityChatRequest represents a Perplexity chat completion request

func ToPerplexityChatCompletionRequest

func ToPerplexityChatCompletionRequest(bifrostReq *schemas.BifrostChatRequest) *PerplexityChatRequest

ToPerplexityChatCompletionRequest converts a Bifrost request to Perplexity chat completion request

func ToPerplexityResponsesRequest

func ToPerplexityResponsesRequest(bifrostReq *schemas.BifrostResponsesRequest) *PerplexityChatRequest

ToPerplexityResponsesRequest converts a BifrostResponsesRequest to PerplexityChatRequest

func (*PerplexityChatRequest) GetExtraParams

func (r *PerplexityChatRequest) GetExtraParams() map[string]interface{}

GetExtraParams implements the RequestBodyWithExtraParams interface

type PerplexityChatResponse

type PerplexityChatResponse struct {
	ID            string                          `json:"id"`
	Choices       []schemas.BifrostResponseChoice `json:"choices"`
	Created       int                             `json:"created"` // The Unix timestamp (in seconds).
	Model         string                          `json:"model"`
	Object        string                          `json:"object"` // "chat.completion" or "chat.completion.chunk"
	Citations     []string                        `json:"citations,omitempty"`
	SearchResults []schemas.SearchResult          `json:"search_results,omitempty"`
	Videos        []schemas.VideoResult           `json:"videos,omitempty"`
	Usage         *Usage                          `json:"usage,omitempty"`
}

func (*PerplexityChatResponse) ToBifrostChatResponse

func (response *PerplexityChatResponse) ToBifrostChatResponse(model string) *schemas.BifrostChatResponse

ToBifrostChatResponse converts a Perplexity chat completion response to Bifrost format

type PerplexityProvider

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

PerplexityProvider implements the Provider interface for Perplexity's API.

func NewPerplexityProvider

func NewPerplexityProvider(config *schemas.ProviderConfig, logger schemas.Logger) (*PerplexityProvider, error)

NewPerplexityProvider creates a new Perplexity provider instance. It initializes the HTTP client with the provided configuration and sets up response pools. The client is configured with timeouts, concurrency limits, and optional proxy settings.

func (*PerplexityProvider) BatchCancel

BatchCancel is not supported by Perplexity provider.

func (*PerplexityProvider) BatchCreate

BatchCreate is not supported by Perplexity provider.

func (*PerplexityProvider) BatchDelete

BatchDelete is not supported by Perplexity provider.

func (*PerplexityProvider) BatchList

BatchList is not supported by Perplexity provider.

func (*PerplexityProvider) BatchResults

BatchResults is not supported by Perplexity provider.

func (*PerplexityProvider) BatchRetrieve

BatchRetrieve is not supported by Perplexity provider.

func (*PerplexityProvider) ChatCompletion

ChatCompletion performs a chat completion request to the Perplexity API.

func (*PerplexityProvider) ChatCompletionStream

func (provider *PerplexityProvider) ChatCompletionStream(ctx *schemas.BifrostContext, postHookRunner schemas.PostHookRunner, postHookSpanFinalizer func(context.Context), key schemas.Key, request *schemas.BifrostChatRequest) (chan *schemas.BifrostStreamChunk, *schemas.BifrostError)

ChatCompletionStream performs a streaming chat completion request to the Perplexity API. It supports real-time streaming of responses using Server-Sent Events (SSE). Uses Perplexity's OpenAI-compatible streaming format. Returns a channel containing BifrostStreamChunk objects representing the stream or an error if the request fails.

func (*PerplexityProvider) ContainerCreate

ContainerCreate is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerDelete

ContainerDelete is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileContent

ContainerFileContent is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileCreate

ContainerFileCreate is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileDelete

ContainerFileDelete is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileList

ContainerFileList is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileRetrieve

ContainerFileRetrieve is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerList

ContainerList is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerRetrieve

ContainerRetrieve is not supported by the Perplexity provider.

func (*PerplexityProvider) CountTokens

CountTokens is not supported by the Perplexity provider.

func (*PerplexityProvider) Embedding

Embedding is not supported by the Perplexity provider.

func (*PerplexityProvider) FileContent

FileContent is not supported by Perplexity provider.

func (*PerplexityProvider) FileDelete

FileDelete is not supported by Perplexity provider.

func (*PerplexityProvider) FileList

FileList is not supported by Perplexity provider.

func (*PerplexityProvider) FileRetrieve

FileRetrieve is not supported by Perplexity provider.

func (*PerplexityProvider) FileUpload

FileUpload is not supported by Perplexity provider.

func (*PerplexityProvider) GetProviderKey

func (provider *PerplexityProvider) GetProviderKey() schemas.ModelProvider

GetProviderKey returns the provider identifier for Perplexity.

func (*PerplexityProvider) ImageEdit

ImageEdit is not supported by the Perplexity provider.

func (*PerplexityProvider) ImageEditStream

func (provider *PerplexityProvider) ImageEditStream(ctx *schemas.BifrostContext, postHookRunner schemas.PostHookRunner, postHookSpanFinalizer func(context.Context), key schemas.Key, request *schemas.BifrostImageEditRequest) (chan *schemas.BifrostStreamChunk, *schemas.BifrostError)

ImageEditStream is not supported by the Perplexity provider.

func (*PerplexityProvider) ImageGeneration

ImageGeneration is not supported by the Perplexity provider.

func (*PerplexityProvider) ImageGenerationStream

func (provider *PerplexityProvider) ImageGenerationStream(ctx *schemas.BifrostContext, postHookRunner schemas.PostHookRunner, postHookSpanFinalizer func(context.Context), key schemas.Key, request *schemas.BifrostImageGenerationRequest) (chan *schemas.BifrostStreamChunk, *schemas.BifrostError)

ImageGenerationStream is not supported by the Perplexity provider.

func (*PerplexityProvider) ImageVariation

ImageVariation is not supported by the Perplexity provider.

func (*PerplexityProvider) ListModels

ListModels performs a list models request to Perplexity's API.

func (*PerplexityProvider) OCR added in v1.4.20

OCR is not supported by the Perplexity provider.

func (*PerplexityProvider) Passthrough

Passthrough is not supported by the Perplexity provider.

func (*PerplexityProvider) Rerank

Rerank is not supported by the Perplexity provider.

func (*PerplexityProvider) Responses

Responses performs a responses request to the Perplexity API.

func (*PerplexityProvider) ResponsesStream

func (provider *PerplexityProvider) ResponsesStream(ctx *schemas.BifrostContext, postHookRunner schemas.PostHookRunner, postHookSpanFinalizer func(context.Context), key schemas.Key, request *schemas.BifrostResponsesRequest) (chan *schemas.BifrostStreamChunk, *schemas.BifrostError)

ResponsesStream performs a streaming responses request to the Perplexity API.

func (*PerplexityProvider) Speech

Speech is not supported by the Perplexity provider.

func (*PerplexityProvider) SpeechStream

func (provider *PerplexityProvider) SpeechStream(ctx *schemas.BifrostContext, postHookRunner schemas.PostHookRunner, postHookSpanFinalizer func(context.Context), key schemas.Key, request *schemas.BifrostSpeechRequest) (chan *schemas.BifrostStreamChunk, *schemas.BifrostError)

SpeechStream is not supported by the Perplexity provider.

func (*PerplexityProvider) TextCompletion

TextCompletion is not supported by the Perplexity provider.

func (*PerplexityProvider) TextCompletionStream

func (provider *PerplexityProvider) TextCompletionStream(ctx *schemas.BifrostContext, postHookRunner schemas.PostHookRunner, postHookSpanFinalizer func(context.Context), key schemas.Key, request *schemas.BifrostTextCompletionRequest) (chan *schemas.BifrostStreamChunk, *schemas.BifrostError)

TextCompletionStream performs a streaming text completion request to Perplexity's API. It formats the request, sends it to Perplexity, and processes the response. Returns a channel of BifrostStreamChunk objects or an error if the request fails.

func (*PerplexityProvider) Transcription

Transcription is not supported by the Perplexity provider.

func (*PerplexityProvider) TranscriptionStream

func (provider *PerplexityProvider) TranscriptionStream(ctx *schemas.BifrostContext, postHookRunner schemas.PostHookRunner, postHookSpanFinalizer func(context.Context), key schemas.Key, request *schemas.BifrostTranscriptionRequest) (chan *schemas.BifrostStreamChunk, *schemas.BifrostError)

TranscriptionStream is not supported by the Perplexity provider.

func (*PerplexityProvider) VideoDelete

VideoDelete is not supported by Perplexity provider.

func (*PerplexityProvider) VideoDownload

VideoDownload is not supported by the Perplexity provider.

func (*PerplexityProvider) VideoGeneration

VideoGeneration is not supported by the Perplexity provider.

func (*PerplexityProvider) VideoList

VideoList is not supported by Perplexity provider.

func (*PerplexityProvider) VideoRemix

VideoRemix is not supported by Perplexity provider.

func (*PerplexityProvider) VideoRetrieve

VideoRetrieve is not supported by the Perplexity provider.

type Usage

type Usage struct {
	PromptTokens      int                  `json:"prompt_tokens"`
	CompletionTokens  int                  `json:"completion_tokens"`
	TotalTokens       int                  `json:"total_tokens"`
	SearchContextSize *string              `json:"search_context_size,omitempty"`
	CitationTokens    *int                 `json:"citation_tokens,omitempty"`
	NumSearchQueries  *int                 `json:"num_search_queries,omitempty"`
	ReasoningTokens   *int                 `json:"reasoning_tokens,omitempty"`
	Cost              *schemas.BifrostCost `json:"cost,omitempty"`
}

type WebSearchOption

type WebSearchOption struct {
	SearchContextSize             *string                      `json:"search_context_size,omitempty"`              // "low" | "medium" | "high"
	UserLocation                  *WebSearchOptionUserLocation `json:"user_location,omitempty"`                    // The approximate location of the user
	ImageResultsEnhancedRelevance *bool                        `json:"image_results_enhanced_relevance,omitempty"` // Optional: Image results enhanced relevance
	SearchType                    *string                      `json:"search_type,omitempty"`                      // Optional: "general" | "news" | "academic" | "social" | "writing"
}

type WebSearchOptionUserLocation

type WebSearchOptionUserLocation struct {
	Latitude  *float64 `json:"latitude,omitempty"`
	Longitude *float64 `json:"longitude,omitempty"`
	City      *string  `json:"city,omitempty"`    // Free text input for the city
	Country   *string  `json:"country,omitempty"` // Two-letter ISO country code
	Region    *string  `json:"region,omitempty"`  // Free text input for the region
}

Jump to

Keyboard shortcuts

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