Skip to content

feat(community): perplexity add web search options #8328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions libs/langchain-community/src/chat_models/perplexity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ export interface PerplexityChatInput extends BaseChatModelParams {

/** Timeout for requests to Perplexity */
timeout?: number;

/** Controls the search mode used for the request. When set to 'academic', results will prioritize scholarly sources. */
searchMode?: "academic" | "web";

/** Controls how much computational effort the AI dedicates to each query for deep research models. Only applicable for sonar-deep-research. */
reasoningEffort?: "low" | "medium" | "high";

/** Filters search results to only include content published after this date. */
searchAfterDateFilter?: string;

/** Filters search results to only include content published before this date. */
searchBeforeDateFilter?: string;

/** Configuration for using web search in model responses. */
webSearchOptions?: Record<string, unknown>;
}

export interface PerplexityChatCallOptions extends BaseChatModelCallOptions {
Expand Down Expand Up @@ -147,6 +162,16 @@ export class ChatPerplexity

frequencyPenalty?: number;

searchMode?: "academic" | "web";

reasoningEffort?: "low" | "medium" | "high";

searchAfterDateFilter?: string;

searchBeforeDateFilter?: string;

webSearchOptions?: Record<string, unknown>;

private client: OpenAI;

constructor(fields: PerplexityChatInput) {
Expand All @@ -170,6 +195,11 @@ export class ChatPerplexity
fields?.searchDomainFilter ?? this.searchDomainFilter;
this.searchRecencyFilter =
fields?.searchRecencyFilter ?? this.searchRecencyFilter;
this.searchMode = fields?.searchMode;
this.reasoningEffort = fields?.reasoningEffort;
this.searchAfterDateFilter = fields?.searchAfterDateFilter;
this.searchBeforeDateFilter = fields?.searchBeforeDateFilter;
this.webSearchOptions = fields?.webSearchOptions;

if (!this.apiKey) {
throw new Error("Perplexity API key not found");
Expand Down Expand Up @@ -203,6 +233,11 @@ export class ChatPerplexity
response_format: options?.response_format,
search_domain_filter: this.searchDomainFilter,
search_recency_filter: this.searchRecencyFilter,
search_mode: this.searchMode,
reasoning_effort: this.reasoningEffort,
search_after_date_filter: this.searchAfterDateFilter,
search_before_date_filter: this.searchBeforeDateFilter,
web_search_options: this.webSearchOptions,
};
}

Expand Down