feat(tools): added perplexity search endpoint, updated models list for perplexity block (#1812)

This commit is contained in:
Waleed
2025-11-05 11:15:15 -08:00
committed by GitHub
parent 68056b72c2
commit 0260dbc3f2
6 changed files with 370 additions and 16 deletions
+27 -2
View File
@@ -1,6 +1,6 @@
---
title: Perplexity
description: Use Perplexity AI chat models
description: Use Perplexity AI for chat and search
---
import { BlockInfoCard } from "@/components/ui/block-info-card"
@@ -37,7 +37,7 @@ In Sim, the Perplexity integration enables your agents to leverage these powerfu
## Usage Instructions
Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models.
Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models or perform web searches with advanced filtering.
@@ -65,6 +65,31 @@ Generate completions using Perplexity AI chat models
| `success` | boolean | Operation success status |
| `output` | object | Chat completion results |
### `perplexity_search`
Get ranked search results from Perplexity
#### Input
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `query` | string | Yes | A search query or array of queries \(max 5 for multi-query search\) |
| `max_results` | number | No | Maximum number of search results to return \(1-20, default: 10\) |
| `search_domain_filter` | array | No | List of domains/URLs to limit search results to \(max 20\) |
| `max_tokens_per_page` | number | No | Maximum number of tokens retrieved from each webpage \(default: 1024\) |
| `country` | string | No | Country code to filter search results \(e.g., US, GB, DE\) |
| `search_recency_filter` | string | No | Filter results by recency: hour, day, week, month, or year |
| `search_after_date` | string | No | Include only content published after this date \(format: MM/DD/YYYY\) |
| `search_before_date` | string | No | Include only content published before this date \(format: MM/DD/YYYY\) |
| `apiKey` | string | Yes | Perplexity API key |
#### Output
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `success` | boolean | Operation success status |
| `output` | object | Search results |
## Notes
+156 -13
View File
@@ -1,25 +1,40 @@
import { PerplexityIcon } from '@/components/icons'
import { AuthMode, type BlockConfig } from '@/blocks/types'
import type { PerplexityChatResponse } from '@/tools/perplexity/types'
import type { PerplexityChatResponse, PerplexitySearchResponse } from '@/tools/perplexity/types'
export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
type PerplexityResponse = PerplexityChatResponse | PerplexitySearchResponse
export const PerplexityBlock: BlockConfig<PerplexityResponse> = {
type: 'perplexity',
name: 'Perplexity',
description: 'Use Perplexity AI chat models',
description: 'Use Perplexity AI for chat and search',
longDescription:
'Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models.',
'Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models or perform web searches with advanced filtering.',
authMode: AuthMode.ApiKey,
docsLink: 'https://docs.sim.ai/tools/perplexity',
category: 'tools',
bgColor: '#20808D', // Perplexity turquoise color
icon: PerplexityIcon,
subBlocks: [
{
id: 'operation',
title: 'Operation',
type: 'dropdown',
layout: 'full',
options: [
{ label: 'Chat', id: 'perplexity_chat' },
{ label: 'Search', id: 'perplexity_search' },
],
value: () => 'perplexity_chat',
},
// Chat operation inputs
{
id: 'systemPrompt',
title: 'System Prompt',
type: 'long-input',
layout: 'full',
placeholder: 'System prompt to guide the model behavior...',
condition: { field: 'operation', value: 'perplexity_chat' },
},
{
id: 'content',
@@ -28,6 +43,7 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
layout: 'full',
placeholder: 'Enter your prompt here...',
required: true,
condition: { field: 'operation', value: 'perplexity_chat' },
},
{
id: 'model',
@@ -36,13 +52,13 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
layout: 'half',
options: [
{ label: 'Sonar', id: 'sonar' },
{ label: 'Mistral', id: 'mistral' },
{ label: 'Claude-3-Opus', id: 'claude-3-opus' },
{ label: 'Claude-3-Sonnet', id: 'claude-3-sonnet' },
{ label: 'Command-R', id: 'command-r' },
{ label: 'GPT-4o', id: 'gpt-4o' },
{ label: 'Sonar Pro', id: 'sonar-pro' },
{ label: 'Sonar Deep Research', id: 'sonar-deep-research' },
{ label: 'Sonar Reasoning', id: 'sonar-reasoning' },
{ label: 'Sonar Reasoning Pro', id: 'sonar-reasoning-pro' },
],
value: () => 'sonar',
condition: { field: 'operation', value: 'perplexity_chat' },
},
{
id: 'temperature',
@@ -52,6 +68,7 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
min: 0,
max: 1,
value: () => '0.7',
condition: { field: 'operation', value: 'perplexity_chat' },
},
{
id: 'max_tokens',
@@ -59,6 +76,80 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
type: 'short-input',
layout: 'half',
placeholder: 'Maximum number of tokens',
condition: { field: 'operation', value: 'perplexity_chat' },
},
// Search operation inputs
{
id: 'query',
title: 'Search Query',
type: 'long-input',
layout: 'full',
placeholder: 'Enter your search query...',
required: true,
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'max_results',
title: 'Max Results',
type: 'short-input',
layout: 'half',
placeholder: '10',
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'search_domain_filter',
title: 'Domain Filter',
type: 'long-input',
layout: 'full',
placeholder: 'science.org, pnas.org, cell.com (comma-separated, max 20)',
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'max_tokens_per_page',
title: 'Max Page Tokens',
type: 'short-input',
layout: 'half',
placeholder: '1024',
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'country',
title: 'Country',
type: 'short-input',
layout: 'half',
placeholder: 'US, GB, DE, etc.',
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'search_recency_filter',
title: 'Recency Filter',
type: 'dropdown',
layout: 'half',
placeholder: 'Select option...',
options: [
{ label: 'Past Hour', id: 'hour' },
{ label: 'Past Day', id: 'day' },
{ label: 'Past Week', id: 'week' },
{ label: 'Past Month', id: 'month' },
{ label: 'Past Year', id: 'year' },
],
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'search_after_date',
title: 'After Date',
type: 'short-input',
layout: 'half',
placeholder: 'MM/DD/YYYY',
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'search_before_date',
title: 'Before Date',
type: 'short-input',
layout: 'half',
placeholder: 'MM/DD/YYYY',
condition: { field: 'operation', value: 'perplexity_search' },
},
{
id: 'apiKey',
@@ -71,11 +162,48 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
},
],
tools: {
access: ['perplexity_chat'],
access: ['perplexity_chat', 'perplexity_search'],
config: {
tool: () => 'perplexity_chat',
tool: (params) => {
switch (params.operation) {
case 'perplexity_chat':
return 'perplexity_chat'
case 'perplexity_search':
return 'perplexity_search'
default:
return 'perplexity_chat'
}
},
params: (params) => {
const toolParams = {
if (params.operation === 'perplexity_search') {
// Process domain filter from comma-separated string to array
let domainFilter: string[] | undefined
if (params.search_domain_filter && typeof params.search_domain_filter === 'string') {
domainFilter = params.search_domain_filter
.split(',')
.map((d) => d.trim())
.filter((d) => d.length > 0)
}
const searchParams = {
apiKey: params.apiKey,
query: params.query,
max_results: params.max_results ? Number.parseInt(params.max_results) : undefined,
search_domain_filter: domainFilter,
max_tokens_per_page: params.max_tokens_per_page
? Number.parseInt(params.max_tokens_per_page)
: undefined,
country: params.country || undefined,
search_recency_filter: params.search_recency_filter || undefined,
search_after_date: params.search_after_date || undefined,
search_before_date: params.search_before_date || undefined,
}
return searchParams
}
// Chat params (default)
const chatParams = {
apiKey: params.apiKey,
model: params.model,
content: params.content,
@@ -84,21 +212,36 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
temperature: params.temperature ? Number.parseFloat(params.temperature) : undefined,
}
return toolParams
return chatParams
},
},
},
inputs: {
operation: { type: 'string', description: 'Operation to perform' },
// Chat operation inputs
content: { type: 'string', description: 'User prompt content' },
systemPrompt: { type: 'string', description: 'System instructions' },
model: { type: 'string', description: 'AI model to use' },
max_tokens: { type: 'string', description: 'Maximum output tokens' },
temperature: { type: 'string', description: 'Response randomness' },
// Search operation inputs
query: { type: 'string', description: 'Search query' },
max_results: { type: 'string', description: 'Maximum search results' },
search_domain_filter: { type: 'string', description: 'Domain filter (comma-separated)' },
max_tokens_per_page: { type: 'string', description: 'Max tokens per page' },
country: { type: 'string', description: 'Country code filter' },
search_recency_filter: { type: 'string', description: 'Recency filter' },
search_after_date: { type: 'string', description: 'After date filter' },
search_before_date: { type: 'string', description: 'Before date filter' },
// Common
apiKey: { type: 'string', description: 'Perplexity API key' },
},
outputs: {
// Chat outputs
content: { type: 'string', description: 'Generated response' },
model: { type: 'string', description: 'Model used' },
usage: { type: 'json', description: 'Token usage' },
// Search outputs
results: { type: 'json', description: 'Search results array' },
},
}
+2
View File
@@ -1,3 +1,5 @@
import { chatTool } from '@/tools/perplexity/chat'
import { searchTool } from '@/tools/perplexity/search'
export const perplexityChatTool = chatTool
export const perplexitySearchTool = searchTool
+157
View File
@@ -0,0 +1,157 @@
import type { PerplexitySearchParams, PerplexitySearchResponse } from '@/tools/perplexity/types'
import type { ToolConfig } from '@/tools/types'
export const searchTool: ToolConfig<PerplexitySearchParams, PerplexitySearchResponse> = {
id: 'perplexity_search',
name: 'Perplexity Search',
description:
"Get ranked search results from Perplexity's continuously refreshed index with advanced filtering and customization options",
version: '1.0',
params: {
query: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'A search query or array of queries (max 5 for multi-query search)',
},
max_results: {
type: 'number',
required: false,
visibility: 'user-only',
description: 'Maximum number of search results to return (1-20, default: 10)',
},
search_domain_filter: {
type: 'array',
required: false,
visibility: 'user-only',
description: 'List of domains/URLs to limit search results to (max 20)',
},
max_tokens_per_page: {
type: 'number',
required: false,
visibility: 'user-only',
description: 'Maximum number of tokens retrieved from each webpage (default: 1024)',
},
country: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Country code to filter search results (e.g., US, GB, DE)',
},
search_recency_filter: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Filter results by recency: hour, day, week, month, or year',
},
search_after_date: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Include only content published after this date (format: MM/DD/YYYY)',
},
search_before_date: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Include only content published before this date (format: MM/DD/YYYY)',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Perplexity API key',
},
},
request: {
method: 'POST',
url: () => 'https://api.perplexity.ai/search',
headers: (params) => ({
Authorization: `Bearer ${params.apiKey}`,
'Content-Type': 'application/json',
}),
body: (params) => {
const body: Record<string, any> = {
query: params.query,
}
if (params.max_results !== undefined) {
body.max_results = Number(params.max_results)
}
if (params.search_domain_filter && params.search_domain_filter.length > 0) {
body.search_domain_filter = params.search_domain_filter
}
if (params.max_tokens_per_page !== undefined) {
body.max_tokens_per_page = Number(params.max_tokens_per_page)
}
if (params.country) {
body.country = params.country
}
if (params.search_recency_filter) {
body.search_recency_filter = params.search_recency_filter
}
if (params.search_after_date) {
body.search_after_date = params.search_after_date
}
if (params.search_before_date) {
body.search_before_date = params.search_before_date
}
return body
},
},
transformResponse: async (response) => {
const data = await response.json()
return {
success: true,
output: {
results: data.results.map((result: any) => ({
title: result.title,
url: result.url,
snippet: result.snippet,
date: result.date,
last_updated: result.last_updated,
})),
},
}
},
outputs: {
success: { type: 'boolean', description: 'Operation success status' },
output: {
type: 'object',
description: 'Search results',
properties: {
results: {
type: 'array',
description: 'Array of search results',
items: {
type: 'object',
properties: {
title: { type: 'string', description: 'Title of the search result' },
url: { type: 'string', description: 'URL of the search result' },
snippet: { type: 'string', description: 'Brief excerpt or summary of the content' },
date: {
type: 'string',
description: "Date the page was crawled and added to Perplexity's index",
},
last_updated: {
type: 'string',
description: "Date the page was last updated in Perplexity's index",
},
},
},
},
},
},
},
}
+26
View File
@@ -25,3 +25,29 @@ export interface PerplexityChatResponse extends ToolResponse {
}
}
}
export interface PerplexitySearchParams {
query: string | string[]
max_results?: number
search_domain_filter?: string[]
max_tokens_per_page?: number
country?: string
search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year'
search_after_date?: string
search_before_date?: string
apiKey: string
}
export interface PerplexitySearchResult {
title: string
url: string
snippet: string
date: string
last_updated: string
}
export interface PerplexitySearchResponse extends ToolResponse {
output: {
results: PerplexitySearchResult[]
}
}
+2 -1
View File
@@ -134,7 +134,7 @@ import {
outlookSendTool,
} from '@/tools/outlook'
import { parallelSearchTool } from '@/tools/parallel'
import { perplexityChatTool } from '@/tools/perplexity'
import { perplexityChatTool, perplexitySearchTool } from '@/tools/perplexity'
import {
pineconeFetchTool,
pineconeGenerateEmbeddingsTool,
@@ -348,6 +348,7 @@ export const tools: Record<string, ToolConfig> = {
google_sheets_update: googleSheetsUpdateTool,
google_sheets_append: googleSheetsAppendTool,
perplexity_chat: perplexityChatTool,
perplexity_search: perplexitySearchTool,
confluence_retrieve: confluenceRetrieveTool,
confluence_update: confluenceUpdateTool,
twilio_send_sms: sendSMSTool,