@ai-sdk/perplexity 5.0.15 → 5.0.17
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.
- package/CHANGELOG.md +19 -0
- package/dist/index.d.ts +86 -115
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +62 -51
- package/dist/index.js.map +1 -1
- package/docs/70-perplexity.mdx +50 -5
- package/package.json +4 -3
- package/src/perplexity-agent-api.ts +184 -161
- package/src/perplexity-decision-model.ts +48 -32
- package/src/perplexity-embedding-model-options.ts +25 -16
- package/src/perplexity-embedding-model.ts +18 -12
- package/src/perplexity-language-model-options.ts +120 -105
- package/src/perplexity-language-model.ts +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/perplexity
|
|
2
2
|
|
|
3
|
+
## 5.0.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4b4c125: Defer construction of provider validation schemas until first use to reduce package import time.
|
|
8
|
+
- Updated dependencies [b089ce8]
|
|
9
|
+
- Updated dependencies [39a776b]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.65
|
|
11
|
+
|
|
12
|
+
## 5.0.16
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 0c2a9de: Add `maxOutputTokens` and `reasoning` to experimental decision calls and forward them to language-model-backed decisions. Language-model adapters keep reasoning disabled when omitted. Native decision providers warn when either setting is unsupported.
|
|
17
|
+
- Updated dependencies [0c2a9de]
|
|
18
|
+
- Updated dependencies [200c47f]
|
|
19
|
+
- @ai-sdk/provider@4.0.31
|
|
20
|
+
- @ai-sdk/provider-utils@5.0.64
|
|
21
|
+
|
|
3
22
|
## 5.0.15
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EmbeddingModelV4, Experimental_DecisionModelV4, LanguageModelV4, ProviderV4 } from "@ai-sdk/provider";
|
|
2
|
-
import { FetchFunction } from "@ai-sdk/provider-utils";
|
|
3
|
-
import { z } from "zod/v4";
|
|
2
|
+
import { FetchFunction, InferSchema } from "@ai-sdk/provider-utils";
|
|
4
3
|
//#region src/perplexity-decision-model-options.d.ts
|
|
5
4
|
type PerplexityDecisionModelId = 'pplx-decider-v1.2' | 'pplx-decider-flash-v1.2' | 'pplx-decider-latest' | 'pplx-decider-flash-latest' | 'perplexity/pplx-decider-latest' | 'perplexity/pplx-decider-flash-latest' | 'pplx-decider-v1.1-27b' | 'pplx-decider-v1-27b' | (string & {});
|
|
6
5
|
/** Perplexity decision models do not support provider-specific options. */
|
|
@@ -8,14 +7,11 @@ type PerplexityDecisionModelOptions = Record<string, never>;
|
|
|
8
7
|
//#endregion
|
|
9
8
|
//#region src/perplexity-embedding-model-options.d.ts
|
|
10
9
|
type PerplexityEmbeddingModelId = 'pplx-embed-v1-0.6b' | 'pplx-embed-v1-4b' | (string & {});
|
|
11
|
-
declare const perplexityEmbeddingModelOptions:
|
|
12
|
-
dimensions
|
|
13
|
-
encodingFormat
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}>>;
|
|
17
|
-
}, z.core.$strip>;
|
|
18
|
-
type PerplexityEmbeddingModelOptions = z.infer<typeof perplexityEmbeddingModelOptions>;
|
|
10
|
+
declare const perplexityEmbeddingModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
11
|
+
dimensions?: number | undefined;
|
|
12
|
+
encodingFormat?: "base64_int8" | "base64_binary" | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
type PerplexityEmbeddingModelOptions = InferSchema<typeof perplexityEmbeddingModelOptions>;
|
|
19
15
|
//#endregion
|
|
20
16
|
//#region src/perplexity-options.d.ts
|
|
21
17
|
type PerplexityAgentPreset = 'fast' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
@@ -69,111 +65,86 @@ export declare function createPerplexity(options?: PerplexityProviderSettings):
|
|
|
69
65
|
export declare const perplexity: PerplexityProvider;
|
|
70
66
|
//#endregion
|
|
71
67
|
//#region src/perplexity-language-model-options.d.ts
|
|
72
|
-
declare const perplexityLanguageModelOptions:
|
|
73
|
-
|
|
74
|
-
instructions
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
type:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
type:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
low: "low";
|
|
153
|
-
medium: "medium";
|
|
154
|
-
high: "high";
|
|
155
|
-
minimal: "minimal";
|
|
156
|
-
xhigh: "xhigh";
|
|
157
|
-
}>>;
|
|
158
|
-
}, z.core.$loose>>;
|
|
159
|
-
/** Agent API skill configuration. */
|
|
160
|
-
skills: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
161
|
-
type: z.ZodLiteral<"builtin">;
|
|
162
|
-
name: z.ZodEnum<{
|
|
163
|
-
office: "office";
|
|
164
|
-
"office/docx": "office/docx";
|
|
165
|
-
"office/pdf": "office/pdf";
|
|
166
|
-
"office/pptx": "office/pptx";
|
|
167
|
-
"office/xlsx": "office/xlsx";
|
|
168
|
-
}>;
|
|
169
|
-
}, z.core.$loose>, z.ZodObject<{
|
|
170
|
-
type: z.ZodLiteral<"inline">;
|
|
171
|
-
name: z.ZodString;
|
|
172
|
-
description: z.ZodString;
|
|
173
|
-
instructions: z.ZodString;
|
|
174
|
-
}, z.core.$loose>]>>>;
|
|
175
|
-
}, z.core.$loose>;
|
|
176
|
-
type PerplexityLanguageModelOptions = z.infer<typeof perplexityLanguageModelOptions>;
|
|
68
|
+
declare const perplexityLanguageModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
69
|
+
[x: string]: unknown;
|
|
70
|
+
instructions?: string | undefined;
|
|
71
|
+
tools?: ({
|
|
72
|
+
[x: string]: unknown;
|
|
73
|
+
type: "web_search";
|
|
74
|
+
filters?: {
|
|
75
|
+
[x: string]: unknown;
|
|
76
|
+
search_domain_filter?: string[] | undefined;
|
|
77
|
+
search_recency_filter?: "hour" | "day" | "week" | "month" | "year" | undefined;
|
|
78
|
+
search_after_date_filter?: string | undefined;
|
|
79
|
+
search_before_date_filter?: string | undefined;
|
|
80
|
+
last_updated_after_filter?: string | undefined;
|
|
81
|
+
last_updated_before_filter?: string | undefined;
|
|
82
|
+
} | undefined;
|
|
83
|
+
max_results?: number | undefined;
|
|
84
|
+
max_tokens?: number | undefined;
|
|
85
|
+
max_tokens_per_page?: number | undefined;
|
|
86
|
+
search_context_size?: "low" | "medium" | "high" | undefined;
|
|
87
|
+
user_location?: {
|
|
88
|
+
[x: string]: unknown;
|
|
89
|
+
latitude?: number | undefined;
|
|
90
|
+
longitude?: number | undefined;
|
|
91
|
+
country?: string | undefined;
|
|
92
|
+
city?: string | undefined;
|
|
93
|
+
region?: string | undefined;
|
|
94
|
+
} | undefined;
|
|
95
|
+
} | {
|
|
96
|
+
[x: string]: unknown;
|
|
97
|
+
type: "fetch_url";
|
|
98
|
+
max_urls?: number | undefined;
|
|
99
|
+
} | {
|
|
100
|
+
[x: string]: unknown;
|
|
101
|
+
type: "people_search";
|
|
102
|
+
} | {
|
|
103
|
+
[x: string]: unknown;
|
|
104
|
+
type: "finance_search";
|
|
105
|
+
} | {
|
|
106
|
+
[x: string]: unknown;
|
|
107
|
+
type: "sandbox";
|
|
108
|
+
} | {
|
|
109
|
+
[x: string]: unknown;
|
|
110
|
+
type: "mcp";
|
|
111
|
+
server_label: string;
|
|
112
|
+
server_url: string;
|
|
113
|
+
allowed_tools?: string[] | undefined;
|
|
114
|
+
authorization?: string | undefined;
|
|
115
|
+
defer_loading?: boolean | undefined;
|
|
116
|
+
headers?: Record<string, string> | undefined;
|
|
117
|
+
} | {
|
|
118
|
+
[x: string]: unknown;
|
|
119
|
+
type: "connector";
|
|
120
|
+
id: string;
|
|
121
|
+
server_label: string;
|
|
122
|
+
server_description?: string | undefined;
|
|
123
|
+
allowed_tools?: string[] | undefined;
|
|
124
|
+
})[] | undefined;
|
|
125
|
+
models?: string[] | undefined;
|
|
126
|
+
max_steps?: number | undefined;
|
|
127
|
+
max_tool_calls?: number | undefined;
|
|
128
|
+
previous_response_id?: string | undefined;
|
|
129
|
+
store?: boolean | undefined;
|
|
130
|
+
language_preference?: string | undefined;
|
|
131
|
+
reasoning?: {
|
|
132
|
+
[x: string]: unknown;
|
|
133
|
+
effort?: "low" | "medium" | "high" | "minimal" | "xhigh" | undefined;
|
|
134
|
+
} | undefined;
|
|
135
|
+
skills?: ({
|
|
136
|
+
[x: string]: unknown;
|
|
137
|
+
type: "builtin";
|
|
138
|
+
name: "office" | "office/docx" | "office/pdf" | "office/pptx" | "office/xlsx";
|
|
139
|
+
} | {
|
|
140
|
+
[x: string]: unknown;
|
|
141
|
+
type: "inline";
|
|
142
|
+
name: string;
|
|
143
|
+
description: string;
|
|
144
|
+
instructions: string;
|
|
145
|
+
})[] | undefined;
|
|
146
|
+
}>;
|
|
147
|
+
type PerplexityLanguageModelOptions = InferSchema<typeof perplexityLanguageModelOptions>;
|
|
177
148
|
//#endregion
|
|
178
149
|
//#region src/version.d.ts
|
|
179
150
|
export declare const VERSION: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["DecisionModelV4"],"sources":["../src/perplexity-decision-model-options.ts","../src/perplexity-embedding-model-options.ts","../src/perplexity-options.ts","../src/perplexity-provider.ts","../src/perplexity-language-model-options.ts","../src/version.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["DecisionModelV4"],"sources":["../src/perplexity-decision-model-options.ts","../src/perplexity-embedding-model-options.ts","../src/perplexity-options.ts","../src/perplexity-provider.ts","../src/perplexity-language-model-options.ts","../src/version.ts"],"mappings":";;;KAAY;;KAYA,iCAAiC;;;KCJjC;cAKC,kEAA+B;;;;KAqBhC,kCAAkC,mBACrC;;;KCnCG;KAOA,4BACR;;;UCca,2BAA2B;;EAE1C,cAAc,SAAS,4BAA4BA;;;;GAKlD,SAAS,4BAA4B;;;;EAKtC,cAAc,SAAS,4BAA4B;;;;EAKnD,UAAU,SAAS,6BAA6B;;;;EAKhD,eAAe,SAAS,6BAA6B;;;;EAKrD,mBAAmB,SAAS,6BAA6B;;UAG1C;;;;EAIf;;;;EAKA;;;;EAKA,UAAU;;;;;EAMV,QAAQ;;wBAGM,iBACd,UAAS,6BACR;qBA2DU,YAAU;;;cCrEV,iEAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqED,iCAAiC,mBACpC;;;qBCvII"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { APICallError, Experimental_DecisionUnsupportedQuestionTypeError, InvalidArgumentError, InvalidResponseDataError, NoSuchModelError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
2
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, detectMediaType, generateId, getTopLevelMediaType, isCustomReasoning, isFullMediaType, loadApiKey, mapReasoningToProviderEffort, parseProviderOptions, postJsonToApi, resolve, resolveFullMediaType, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, detectMediaType, generateId, getTopLevelMediaType, isCustomReasoning, isFullMediaType, lazySchema, loadApiKey, mapReasoningToProviderEffort, parseProviderOptions, postJsonToApi, resolve, resolveFullMediaType, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
//#region src/perplexity-embedding-model-options.ts
|
|
5
|
-
const perplexityEmbeddingModelOptions = z.object({
|
|
5
|
+
const perplexityEmbeddingModelOptions = lazySchema(() => zodSchema(z.object({
|
|
6
6
|
/**
|
|
7
7
|
* The number of dimensions the resulting output embeddings should have
|
|
8
8
|
* (Matryoshka truncation). Ranges from 128 up to the model's full size
|
|
@@ -16,7 +16,7 @@ const perplexityEmbeddingModelOptions = z.object({
|
|
|
16
16
|
* - `base64_binary`: packed bits per byte (0-255), compare via Hamming distance.
|
|
17
17
|
*/
|
|
18
18
|
encodingFormat: z.enum(["base64_int8", "base64_binary"]).optional()
|
|
19
|
-
});
|
|
19
|
+
})));
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/convert-perplexity-usage.ts
|
|
22
22
|
function convertPerplexityUsage(usage) {
|
|
@@ -177,7 +177,7 @@ function mapPerplexityFinishReason({ status, incompleteReason, hasFunctionCall }
|
|
|
177
177
|
}
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region src/perplexity-agent-api.ts
|
|
180
|
-
const perplexitySearchResultSchema = z.looseObject({
|
|
180
|
+
const perplexitySearchResultSchema = () => z.looseObject({
|
|
181
181
|
id: z.number().optional(),
|
|
182
182
|
title: z.string(),
|
|
183
183
|
url: z.string(),
|
|
@@ -186,12 +186,12 @@ const perplexitySearchResultSchema = z.looseObject({
|
|
|
186
186
|
last_updated: z.string().nullish(),
|
|
187
187
|
source: z.string().optional()
|
|
188
188
|
});
|
|
189
|
-
const perplexityFetchedContentSchema = z.looseObject({
|
|
189
|
+
const perplexityFetchedContentSchema = () => z.looseObject({
|
|
190
190
|
title: z.string(),
|
|
191
191
|
url: z.string(),
|
|
192
192
|
snippet: z.string().optional()
|
|
193
193
|
});
|
|
194
|
-
const perplexityContentPartSchema = z.looseObject({
|
|
194
|
+
const perplexityContentPartSchema = () => z.looseObject({
|
|
195
195
|
type: z.string(),
|
|
196
196
|
text: z.string().optional(),
|
|
197
197
|
annotations: z.array(z.looseObject({
|
|
@@ -206,19 +206,19 @@ const handledOutputTypes = [
|
|
|
206
206
|
"fetch_url_results",
|
|
207
207
|
"function_call"
|
|
208
208
|
];
|
|
209
|
-
const perplexityOutputItemSchema = z.union([
|
|
209
|
+
const perplexityOutputItemSchema = () => z.union([
|
|
210
210
|
z.looseObject({
|
|
211
211
|
type: z.literal("message"),
|
|
212
212
|
id: z.string().nullish(),
|
|
213
|
-
content: z.array(perplexityContentPartSchema).nullish()
|
|
213
|
+
content: z.array(perplexityContentPartSchema()).nullish()
|
|
214
214
|
}),
|
|
215
215
|
z.looseObject({
|
|
216
216
|
type: z.literal("search_results"),
|
|
217
|
-
results: z.array(perplexitySearchResultSchema).nullish()
|
|
217
|
+
results: z.array(perplexitySearchResultSchema()).nullish()
|
|
218
218
|
}),
|
|
219
219
|
z.looseObject({
|
|
220
220
|
type: z.literal("fetch_url_results"),
|
|
221
|
-
contents: z.array(perplexityFetchedContentSchema).nullish()
|
|
221
|
+
contents: z.array(perplexityFetchedContentSchema()).nullish()
|
|
222
222
|
}),
|
|
223
223
|
z.looseObject({
|
|
224
224
|
type: z.literal("function_call"),
|
|
@@ -230,7 +230,7 @@ const perplexityOutputItemSchema = z.union([
|
|
|
230
230
|
}),
|
|
231
231
|
z.object({ type: z.string().refine((type) => !handledOutputTypes.includes(type)) }).transform(() => ({ type: "unhandled" }))
|
|
232
232
|
]);
|
|
233
|
-
const perplexityCostSchema = z.looseObject({
|
|
233
|
+
const perplexityCostSchema = () => z.looseObject({
|
|
234
234
|
currency: z.string().optional(),
|
|
235
235
|
input_cost: z.number().optional(),
|
|
236
236
|
output_cost: z.number().optional(),
|
|
@@ -239,7 +239,7 @@ const perplexityCostSchema = z.looseObject({
|
|
|
239
239
|
cache_read_cost: z.number().nullish(),
|
|
240
240
|
tool_calls_cost: z.number().nullish()
|
|
241
241
|
});
|
|
242
|
-
const perplexityUsageSchema = z.looseObject({
|
|
242
|
+
const perplexityUsageSchema = () => z.looseObject({
|
|
243
243
|
input_tokens: z.number(),
|
|
244
244
|
output_tokens: z.number(),
|
|
245
245
|
total_tokens: z.number(),
|
|
@@ -250,14 +250,14 @@ const perplexityUsageSchema = z.looseObject({
|
|
|
250
250
|
}).nullish(),
|
|
251
251
|
output_tokens_details: z.looseObject({ reasoning_tokens: z.number().optional() }).nullish(),
|
|
252
252
|
tool_calls_details: z.record(z.string(), z.looseObject({ invocation: z.number().optional() })).nullish(),
|
|
253
|
-
cost: perplexityCostSchema.nullish()
|
|
253
|
+
cost: perplexityCostSchema().nullish()
|
|
254
254
|
});
|
|
255
|
-
const perplexityAgentResponseSchema = z.looseObject({
|
|
255
|
+
const perplexityAgentResponseSchema = () => z.looseObject({
|
|
256
256
|
id: z.string(),
|
|
257
257
|
created_at: z.number(),
|
|
258
258
|
model: z.string(),
|
|
259
259
|
object: z.literal("response"),
|
|
260
|
-
output: z.array(perplexityOutputItemSchema),
|
|
260
|
+
output: z.array(perplexityOutputItemSchema()),
|
|
261
261
|
status: z.string(),
|
|
262
262
|
incomplete_details: z.looseObject({ reason: z.string() }).nullish(),
|
|
263
263
|
error: z.looseObject({
|
|
@@ -265,13 +265,14 @@ const perplexityAgentResponseSchema = z.looseObject({
|
|
|
265
265
|
message: z.string(),
|
|
266
266
|
type: z.string().optional()
|
|
267
267
|
}).nullish(),
|
|
268
|
-
usage: perplexityUsageSchema.nullish()
|
|
268
|
+
usage: perplexityUsageSchema().nullish()
|
|
269
269
|
});
|
|
270
|
-
const
|
|
270
|
+
const perplexityAgentResponseSchemaValidator = lazySchema(() => zodSchema(perplexityAgentResponseSchema()));
|
|
271
|
+
const perplexityAgentChunkSchema = lazySchema(() => zodSchema(z.looseObject({
|
|
271
272
|
type: z.string(),
|
|
272
273
|
sequence_number: z.number().nullish(),
|
|
273
|
-
response: perplexityAgentResponseSchema.nullish(),
|
|
274
|
-
item: perplexityOutputItemSchema.nullish(),
|
|
274
|
+
response: perplexityAgentResponseSchema().nullish(),
|
|
275
|
+
item: perplexityOutputItemSchema().nullish(),
|
|
275
276
|
output_index: z.number().nullish(),
|
|
276
277
|
item_id: z.string().nullish(),
|
|
277
278
|
content_index: z.number().nullish(),
|
|
@@ -280,15 +281,15 @@ const perplexityAgentChunkSchema = z.looseObject({
|
|
|
280
281
|
thought: z.string().nullish(),
|
|
281
282
|
queries: z.array(z.string()).nullish(),
|
|
282
283
|
urls: z.array(z.string()).nullish(),
|
|
283
|
-
results: z.array(perplexitySearchResultSchema).nullish(),
|
|
284
|
-
contents: z.array(perplexityFetchedContentSchema).nullish(),
|
|
284
|
+
results: z.array(perplexitySearchResultSchema()).nullish(),
|
|
285
|
+
contents: z.array(perplexityFetchedContentSchema()).nullish(),
|
|
285
286
|
error: z.looseObject({
|
|
286
287
|
code: z.string().nullish(),
|
|
287
288
|
message: z.string(),
|
|
288
289
|
type: z.string().nullish()
|
|
289
290
|
}).nullish()
|
|
290
|
-
});
|
|
291
|
-
const perplexityErrorSchema = z.looseObject({
|
|
291
|
+
})));
|
|
292
|
+
const perplexityErrorSchema = lazySchema(() => zodSchema(z.looseObject({
|
|
292
293
|
error: z.union([z.string(), z.looseObject({
|
|
293
294
|
code: z.union([z.string(), z.number()]).nullish(),
|
|
294
295
|
message: z.string().nullish(),
|
|
@@ -296,7 +297,7 @@ const perplexityErrorSchema = z.looseObject({
|
|
|
296
297
|
})]).optional(),
|
|
297
298
|
detail: z.union([z.string(), z.array(z.looseObject({ msg: z.string() }))]).optional(),
|
|
298
299
|
message: z.string().optional()
|
|
299
|
-
});
|
|
300
|
+
})));
|
|
300
301
|
function perplexityErrorToMessage(data) {
|
|
301
302
|
if (typeof data.error === "string") return data.error;
|
|
302
303
|
if (data.error != null) return data.error.message ?? data.error.type ?? "unknown error";
|
|
@@ -306,14 +307,14 @@ function perplexityErrorToMessage(data) {
|
|
|
306
307
|
}
|
|
307
308
|
//#endregion
|
|
308
309
|
//#region src/perplexity-language-model-options.ts
|
|
309
|
-
const userLocationSchema = z.looseObject({
|
|
310
|
+
const userLocationSchema = () => z.looseObject({
|
|
310
311
|
latitude: z.number().optional(),
|
|
311
312
|
longitude: z.number().optional(),
|
|
312
313
|
country: z.string().optional(),
|
|
313
314
|
city: z.string().optional(),
|
|
314
315
|
region: z.string().optional()
|
|
315
316
|
});
|
|
316
|
-
const webSearchFiltersSchema = z.looseObject({
|
|
317
|
+
const webSearchFiltersSchema = () => z.looseObject({
|
|
317
318
|
search_domain_filter: z.array(z.string()).optional(),
|
|
318
319
|
search_recency_filter: z.enum([
|
|
319
320
|
"hour",
|
|
@@ -327,9 +328,9 @@ const webSearchFiltersSchema = z.looseObject({
|
|
|
327
328
|
last_updated_after_filter: z.string().optional(),
|
|
328
329
|
last_updated_before_filter: z.string().optional()
|
|
329
330
|
});
|
|
330
|
-
const webSearchToolSchema = z.looseObject({
|
|
331
|
+
const webSearchToolSchema = () => z.looseObject({
|
|
331
332
|
type: z.literal("web_search"),
|
|
332
|
-
filters: webSearchFiltersSchema.optional(),
|
|
333
|
+
filters: webSearchFiltersSchema().optional(),
|
|
333
334
|
max_results: z.number().int().positive().optional(),
|
|
334
335
|
max_tokens: z.number().optional(),
|
|
335
336
|
max_tokens_per_page: z.number().optional(),
|
|
@@ -338,10 +339,10 @@ const webSearchToolSchema = z.looseObject({
|
|
|
338
339
|
"medium",
|
|
339
340
|
"high"
|
|
340
341
|
]).optional(),
|
|
341
|
-
user_location: userLocationSchema.optional()
|
|
342
|
+
user_location: userLocationSchema().optional()
|
|
342
343
|
});
|
|
343
|
-
const nativeToolSchema = z.union([
|
|
344
|
-
webSearchToolSchema,
|
|
344
|
+
const nativeToolSchema = () => z.union([
|
|
345
|
+
webSearchToolSchema(),
|
|
345
346
|
z.looseObject({
|
|
346
347
|
type: z.literal("fetch_url"),
|
|
347
348
|
max_urls: z.number().optional()
|
|
@@ -366,14 +367,14 @@ const nativeToolSchema = z.union([
|
|
|
366
367
|
allowed_tools: z.array(z.string()).optional()
|
|
367
368
|
})
|
|
368
369
|
]);
|
|
369
|
-
const perplexityLanguageModelOptions = z.looseObject({
|
|
370
|
+
const perplexityLanguageModelOptions = lazySchema(() => zodSchema(z.looseObject({
|
|
370
371
|
/** Top-level Agent API instructions. */
|
|
371
372
|
instructions: z.string().optional(),
|
|
372
373
|
/**
|
|
373
374
|
* Native Agent API tools. AI SDK function tools can also be supplied through
|
|
374
375
|
* the top-level `tools` option on `generateText` and `streamText`.
|
|
375
376
|
*/
|
|
376
|
-
tools: z.array(nativeToolSchema).optional(),
|
|
377
|
+
tools: z.array(nativeToolSchema()).optional(),
|
|
377
378
|
/** A fallback model list for Agent API routing. */
|
|
378
379
|
models: z.array(z.string()).optional(),
|
|
379
380
|
/** Maximum number of agentic steps. */
|
|
@@ -413,7 +414,7 @@ const perplexityLanguageModelOptions = z.looseObject({
|
|
|
413
414
|
description: z.string(),
|
|
414
415
|
instructions: z.string()
|
|
415
416
|
})])).optional()
|
|
416
|
-
});
|
|
417
|
+
})));
|
|
417
418
|
//#endregion
|
|
418
419
|
//#region src/perplexity-prepare-tools.ts
|
|
419
420
|
function preparePerplexityTools({ tools, toolChoice }) {
|
|
@@ -626,7 +627,7 @@ var PerplexityLanguageModel = class PerplexityLanguageModel {
|
|
|
626
627
|
errorSchema: perplexityErrorSchema,
|
|
627
628
|
errorToMessage: perplexityErrorToMessage
|
|
628
629
|
}),
|
|
629
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
630
|
+
successfulResponseHandler: createJsonResponseHandler(perplexityAgentResponseSchemaValidator),
|
|
630
631
|
abortSignal: options.abortSignal,
|
|
631
632
|
fetch: this.config.fetch
|
|
632
633
|
});
|
|
@@ -1078,7 +1079,7 @@ function decodeEmbedding(base64, encodingFormat) {
|
|
|
1078
1079
|
}
|
|
1079
1080
|
return Array.from(bytes);
|
|
1080
1081
|
}
|
|
1081
|
-
const perplexityEmbeddingResponseSchema = z.object({
|
|
1082
|
+
const perplexityEmbeddingResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
1082
1083
|
data: z.array(z.object({ embedding: z.string() })),
|
|
1083
1084
|
usage: z.object({
|
|
1084
1085
|
prompt_tokens: z.number(),
|
|
@@ -1088,7 +1089,7 @@ const perplexityEmbeddingResponseSchema = z.object({
|
|
|
1088
1089
|
currency: z.string().nullish()
|
|
1089
1090
|
}).nullish()
|
|
1090
1091
|
}).nullish()
|
|
1091
|
-
});
|
|
1092
|
+
})));
|
|
1092
1093
|
//#endregion
|
|
1093
1094
|
//#region src/convert-to-perplexity-decision-state.ts
|
|
1094
1095
|
function convertToPerplexityDecisionState(state) {
|
|
@@ -1157,7 +1158,7 @@ var DecisionPerplexityModel = class DecisionPerplexityModel {
|
|
|
1157
1158
|
static [WORKFLOW_DESERIALIZE](options) {
|
|
1158
1159
|
return new DecisionPerplexityModel(options.modelId, options.config);
|
|
1159
1160
|
}
|
|
1160
|
-
async doDecide({ state, questions, headers, abortSignal, providerOptions }) {
|
|
1161
|
+
async doDecide({ state, questions, maxOutputTokens, reasoning, headers, abortSignal, providerOptions }) {
|
|
1161
1162
|
const entries = Object.entries(questions);
|
|
1162
1163
|
if (entries.length === 0 || entries.length > 128) throw new InvalidArgumentError({
|
|
1163
1164
|
argument: "questions",
|
|
@@ -1241,10 +1242,20 @@ var DecisionPerplexityModel = class DecisionPerplexityModel {
|
|
|
1241
1242
|
inputTokens: response.usage.input_tokens ?? void 0,
|
|
1242
1243
|
outputTokens: response.usage.output_tokens ?? void 0
|
|
1243
1244
|
},
|
|
1244
|
-
warnings:
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1245
|
+
warnings: [
|
|
1246
|
+
...maxOutputTokens != null ? [{
|
|
1247
|
+
type: "unsupported",
|
|
1248
|
+
feature: "maxOutputTokens"
|
|
1249
|
+
}] : [],
|
|
1250
|
+
...reasoning != null ? [{
|
|
1251
|
+
type: "unsupported",
|
|
1252
|
+
feature: "reasoning"
|
|
1253
|
+
}] : [],
|
|
1254
|
+
...Object.keys(providerOptions?.perplexity ?? {}).map((option) => ({
|
|
1255
|
+
type: "unsupported",
|
|
1256
|
+
feature: `providerOptions.perplexity.${option}`
|
|
1257
|
+
}))
|
|
1258
|
+
],
|
|
1248
1259
|
providerMetadata: { perplexity: {
|
|
1249
1260
|
confidence: Object.fromEntries(Object.entries(response.answers).flatMap(([id, answer]) => answer.type !== "noul" && answer.confidence != null ? [[id, answer.confidence]] : [])),
|
|
1250
1261
|
legend: Object.fromEntries(Object.entries(response.answers).flatMap(([id, answer]) => answer.type === "score" && answer.legend != null ? [[id, answer.legend]] : []))
|
|
@@ -1258,25 +1269,25 @@ var DecisionPerplexityModel = class DecisionPerplexityModel {
|
|
|
1258
1269
|
};
|
|
1259
1270
|
}
|
|
1260
1271
|
};
|
|
1261
|
-
const probability = z.number().min(0).max(1);
|
|
1262
|
-
const perplexityDecisionResponseSchema = z.object({
|
|
1272
|
+
const probability = () => z.number().min(0).max(1);
|
|
1273
|
+
const perplexityDecisionResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
1263
1274
|
model: z.string().nullish(),
|
|
1264
1275
|
answers: z.record(z.string(), z.discriminatedUnion("type", [
|
|
1265
1276
|
z.object({
|
|
1266
1277
|
type: z.literal("noul"),
|
|
1267
|
-
noul: probability
|
|
1278
|
+
noul: probability()
|
|
1268
1279
|
}),
|
|
1269
1280
|
z.object({
|
|
1270
1281
|
type: z.literal("choice"),
|
|
1271
1282
|
choice: z.string(),
|
|
1272
|
-
probabilities: z.record(z.string(), probability),
|
|
1273
|
-
confidence: probability.nullish()
|
|
1283
|
+
probabilities: z.record(z.string(), probability()),
|
|
1284
|
+
confidence: probability().nullish()
|
|
1274
1285
|
}),
|
|
1275
1286
|
z.object({
|
|
1276
1287
|
type: z.literal("score"),
|
|
1277
1288
|
score: z.number(),
|
|
1278
|
-
probabilities: z.record(z.string(), probability),
|
|
1279
|
-
confidence: probability.nullish(),
|
|
1289
|
+
probabilities: z.record(z.string(), probability()),
|
|
1290
|
+
confidence: probability().nullish(),
|
|
1280
1291
|
legend: z.record(z.string(), z.json()).nullish()
|
|
1281
1292
|
})
|
|
1282
1293
|
])),
|
|
@@ -1284,10 +1295,10 @@ const perplexityDecisionResponseSchema = z.object({
|
|
|
1284
1295
|
input_tokens: z.number().nullish(),
|
|
1285
1296
|
output_tokens: z.number().nullish()
|
|
1286
1297
|
}).nullish()
|
|
1287
|
-
});
|
|
1298
|
+
})));
|
|
1288
1299
|
//#endregion
|
|
1289
1300
|
//#region src/version.ts
|
|
1290
|
-
const VERSION = "5.0.
|
|
1301
|
+
const VERSION = "5.0.17";
|
|
1291
1302
|
//#endregion
|
|
1292
1303
|
//#region src/perplexity-provider.ts
|
|
1293
1304
|
function createPerplexity(options = {}) {
|