perplexity

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 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 added in v1.4.0

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 added in v1.2.38

BatchCancel is not supported by Perplexity provider.

func (*PerplexityProvider) BatchCreate added in v1.2.38

BatchCreate is not supported by Perplexity provider.

func (*PerplexityProvider) BatchDelete added in v1.4.8

BatchDelete is not supported by Perplexity provider.

func (*PerplexityProvider) BatchList added in v1.2.38

BatchList is not supported by Perplexity provider.

func (*PerplexityProvider) BatchResults added in v1.2.38

BatchResults is not supported by Perplexity provider.

func (*PerplexityProvider) BatchRetrieve added in v1.2.38

BatchRetrieve is not supported by Perplexity provider.

func (*PerplexityProvider) CachedContentCreate added in v1.5.8

CachedContentCreate is unsupported on PerplexityProvider. Only Gemini and Vertex AI implement the cached-content lifecycle (Google AI Studio + Vertex AI named caches). Other providers either lack named cache management entirely or handle caching implicitly via per-message cache_control markers.

func (*PerplexityProvider) CachedContentDelete added in v1.5.8

CachedContentDelete is unsupported on PerplexityProvider (see CachedContentCreate).

func (*PerplexityProvider) CachedContentList added in v1.5.8

CachedContentList is unsupported on PerplexityProvider (see CachedContentCreate).

func (*PerplexityProvider) CachedContentRetrieve added in v1.5.8

CachedContentRetrieve is unsupported on PerplexityProvider (see CachedContentCreate).

func (*PerplexityProvider) CachedContentUpdate added in v1.5.8

CachedContentUpdate is unsupported on PerplexityProvider (see CachedContentCreate).

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) Compaction added in v1.5.17

Compaction is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerCreate added in v1.3.12

ContainerCreate is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerDelete added in v1.3.12

ContainerDelete is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileContent added in v1.3.12

ContainerFileContent is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileCreate added in v1.3.12

ContainerFileCreate is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileDelete added in v1.3.12

ContainerFileDelete is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileList added in v1.3.12

ContainerFileList is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerFileRetrieve added in v1.3.12

ContainerFileRetrieve is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerList added in v1.3.12

ContainerList is not supported by the Perplexity provider.

func (*PerplexityProvider) ContainerRetrieve added in v1.3.12

ContainerRetrieve is not supported by the Perplexity provider.

func (*PerplexityProvider) CountTokens added in v1.2.43

CountTokens is not supported by the Perplexity provider.

func (*PerplexityProvider) Embedding

Embedding is not supported by the Perplexity provider.

func (*PerplexityProvider) FileContent added in v1.2.38

FileContent is not supported by Perplexity provider.

func (*PerplexityProvider) FileDelete added in v1.2.38

FileDelete is not supported by Perplexity provider.

func (*PerplexityProvider) FileList added in v1.2.38

FileList is not supported by Perplexity provider.

func (*PerplexityProvider) FileRetrieve added in v1.2.38

FileRetrieve is not supported by Perplexity provider.

func (*PerplexityProvider) FileUpload added in v1.2.38

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 added in v1.4.0

ImageEdit is not supported by the Perplexity provider.

func (*PerplexityProvider) ImageEditStream added in v1.4.0

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 added in v1.3.9

ImageGeneration is not supported by the Perplexity provider.

func (*PerplexityProvider) ImageGenerationStream added in v1.3.9

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 added in v1.4.0

ImageVariation is not supported by the Perplexity provider.

func (*PerplexityProvider) ListModels

ListModels performs a list models request to Perplexity's API. Perplexity's /v1/models endpoint is OpenAI-compatible, so the OpenAI handler is reused.

func (*PerplexityProvider) OCR added in v1.4.18

OCR is not supported by the Perplexity provider.

func (*PerplexityProvider) Passthrough added in v1.4.8

Passthrough is not supported by the Perplexity provider.

func (*PerplexityProvider) PassthroughStream added in v1.4.8

func (*PerplexityProvider) Rerank added in v1.4.4

Rerank is not supported by the Perplexity provider.

func (*PerplexityProvider) Responses

Responses performs a responses request to the Perplexity API. Models available on Perplexity's /v1/responses endpoint are routed there via the OpenAI-compatible handler; sonar-* models not supported on responses fall back to /chat/completions.

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. Models available on Perplexity's /v1/responses endpoint are streamed from there via the OpenAI-compatible handler; sonar-* models not supported on responses fall back to /chat/completions.

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 added in v1.4.4

VideoDelete is not supported by Perplexity provider.

func (*PerplexityProvider) VideoDownload added in v1.4.4

VideoDownload is not supported by the Perplexity provider.

func (*PerplexityProvider) VideoGeneration added in v1.4.4

VideoGeneration is not supported by the Perplexity provider.

func (*PerplexityProvider) VideoList added in v1.4.4

VideoList is not supported by Perplexity provider.

func (*PerplexityProvider) VideoRemix added in v1.4.4

VideoRemix is not supported by Perplexity provider.

func (*PerplexityProvider) VideoRetrieve added in v1.4.4

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