Skip to content

Commit 0260dbc

Browse files
authored
feat(tools): added perplexity search endpoint, updated models list for perplexity block (#1812)
1 parent 68056b7 commit 0260dbc

File tree

6 files changed

+370
-16
lines changed

6 files changed

+370
-16
lines changed

apps/docs/content/docs/en/tools/perplexity.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Perplexity
3-
description: Use Perplexity AI chat models
3+
description: Use Perplexity AI for chat and search
44
---
55

66
import { BlockInfoCard } from "@/components/ui/block-info-card"
@@ -37,7 +37,7 @@ In Sim, the Perplexity integration enables your agents to leverage these powerfu
3737

3838
## Usage Instructions
3939

40-
Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models.
40+
Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models or perform web searches with advanced filtering.
4141

4242

4343

@@ -65,6 +65,31 @@ Generate completions using Perplexity AI chat models
6565
| `success` | boolean | Operation success status |
6666
| `output` | object | Chat completion results |
6767

68+
### `perplexity_search`
69+
70+
Get ranked search results from Perplexity
71+
72+
#### Input
73+
74+
| Parameter | Type | Required | Description |
75+
| --------- | ---- | -------- | ----------- |
76+
| `query` | string | Yes | A search query or array of queries \(max 5 for multi-query search\) |
77+
| `max_results` | number | No | Maximum number of search results to return \(1-20, default: 10\) |
78+
| `search_domain_filter` | array | No | List of domains/URLs to limit search results to \(max 20\) |
79+
| `max_tokens_per_page` | number | No | Maximum number of tokens retrieved from each webpage \(default: 1024\) |
80+
| `country` | string | No | Country code to filter search results \(e.g., US, GB, DE\) |
81+
| `search_recency_filter` | string | No | Filter results by recency: hour, day, week, month, or year |
82+
| `search_after_date` | string | No | Include only content published after this date \(format: MM/DD/YYYY\) |
83+
| `search_before_date` | string | No | Include only content published before this date \(format: MM/DD/YYYY\) |
84+
| `apiKey` | string | Yes | Perplexity API key |
85+
86+
#### Output
87+
88+
| Parameter | Type | Description |
89+
| --------- | ---- | ----------- |
90+
| `success` | boolean | Operation success status |
91+
| `output` | object | Search results |
92+
6893

6994

7095
## Notes
Lines changed: 156 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
import { PerplexityIcon } from '@/components/icons'
22
import { AuthMode, type BlockConfig } from '@/blocks/types'
3-
import type { PerplexityChatResponse } from '@/tools/perplexity/types'
3+
import type { PerplexityChatResponse, PerplexitySearchResponse } from '@/tools/perplexity/types'
44

5-
export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
5+
type PerplexityResponse = PerplexityChatResponse | PerplexitySearchResponse
6+
7+
export const PerplexityBlock: BlockConfig<PerplexityResponse> = {
68
type: 'perplexity',
79
name: 'Perplexity',
8-
description: 'Use Perplexity AI chat models',
10+
description: 'Use Perplexity AI for chat and search',
911
longDescription:
10-
'Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models.',
12+
'Integrate Perplexity into the workflow. Can generate completions using Perplexity AI chat models or perform web searches with advanced filtering.',
1113
authMode: AuthMode.ApiKey,
1214
docsLink: 'https://docs.sim.ai/tools/perplexity',
1315
category: 'tools',
1416
bgColor: '#20808D', // Perplexity turquoise color
1517
icon: PerplexityIcon,
1618
subBlocks: [
19+
{
20+
id: 'operation',
21+
title: 'Operation',
22+
type: 'dropdown',
23+
layout: 'full',
24+
options: [
25+
{ label: 'Chat', id: 'perplexity_chat' },
26+
{ label: 'Search', id: 'perplexity_search' },
27+
],
28+
value: () => 'perplexity_chat',
29+
},
30+
// Chat operation inputs
1731
{
1832
id: 'systemPrompt',
1933
title: 'System Prompt',
2034
type: 'long-input',
2135
layout: 'full',
2236
placeholder: 'System prompt to guide the model behavior...',
37+
condition: { field: 'operation', value: 'perplexity_chat' },
2338
},
2439
{
2540
id: 'content',
@@ -28,6 +43,7 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
2843
layout: 'full',
2944
placeholder: 'Enter your prompt here...',
3045
required: true,
46+
condition: { field: 'operation', value: 'perplexity_chat' },
3147
},
3248
{
3349
id: 'model',
@@ -36,13 +52,13 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
3652
layout: 'half',
3753
options: [
3854
{ label: 'Sonar', id: 'sonar' },
39-
{ label: 'Mistral', id: 'mistral' },
40-
{ label: 'Claude-3-Opus', id: 'claude-3-opus' },
41-
{ label: 'Claude-3-Sonnet', id: 'claude-3-sonnet' },
42-
{ label: 'Command-R', id: 'command-r' },
43-
{ label: 'GPT-4o', id: 'gpt-4o' },
55+
{ label: 'Sonar Pro', id: 'sonar-pro' },
56+
{ label: 'Sonar Deep Research', id: 'sonar-deep-research' },
57+
{ label: 'Sonar Reasoning', id: 'sonar-reasoning' },
58+
{ label: 'Sonar Reasoning Pro', id: 'sonar-reasoning-pro' },
4459
],
4560
value: () => 'sonar',
61+
condition: { field: 'operation', value: 'perplexity_chat' },
4662
},
4763
{
4864
id: 'temperature',
@@ -52,13 +68,88 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
5268
min: 0,
5369
max: 1,
5470
value: () => '0.7',
71+
condition: { field: 'operation', value: 'perplexity_chat' },
5572
},
5673
{
5774
id: 'max_tokens',
5875
title: 'Max Tokens',
5976
type: 'short-input',
6077
layout: 'half',
6178
placeholder: 'Maximum number of tokens',
79+
condition: { field: 'operation', value: 'perplexity_chat' },
80+
},
81+
// Search operation inputs
82+
{
83+
id: 'query',
84+
title: 'Search Query',
85+
type: 'long-input',
86+
layout: 'full',
87+
placeholder: 'Enter your search query...',
88+
required: true,
89+
condition: { field: 'operation', value: 'perplexity_search' },
90+
},
91+
{
92+
id: 'max_results',
93+
title: 'Max Results',
94+
type: 'short-input',
95+
layout: 'half',
96+
placeholder: '10',
97+
condition: { field: 'operation', value: 'perplexity_search' },
98+
},
99+
{
100+
id: 'search_domain_filter',
101+
title: 'Domain Filter',
102+
type: 'long-input',
103+
layout: 'full',
104+
placeholder: 'science.org, pnas.org, cell.com (comma-separated, max 20)',
105+
condition: { field: 'operation', value: 'perplexity_search' },
106+
},
107+
{
108+
id: 'max_tokens_per_page',
109+
title: 'Max Page Tokens',
110+
type: 'short-input',
111+
layout: 'half',
112+
placeholder: '1024',
113+
condition: { field: 'operation', value: 'perplexity_search' },
114+
},
115+
{
116+
id: 'country',
117+
title: 'Country',
118+
type: 'short-input',
119+
layout: 'half',
120+
placeholder: 'US, GB, DE, etc.',
121+
condition: { field: 'operation', value: 'perplexity_search' },
122+
},
123+
{
124+
id: 'search_recency_filter',
125+
title: 'Recency Filter',
126+
type: 'dropdown',
127+
layout: 'half',
128+
placeholder: 'Select option...',
129+
options: [
130+
{ label: 'Past Hour', id: 'hour' },
131+
{ label: 'Past Day', id: 'day' },
132+
{ label: 'Past Week', id: 'week' },
133+
{ label: 'Past Month', id: 'month' },
134+
{ label: 'Past Year', id: 'year' },
135+
],
136+
condition: { field: 'operation', value: 'perplexity_search' },
137+
},
138+
{
139+
id: 'search_after_date',
140+
title: 'After Date',
141+
type: 'short-input',
142+
layout: 'half',
143+
placeholder: 'MM/DD/YYYY',
144+
condition: { field: 'operation', value: 'perplexity_search' },
145+
},
146+
{
147+
id: 'search_before_date',
148+
title: 'Before Date',
149+
type: 'short-input',
150+
layout: 'half',
151+
placeholder: 'MM/DD/YYYY',
152+
condition: { field: 'operation', value: 'perplexity_search' },
62153
},
63154
{
64155
id: 'apiKey',
@@ -71,11 +162,48 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
71162
},
72163
],
73164
tools: {
74-
access: ['perplexity_chat'],
165+
access: ['perplexity_chat', 'perplexity_search'],
75166
config: {
76-
tool: () => 'perplexity_chat',
167+
tool: (params) => {
168+
switch (params.operation) {
169+
case 'perplexity_chat':
170+
return 'perplexity_chat'
171+
case 'perplexity_search':
172+
return 'perplexity_search'
173+
default:
174+
return 'perplexity_chat'
175+
}
176+
},
77177
params: (params) => {
78-
const toolParams = {
178+
if (params.operation === 'perplexity_search') {
179+
// Process domain filter from comma-separated string to array
180+
let domainFilter: string[] | undefined
181+
if (params.search_domain_filter && typeof params.search_domain_filter === 'string') {
182+
domainFilter = params.search_domain_filter
183+
.split(',')
184+
.map((d) => d.trim())
185+
.filter((d) => d.length > 0)
186+
}
187+
188+
const searchParams = {
189+
apiKey: params.apiKey,
190+
query: params.query,
191+
max_results: params.max_results ? Number.parseInt(params.max_results) : undefined,
192+
search_domain_filter: domainFilter,
193+
max_tokens_per_page: params.max_tokens_per_page
194+
? Number.parseInt(params.max_tokens_per_page)
195+
: undefined,
196+
country: params.country || undefined,
197+
search_recency_filter: params.search_recency_filter || undefined,
198+
search_after_date: params.search_after_date || undefined,
199+
search_before_date: params.search_before_date || undefined,
200+
}
201+
202+
return searchParams
203+
}
204+
205+
// Chat params (default)
206+
const chatParams = {
79207
apiKey: params.apiKey,
80208
model: params.model,
81209
content: params.content,
@@ -84,21 +212,36 @@ export const PerplexityBlock: BlockConfig<PerplexityChatResponse> = {
84212
temperature: params.temperature ? Number.parseFloat(params.temperature) : undefined,
85213
}
86214

87-
return toolParams
215+
return chatParams
88216
},
89217
},
90218
},
91219
inputs: {
220+
operation: { type: 'string', description: 'Operation to perform' },
221+
// Chat operation inputs
92222
content: { type: 'string', description: 'User prompt content' },
93223
systemPrompt: { type: 'string', description: 'System instructions' },
94224
model: { type: 'string', description: 'AI model to use' },
95225
max_tokens: { type: 'string', description: 'Maximum output tokens' },
96226
temperature: { type: 'string', description: 'Response randomness' },
227+
// Search operation inputs
228+
query: { type: 'string', description: 'Search query' },
229+
max_results: { type: 'string', description: 'Maximum search results' },
230+
search_domain_filter: { type: 'string', description: 'Domain filter (comma-separated)' },
231+
max_tokens_per_page: { type: 'string', description: 'Max tokens per page' },
232+
country: { type: 'string', description: 'Country code filter' },
233+
search_recency_filter: { type: 'string', description: 'Recency filter' },
234+
search_after_date: { type: 'string', description: 'After date filter' },
235+
search_before_date: { type: 'string', description: 'Before date filter' },
236+
// Common
97237
apiKey: { type: 'string', description: 'Perplexity API key' },
98238
},
99239
outputs: {
240+
// Chat outputs
100241
content: { type: 'string', description: 'Generated response' },
101242
model: { type: 'string', description: 'Model used' },
102243
usage: { type: 'json', description: 'Token usage' },
244+
// Search outputs
245+
results: { type: 'json', description: 'Search results array' },
103246
},
104247
}

apps/sim/tools/perplexity/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import { chatTool } from '@/tools/perplexity/chat'
2+
import { searchTool } from '@/tools/perplexity/search'
23

34
export const perplexityChatTool = chatTool
5+
export const perplexitySearchTool = searchTool

0 commit comments

Comments
 (0)