@perplexity-ai/perplexity_ai 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +171 -14
  3. package/client.d.mts +4 -3
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +4 -3
  6. package/client.d.ts.map +1 -1
  7. package/package.json +1 -1
  8. package/resources/async/chat/chat.d.mts +2 -2
  9. package/resources/async/chat/chat.d.mts.map +1 -1
  10. package/resources/async/chat/chat.d.ts +2 -2
  11. package/resources/async/chat/chat.d.ts.map +1 -1
  12. package/resources/async/chat/completions.d.mts +161 -134
  13. package/resources/async/chat/completions.d.mts.map +1 -1
  14. package/resources/async/chat/completions.d.ts +161 -134
  15. package/resources/async/chat/completions.d.ts.map +1 -1
  16. package/resources/async/chat/completions.js +25 -7
  17. package/resources/async/chat/completions.js.map +1 -1
  18. package/resources/async/chat/completions.mjs +25 -7
  19. package/resources/async/chat/completions.mjs.map +1 -1
  20. package/resources/async/chat/index.d.mts +1 -1
  21. package/resources/async/chat/index.d.mts.map +1 -1
  22. package/resources/async/chat/index.d.ts +1 -1
  23. package/resources/async/chat/index.d.ts.map +1 -1
  24. package/resources/chat/completions.d.mts +116 -83
  25. package/resources/chat/completions.d.mts.map +1 -1
  26. package/resources/chat/completions.d.ts +116 -83
  27. package/resources/chat/completions.d.ts.map +1 -1
  28. package/resources/chat/completions.js +1 -2
  29. package/resources/chat/completions.js.map +1 -1
  30. package/resources/chat/completions.mjs +1 -2
  31. package/resources/chat/completions.mjs.map +1 -1
  32. package/resources/content.d.mts +1 -28
  33. package/resources/content.d.mts.map +1 -1
  34. package/resources/content.d.ts +1 -28
  35. package/resources/content.d.ts.map +1 -1
  36. package/resources/content.js +1 -1
  37. package/resources/content.mjs +1 -1
  38. package/resources/search.d.mts +1 -70
  39. package/resources/search.d.mts.map +1 -1
  40. package/resources/search.d.ts +1 -70
  41. package/resources/search.d.ts.map +1 -1
  42. package/resources/search.js +1 -1
  43. package/resources/search.mjs +1 -1
  44. package/resources/shared.d.mts +310 -25
  45. package/resources/shared.d.mts.map +1 -1
  46. package/resources/shared.d.ts +310 -25
  47. package/resources/shared.d.ts.map +1 -1
  48. package/src/client.ts +4 -3
  49. package/src/resources/async/chat/chat.ts +2 -2
  50. package/src/resources/async/chat/completions.ts +265 -142
  51. package/src/resources/async/chat/index.ts +1 -1
  52. package/src/resources/chat/completions.ts +183 -85
  53. package/src/resources/content.ts +1 -28
  54. package/src/resources/search.ts +1 -70
  55. package/src/resources/shared.ts +434 -25
  56. package/src/version.ts +1 -1
  57. package/version.d.mts +1 -1
  58. package/version.d.ts +1 -1
  59. package/version.js +1 -1
  60. package/version.mjs +1 -1
@@ -7,8 +7,7 @@ import { RequestOptions } from '../../internal/request-options';
7
7
 
