11import { PerplexityIcon } from '@/components/icons'
22import { 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}
0 commit comments