8
8
  export class Completions extends APIResource {
9
9
  /**
10
- * Generates a model's response for the given chat conversation with integrated
11
- * search capabilities
10
+ * FastAPI wrapper around chat completions
12
11
  */
13
12
  create(body: CompletionCreateParams, options?: RequestOptions): APIPromise<CompletionCreateResponse> {
14
13
  return this._client.post('/chat/completions', { body, ...options });
@@ -16,141 +15,240 @@ export class Completions extends APIResource {
16
15
  }
17
16
 
18
17
  export interface CompletionCreateResponse {
19
- /**
20
- * Unique identifier for the chat completion
21
- */
22
18
  id: string;
23
19
 
24
- choices: Array<Shared.ChatChoice>;
20
+ choices: Array<Shared.Choice>;
25
21
 
26
- /**
27
- * Unix timestamp of creation
28
- */
29
22
  created: number;
30
23
 
31
- /**
32
- * The model used
33
- */
34
24
  model: string;
35
25
 
36
- object: string;
37
-
38
26
  usage: Shared.UsageInfo;
39
27
 
40
- /**
41
- * Search results used in generating the response
42
- */
43
- search_results?: Array<Shared.SearchResult> | null;
28
+ citations?: Array<string> | null;
29
+
30
+ object?: string;
31
+
32
+ search_results?: Array<Shared.APIPublicSearchResult> | null;
33
+
34
+ status?: 'PENDING' | 'COMPLETED' | null;
35
+
36
+ type?: 'message' | 'info' | 'end_of_stream' | null;
44
37
  }
45
38
 
46
39
  export interface CompletionCreateParams {
47
- /**
48
- * A list of messages comprising the conversation so far
49
- */
50
- messages: Array<Shared.ChatMessage>;
40
+ messages: Array<Shared.ChatMessageInput>;
51
41
 
52
- /**
53
- * The name of the model that will complete your prompt
54
- */
55
- model: 'sonar' | 'sonar-pro' | 'sonar-deep-research' | 'sonar-reasoning' | 'sonar-reasoning-pro';
42
+ model: string;
56
43
 
57
- /**
58
- * Disables web search completely - model uses only training data
59
- */
60
- disable_search?: boolean;
44
+ _debug_pro_search?: boolean;
61
45
 
62
- /**
63
- * Enables classifier that decides if web search is needed
64
- */
65
- enable_search_classifier?: boolean;
46
+ _inputs?: Array<number> | null;
47
+
48
+ _is_browser_agent?: boolean | null;
49
+
50
+ _prompt_token_length?: number | null;
51
+
52
+ best_of?: number | null;
53
+
54
+ country?: string | null;
55
+
56
+ cum_logprobs?: boolean | null;
57
+
58
+ debug_params?: CompletionCreateParams.DebugParams | null;
59
+
60
+ disable_search?: boolean | null;
61
+
62
+ diverse_first_token?: boolean | null;
63
+
64
+ enable_search_classifier?: boolean | null;
65
+
66
+ file_workspace_id?: string | null;
67
+
68
+ frequency_penalty?: number | null;
69
+
70
+ has_image_url?: boolean;
71
+
72
+ image_domain_filter?: Array<string> | null;
73
+
74
+ image_format_filter?: Array<string> | null;
66
75
 
67
- /**
68
- * Only include content last updated after this date (YYYY-MM-DD)
69
- */
70
76
  last_updated_after_filter?: string | null;
71
77
 
72
- /**
73
- * Only include content last updated before this date (YYYY-MM-DD)
74
- */
75
78
  last_updated_before_filter?: string | null;
76
79
 
77
- /**
78
- * Controls computational effort for sonar-deep-research model. Higher effort =
79
- * more thorough but more tokens
80
- */
81
- reasoning_effort?: 'low' | 'medium' | 'high' | null;
80
+ latitude?: number | null;
82
81
 
83
- /**
84
- * Whether to include images in search results
85
- */
86
- return_images?: boolean;
82
+ logprobs?: boolean | null;
87
83
 
88
- /**
89
- * Whether to return related questions
90
- */
91
- return_related_questions?: boolean;
84
+ longitude?: number | null;
85
+
86
+ max_tokens?: number | null;
87
+
88
+ n?: number | null;
89
+
90
+ num_images?: number;
91
+
92
+ num_search_results?: number;
93
+
94
+ parallel_tool_calls?: boolean | null;
95
+
96
+ presence_penalty?: number | null;
97
+
98
+ ranking_model?: string | null;
99
+
100
+ reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high' | null;
101
+
102
+ response_format?:
103
+ | CompletionCreateParams.ResponseFormatText
104
+ | CompletionCreateParams.ResponseFormatJsonSchema
105
+ | CompletionCreateParams.ResponseFormatRegex
106
+ | null;
107
+
108
+ response_metadata?: { [key: string]: unknown } | null;
109
+
110
+ return_images?: boolean | null;
111
+
112
+ return_related_questions?: boolean | null;
113
+
114
+ return_videos?: boolean | null;
115
+
116
+ safe_search?: boolean | null;
92
117
 
93
- /**
94
- * Only include content published after this date (YYYY-MM-DD)
95
- */
96
118
  search_after_date_filter?: string | null;
97
119
 
98
- /**
99
- * Only include content published before this date (YYYY-MM-DD)
100
- */
101
120
  search_before_date_filter?: string | null;
102
121
 
103
- /**
104
- * List of domains to limit search results to. Use '-' prefix to exclude domains
105
- */
106
122
  search_domain_filter?: Array<string> | null;
107
123
 
108
- /**
109
- * Type of search: 'web' for general, 'academic' for scholarly, 'sec' for SEC
110
- * filings
111
- */
124
+ search_internal_properties?: { [key: string]: unknown } | null;
125
+
112
126
  search_mode?: 'web' | 'academic' | 'sec' | null;
113
127
 
114
- /**
115
- * Filter results by how recently they were published
116
- */
117
128
  search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year' | null;
118
129
 
130
+ search_tenant?: string | null;
131
+
132
+ stop?: string | Array<string> | null;
133
+
134
+ stream?: boolean | null;
135
+
136
+ temperature?: number | null;
137
+
138
+ tool_choice?: 'none' | 'auto' | 'required' | null;
139
+
140
+ tools?: Array<CompletionCreateParams.Tool> | null;
141
+
142
+ top_k?: number | null;
143
+
144
+ top_logprobs?: number | null;
145
+
146
+ top_p?: number | null;
147
+
148
+ updated_after_timestamp?: number | null;
149
+
150
+ updated_before_timestamp?: number | null;
151
+
119
152
  web_search_options?: CompletionCreateParams.WebSearchOptions;
120
153
  }
121
154
 
122
155
  export namespace CompletionCreateParams {
156
+ export interface DebugParams {
157
+ summarizer_model_override?: string | null;
158
+
159
+ summarizer_prompt_override?: string | null;
160
+ }
161
+
162
+ export interface ResponseFormatText {
163
+ type: 'text';
164
+ }
165
+
166
+ export interface ResponseFormatJsonSchema {
167
+ json_schema: ResponseFormatJsonSchema.JsonSchema;
168
+
169
+ type: 'json_schema';
170
+ }
171
+
172
+ export namespace ResponseFormatJsonSchema {
173
+ export interface JsonSchema {
174
+ schema: { [key: string]: unknown };
175
+
176
+ description?: string | null;
177
+
178
+ name?: string | null;
179
+
180
+ strict?: boolean | null;
181
+ }
182
+ }
183
+
184
+ export interface ResponseFormatRegex {
185
+ regex: ResponseFormatRegex.Regex;
186
+
187
+ type: 'regex';
188
+ }
189
+
190
+ export namespace ResponseFormatRegex {
191
+ export interface Regex {
192
+ regex: string;
193
+
194
+ description?: string | null;
195
+
196
+ name?: string | null;
197
+
198
+ strict?: boolean | null;
199
+ }
200
+ }
201
+
202
+ export interface Tool {
203
+ function: Tool.Function;
204
+
205
+ type: 'function';
206
+ }
207
+
208
+ export namespace Tool {
209
+ export interface Function {
210
+ description: string;
211
+
212
+ name: string;
213
+
214
+ parameters: Function.Parameters;
215
+
216
+ strict?: boolean | null;
217
+ }
218
+
219
+ export namespace Function {
220
+ export interface Parameters {
221
+ properties: { [key: string]: unknown };
222
+
223
+ type: string;
224
+
225
+ additional_properties?: boolean | null;
226
+
227
+ required?: Array<string> | null;
228
+ }
229
+ }
230
+ }
231
+
123
232
  export interface WebSearchOptions {
124
- /**
125
- * Improves relevance of image search results
126
- */
127
- image_search_relevance_enhanced?: boolean;
128
-
129
- /**
130
- * Amount of search context retrieved: low (cost-saving), medium (balanced), high
131
- * (comprehensive)
132
- */
233
+ image_results_enhanced_relevance?: boolean;
234
+
133
235
  search_context_size?: 'low' | 'medium' | 'high';
134
236
 
135
- user_location?: WebSearchOptions.UserLocation;
237
+ search_type?: 'fast' | 'pro' | 'auto';
238
+
239
+ user_location?: WebSearchOptions.UserLocation | null;
136
240
  }
137
241
 
138
242
  export namespace WebSearchOptions {
139
243
  export interface UserLocation {
140
244
  city?: string | null;
141
245
 
142
- /**
143
- * Two-letter ISO country code
144
- */
145
246
  country?: string | null;
146
247
 
147
248
  latitude?: number | null;
148
249
 
149
250
  longitude?: number | null;
150
251
 
151
- /**
152
- * State/province name
153
- */
154
252
  region?: string | null;
155
253
  }
156
254
  }
@@ -6,59 +6,32 @@ import { RequestOptions } from '../internal/request-options';
6
6
 
7
7
  export class Content extends APIResource {
8
8
  /**
9
- * Retrieve the full content from specified URLs
9
+ * Get Urls Content
10
10
  */
11
11
  create(body: ContentCreateParams, options?: RequestOptions): APIPromise<ContentCreateResponse> {
12
12
  return this._client.post('/content', { body, ...options });
13
13
  }
14
14
  }
15
15
 
16
- /**
17
- * Response containing the retrieved content from URLs
18
- */
19
16
  export interface ContentCreateResponse {
20
- /**
21
- * Unique identifier for this content retrieval request
22
- */
23
17
  id: string;
24
18
 
25
- /**
26
- * Array of content objects retrieved from the requested URLs
27
- */
28
19
  results: Array<ContentCreateResponse.Result>;
29
20
  }
30
21
 
31
22
  export namespace ContentCreateResponse {
32
- /**
33
- * Content retrieved from a specific URL
34
- */
35
23
  export interface Result {
36
- /**
37
- * The full text content of the web page or document
38
- */
39
24
  content: string;
40
25
 
41
- /**
42
- * The title of the web page or document
43
- */
44
26
  title: string;
45
27
 
46
- /**
47
- * The URL of the web page or document
48
- */
49
28
  url: string;
50
29
 
51
- /**
52
- * The publication date of the content (if available)
53
- */
54
30
  date?: string | null;
55
31
  }
56
32
  }
57
33
 
58
34
  export interface ContentCreateParams {
59
- /**
60
- * List of URLs to retrieve content from
61
- */
62
35
  urls: Array<string>;
63
36
  }
64
37
 
@@ -6,127 +6,58 @@ import { RequestOptions } from '../internal/request-options';
6
6
 
7
7
  export class Search extends APIResource {
8
8
  /**
9
- * Perform a search query with various filtering and customization options
9
+ * Search
10
10
  */
11
11
  create(body: SearchCreateParams, options?: RequestOptions): APIPromise<SearchCreateResponse> {
12
12
  return this._client.post('/search', { body, ...options });
13
13
  }
14
14
  }
15
15
 
16
- /**
17
- * Response containing search results
18
- */
19
16
  export interface SearchCreateResponse {
20
- /**
21
- * Unique identifier for this search request
22
- */
23
17
  id: string;
24
18
 
25
- /**
26
- * Array of search result pages matching the query
27
- */
28
19
  results: Array<SearchCreateResponse.Result>;
29
20
  }
30
21
 
31
22
  export namespace SearchCreateResponse {
32
- /**
33
- * A single search result page
34
- */
35
23
  export interface Result {
36
- /**
37
- * A brief excerpt or summary of the page content
38
- */
39
24
  snippet: string;
40
25
 
41
- /**
42
- * The title of the search result page
43
- */
44
26
  title: string;
45
27
 
46
- /**
47
- * The URL of the search result page
48
- */
49
28
  url: string;
50
29
 
51
- /**
52
- * The publication date of the content (if available)
53
- */
54
30
  date?: string | null;
55
31
 
56
- /**
57
- * When the content was last updated (if available)
58
- */
59
32
  last_updated?: string | null;
60
33
  }
61
34
  }
62
35
 
63
36
  export interface SearchCreateParams {
64
- /**
65
- * Search query string or array of query strings to search for
66
- */
67
37
  query: string | Array<string>;
68
38
 
69
- /**
70
- * Country code to bias search results towards (e.g., 'US', 'GB', 'CA')
71
- */
72
39
  country?: string | null;
73
40
 
74
- /**
75
- * Only include results last updated after this date (ISO 8601 format: YYYY-MM-DD)
76
- */
77
41
  last_updated_after_filter?: string | null;
78
42
 
79
- /**
80
- * Only include results last updated before this date (ISO 8601 format: YYYY-MM-DD)
81
- */
82
43
  last_updated_before_filter?: string | null;
83
44
 
84
- /**
85
- * Maximum number of search results to return
86
- */
87
45
  max_results?: number;
88
46
 
89
- /**
90
- * Maximum number of tokens to return across all results
91
- */
92
47
  max_tokens?: number;
93
48
 
94
- /**
95
- * Maximum number of tokens to return per individual search result
96
- */
97
49
  max_tokens_per_page?: number;
98
50
 
99
- /**
100
- * Enable safe search filtering to exclude adult content
101
- */
102
51
  safe_search?: boolean | null;
103
52
 
104
- /**
105
- * Only include results published after this date (ISO 8601 format: YYYY-MM-DD)
106
- */
107
53
  search_after_date_filter?: string | null;
108
54
 
109
- /**
110
- * Only include results published before this date (ISO 8601 format: YYYY-MM-DD)
111
- */
112
55
  search_before_date_filter?: string | null;
113
56
 
114
- /**
115
- * List of domains to restrict search results to (e.g., ['example.com',
116
- * 'another.com'])
117
- */
118
57
  search_domain_filter?: Array<string> | null;
119
58
 
120
- /**
121
- * Type of search to perform: 'web' for general web search, 'academic' for
122
- * scholarly articles, 'sec' for SEC filings
123
- */
124
59
  search_mode?: 'web' | 'academic' | 'sec' | null;
125
60
 
126
- /**
127
- * Filter results by how recently they were published (hour, day, week, month, or
128
- * year)
129
- */
130
61
  search_recency_filter?: 'hour' | 'day' | 'week' | 'month' | 'year' | null;
131
62
  }
132
63