@ai-sdk/perplexity 3.1.7 → 3.1.8
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 +9 -0
- package/dist/index.d.mts +87 -115
- package/dist/index.d.ts +87 -115
- package/dist/index.js +184 -158
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -134
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/perplexity-agent-api.ts +184 -161
- 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 -5
package/dist/index.js
CHANGED
|
@@ -28,34 +28,39 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/perplexity-provider.ts
|
|
30
30
|
var import_provider4 = require("@ai-sdk/provider");
|
|
31
|
-
var
|
|
31
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/perplexity-embedding-model.ts
|
|
34
34
|
var import_provider3 = require("@ai-sdk/provider");
|
|
35
|
-
var
|
|
35
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
36
36
|
var import_v44 = require("zod/v4");
|
|
37
37
|
|
|
38
38
|
// src/perplexity-embedding-model-options.ts
|
|
39
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
39
40
|
var import_v4 = require("zod/v4");
|
|
40
|
-
var perplexityEmbeddingModelOptions =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
var perplexityEmbeddingModelOptions = (0, import_provider_utils.lazySchema)(
|
|
42
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
43
|
+
import_v4.z.object({
|
|
44
|
+
/**
|
|
45
|
+
* The number of dimensions the resulting output embeddings should have
|
|
46
|
+
* (Matryoshka truncation). Ranges from 128 up to the model's full size
|
|
47
|
+
* (1024 for 0.6b models, 2560 for 4b models).
|
|
48
|
+
*/
|
|
49
|
+
dimensions: import_v4.z.number().int().positive().optional(),
|
|
50
|
+
/**
|
|
51
|
+
* The quantized encoding format returned by the API. Perplexity does not
|
|
52
|
+
* return floating point embeddings; values are decoded to numbers:
|
|
53
|
+
* - `base64_int8` (default): signed int8 values, compare via cosine similarity.
|
|
54
|
+
* - `base64_binary`: packed bits per byte (0-255), compare via Hamming distance.
|
|
55
|
+
*/
|
|
56
|
+
encodingFormat: import_v4.z.enum(["base64_int8", "base64_binary"]).optional()
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
);
|
|
55
60
|
|
|
56
61
|
// src/perplexity-language-model.ts
|
|
57
62
|
var import_provider2 = require("@ai-sdk/provider");
|
|
58
|
-
var
|
|
63
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
59
64
|
|
|
60
65
|
// src/convert-perplexity-usage.ts
|
|
61
66
|
function convertPerplexityUsage(usage) {
|
|
@@ -99,7 +104,7 @@ function convertPerplexityUsage(usage) {
|
|
|
99
104
|
|
|
100
105
|
// src/convert-to-perplexity-input.ts
|
|
101
106
|
var import_provider = require("@ai-sdk/provider");
|
|
102
|
-
var
|
|
107
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
103
108
|
function serializeToolOutput(output) {
|
|
104
109
|
var _a;
|
|
105
110
|
switch (output.type) {
|
|
@@ -165,7 +170,7 @@ function convertToPerplexityInput(prompt) {
|
|
|
165
170
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
166
171
|
return {
|
|
167
172
|
type: "input_image",
|
|
168
|
-
image_url: `data:${mediaType};base64,${typeof part.data === "string" ? part.data : (0,
|
|
173
|
+
image_url: `data:${mediaType};base64,${typeof part.data === "string" ? part.data : (0, import_provider_utils2.convertUint8ArrayToBase64)(part.data)}`
|
|
169
174
|
};
|
|
170
175
|
}
|
|
171
176
|
}
|
|
@@ -282,8 +287,9 @@ function mapPerplexityFinishReason({
|
|
|
282
287
|
}
|
|
283
288
|
|
|
284
289
|
// src/perplexity-agent-api.ts
|
|
290
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
285
291
|
var import_v42 = require("zod/v4");
|
|
286
|
-
var perplexitySearchResultSchema = import_v42.z.looseObject({
|
|
292
|
+
var perplexitySearchResultSchema = () => import_v42.z.looseObject({
|
|
287
293
|
id: import_v42.z.number().optional(),
|
|
288
294
|
title: import_v42.z.string(),
|
|
289
295
|
url: import_v42.z.string(),
|
|
@@ -292,12 +298,12 @@ var perplexitySearchResultSchema = import_v42.z.looseObject({
|
|
|
292
298
|
last_updated: import_v42.z.string().nullish(),
|
|
293
299
|
source: import_v42.z.string().optional()
|
|
294
300
|
});
|
|
295
|
-
var perplexityFetchedContentSchema = import_v42.z.looseObject({
|
|
301
|
+
var perplexityFetchedContentSchema = () => import_v42.z.looseObject({
|
|
296
302
|
title: import_v42.z.string(),
|
|
297
303
|
url: import_v42.z.string(),
|
|
298
304
|
snippet: import_v42.z.string().optional()
|
|
299
305
|
});
|
|
300
|
-
var perplexityContentPartSchema = import_v42.z.looseObject({
|
|
306
|
+
var perplexityContentPartSchema = () => import_v42.z.looseObject({
|
|
301
307
|
type: import_v42.z.string(),
|
|
302
308
|
text: import_v42.z.string().optional(),
|
|
303
309
|
annotations: import_v42.z.array(
|
|
@@ -314,19 +320,19 @@ var handledOutputTypes = [
|
|
|
314
320
|
"fetch_url_results",
|
|
315
321
|
"function_call"
|
|
316
322
|
];
|
|
317
|
-
var perplexityOutputItemSchema = import_v42.z.union([
|
|
323
|
+
var perplexityOutputItemSchema = () => import_v42.z.union([
|
|
318
324
|
import_v42.z.looseObject({
|
|
319
325
|
type: import_v42.z.literal("message"),
|
|
320
326
|
id: import_v42.z.string().nullish(),
|
|
321
|
-
content: import_v42.z.array(perplexityContentPartSchema).nullish()
|
|
327
|
+
content: import_v42.z.array(perplexityContentPartSchema()).nullish()
|
|
322
328
|
}),
|
|
323
329
|
import_v42.z.looseObject({
|
|
324
330
|
type: import_v42.z.literal("search_results"),
|
|
325
|
-
results: import_v42.z.array(perplexitySearchResultSchema).nullish()
|
|
331
|
+
results: import_v42.z.array(perplexitySearchResultSchema()).nullish()
|
|
326
332
|
}),
|
|
327
333
|
import_v42.z.looseObject({
|
|
328
334
|
type: import_v42.z.literal("fetch_url_results"),
|
|
329
|
-
contents: import_v42.z.array(perplexityFetchedContentSchema).nullish()
|
|
335
|
+
contents: import_v42.z.array(perplexityFetchedContentSchema()).nullish()
|
|
330
336
|
}),
|
|
331
337
|
import_v42.z.looseObject({
|
|
332
338
|
type: import_v42.z.literal("function_call"),
|
|
@@ -343,7 +349,7 @@ var perplexityOutputItemSchema = import_v42.z.union([
|
|
|
343
349
|
type: import_v42.z.string().refine((type) => !handledOutputTypes.includes(type))
|
|
344
350
|
}).transform(() => ({ type: "unhandled" }))
|
|
345
351
|
]);
|
|
346
|
-
var perplexityCostSchema = import_v42.z.looseObject({
|
|
352
|
+
var perplexityCostSchema = () => import_v42.z.looseObject({
|
|
347
353
|
currency: import_v42.z.string().optional(),
|
|
348
354
|
input_cost: import_v42.z.number().optional(),
|
|
349
355
|
output_cost: import_v42.z.number().optional(),
|
|
@@ -352,7 +358,7 @@ var perplexityCostSchema = import_v42.z.looseObject({
|
|
|
352
358
|
cache_read_cost: import_v42.z.number().nullish(),
|
|
353
359
|
tool_calls_cost: import_v42.z.number().nullish()
|
|
354
360
|
});
|
|
355
|
-
var perplexityUsageSchema = import_v42.z.looseObject({
|
|
361
|
+
var perplexityUsageSchema = () => import_v42.z.looseObject({
|
|
356
362
|
input_tokens: import_v42.z.number(),
|
|
357
363
|
output_tokens: import_v42.z.number(),
|
|
358
364
|
total_tokens: import_v42.z.number(),
|
|
@@ -370,14 +376,14 @@ var perplexityUsageSchema = import_v42.z.looseObject({
|
|
|
370
376
|
invocation: import_v42.z.number().optional()
|
|
371
377
|
})
|
|
372
378
|
).nullish(),
|
|
373
|
-
cost: perplexityCostSchema.nullish()
|
|
379
|
+
cost: perplexityCostSchema().nullish()
|
|
374
380
|
});
|
|
375
|
-
var perplexityAgentResponseSchema = import_v42.z.looseObject({
|
|
381
|
+
var perplexityAgentResponseSchema = () => import_v42.z.looseObject({
|
|
376
382
|
id: import_v42.z.string(),
|
|
377
383
|
created_at: import_v42.z.number(),
|
|
378
384
|
model: import_v42.z.string(),
|
|
379
385
|
object: import_v42.z.literal("response"),
|
|
380
|
-
output: import_v42.z.array(perplexityOutputItemSchema),
|
|
386
|
+
output: import_v42.z.array(perplexityOutputItemSchema()),
|
|
381
387
|
status: import_v42.z.string(),
|
|
382
388
|
incomplete_details: import_v42.z.looseObject({
|
|
383
389
|
reason: import_v42.z.string()
|
|
@@ -387,48 +393,59 @@ var perplexityAgentResponseSchema = import_v42.z.looseObject({
|
|
|
387
393
|
message: import_v42.z.string(),
|
|
388
394
|
type: import_v42.z.string().optional()
|
|
389
395
|
}).nullish(),
|
|
390
|
-
usage: perplexityUsageSchema.nullish()
|
|
391
|
-
});
|
|
392
|
-
var perplexityAgentChunkSchema = import_v42.z.looseObject({
|
|
393
|
-
type: import_v42.z.string(),
|
|
394
|
-
sequence_number: import_v42.z.number().nullish(),
|
|
395
|
-
response: perplexityAgentResponseSchema.nullish(),
|
|
396
|
-
item: perplexityOutputItemSchema.nullish(),
|
|
397
|
-
output_index: import_v42.z.number().nullish(),
|
|
398
|
-
item_id: import_v42.z.string().nullish(),
|
|
399
|
-
content_index: import_v42.z.number().nullish(),
|
|
400
|
-
delta: import_v42.z.string().nullish(),
|
|
401
|
-
text: import_v42.z.string().nullish(),
|
|
402
|
-
thought: import_v42.z.string().nullish(),
|
|
403
|
-
queries: import_v42.z.array(import_v42.z.string()).nullish(),
|
|
404
|
-
urls: import_v42.z.array(import_v42.z.string()).nullish(),
|
|
405
|
-
results: import_v42.z.array(perplexitySearchResultSchema).nullish(),
|
|
406
|
-
contents: import_v42.z.array(perplexityFetchedContentSchema).nullish(),
|
|
407
|
-
error: import_v42.z.looseObject({
|
|
408
|
-
code: import_v42.z.string().nullish(),
|
|
409
|
-
message: import_v42.z.string(),
|
|
410
|
-
type: import_v42.z.string().nullish()
|
|
411
|
-
}).nullish()
|
|
396
|
+
usage: perplexityUsageSchema().nullish()
|
|
412
397
|
});
|
|
413
|
-
var
|
|
414
|
-
|
|
415
|
-
|
|
398
|
+
var perplexityAgentResponseSchemaValidator = (0, import_provider_utils3.lazySchema)(
|
|
399
|
+
() => (0, import_provider_utils3.zodSchema)(perplexityAgentResponseSchema())
|
|
400
|
+
);
|
|
401
|
+
var perplexityAgentChunkSchema = (0, import_provider_utils3.lazySchema)(
|
|
402
|
+
() => (0, import_provider_utils3.zodSchema)(
|
|
416
403
|
import_v42.z.looseObject({
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
404
|
+
type: import_v42.z.string(),
|
|
405
|
+
sequence_number: import_v42.z.number().nullish(),
|
|
406
|
+
response: perplexityAgentResponseSchema().nullish(),
|
|
407
|
+
item: perplexityOutputItemSchema().nullish(),
|
|
408
|
+
output_index: import_v42.z.number().nullish(),
|
|
409
|
+
item_id: import_v42.z.string().nullish(),
|
|
410
|
+
content_index: import_v42.z.number().nullish(),
|
|
411
|
+
delta: import_v42.z.string().nullish(),
|
|
412
|
+
text: import_v42.z.string().nullish(),
|
|
413
|
+
thought: import_v42.z.string().nullish(),
|
|
414
|
+
queries: import_v42.z.array(import_v42.z.string()).nullish(),
|
|
415
|
+
urls: import_v42.z.array(import_v42.z.string()).nullish(),
|
|
416
|
+
results: import_v42.z.array(perplexitySearchResultSchema()).nullish(),
|
|
417
|
+
contents: import_v42.z.array(perplexityFetchedContentSchema()).nullish(),
|
|
418
|
+
error: import_v42.z.looseObject({
|
|
419
|
+
code: import_v42.z.string().nullish(),
|
|
420
|
+
message: import_v42.z.string(),
|
|
421
|
+
type: import_v42.z.string().nullish()
|
|
422
|
+
}).nullish()
|
|
420
423
|
})
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
var perplexityErrorSchema = (0, import_provider_utils3.lazySchema)(
|
|
427
|
+
() => (0, import_provider_utils3.zodSchema)(
|
|
428
|
+
import_v42.z.looseObject({
|
|
429
|
+
error: import_v42.z.union([
|
|
430
|
+
import_v42.z.string(),
|
|
431
|
+
import_v42.z.looseObject({
|
|
432
|
+
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).optional(),
|
|
433
|
+
message: import_v42.z.string().nullish(),
|
|
434
|
+
type: import_v42.z.string().nullish()
|
|
435
|
+
})
|
|
436
|
+
]).optional(),
|
|
437
|
+
detail: import_v42.z.union([
|
|
438
|
+
import_v42.z.string(),
|
|
439
|
+
import_v42.z.array(
|
|
440
|
+
import_v42.z.looseObject({
|
|
441
|
+
msg: import_v42.z.string()
|
|
442
|
+
})
|
|
443
|
+
)
|
|
444
|
+
]).optional(),
|
|
445
|
+
message: import_v42.z.string().optional()
|
|
446
|
+
})
|
|
447
|
+
)
|
|
448
|
+
);
|
|
432
449
|
function perplexityErrorToMessage(data) {
|
|
433
450
|
var _a, _b, _c;
|
|
434
451
|
if (typeof data.error === "string") {
|
|
@@ -447,15 +464,16 @@ function perplexityErrorToMessage(data) {
|
|
|
447
464
|
}
|
|
448
465
|
|
|
449
466
|
// src/perplexity-language-model-options.ts
|
|
467
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
450
468
|
var import_v43 = require("zod/v4");
|
|
451
|
-
var userLocationSchema = import_v43.z.looseObject({
|
|
469
|
+
var userLocationSchema = () => import_v43.z.looseObject({
|
|
452
470
|
latitude: import_v43.z.number().optional(),
|
|
453
471
|
longitude: import_v43.z.number().optional(),
|
|
454
472
|
country: import_v43.z.string().optional(),
|
|
455
473
|
city: import_v43.z.string().optional(),
|
|
456
474
|
region: import_v43.z.string().optional()
|
|
457
475
|
});
|
|
458
|
-
var webSearchFiltersSchema = import_v43.z.looseObject({
|
|
476
|
+
var webSearchFiltersSchema = () => import_v43.z.looseObject({
|
|
459
477
|
search_domain_filter: import_v43.z.array(import_v43.z.string()).optional(),
|
|
460
478
|
search_recency_filter: import_v43.z.enum(["hour", "day", "week", "month", "year"]).optional(),
|
|
461
479
|
search_after_date_filter: import_v43.z.string().optional(),
|
|
@@ -463,17 +481,17 @@ var webSearchFiltersSchema = import_v43.z.looseObject({
|
|
|
463
481
|
last_updated_after_filter: import_v43.z.string().optional(),
|
|
464
482
|
last_updated_before_filter: import_v43.z.string().optional()
|
|
465
483
|
});
|
|
466
|
-
var webSearchToolSchema = import_v43.z.looseObject({
|
|
484
|
+
var webSearchToolSchema = () => import_v43.z.looseObject({
|
|
467
485
|
type: import_v43.z.literal("web_search"),
|
|
468
|
-
filters: webSearchFiltersSchema.optional(),
|
|
486
|
+
filters: webSearchFiltersSchema().optional(),
|
|
469
487
|
max_results: import_v43.z.number().int().positive().optional(),
|
|
470
488
|
max_tokens: import_v43.z.number().optional(),
|
|
471
489
|
max_tokens_per_page: import_v43.z.number().optional(),
|
|
472
490
|
search_context_size: import_v43.z.enum(["low", "medium", "high"]).optional(),
|
|
473
|
-
user_location: userLocationSchema.optional()
|
|
491
|
+
user_location: userLocationSchema().optional()
|
|
474
492
|
});
|
|
475
|
-
var nativeToolSchema = import_v43.z.union([
|
|
476
|
-
webSearchToolSchema,
|
|
493
|
+
var nativeToolSchema = () => import_v43.z.union([
|
|
494
|
+
webSearchToolSchema(),
|
|
477
495
|
import_v43.z.looseObject({
|
|
478
496
|
type: import_v43.z.literal("fetch_url"),
|
|
479
497
|
max_urls: import_v43.z.number().optional()
|
|
@@ -498,55 +516,59 @@ var nativeToolSchema = import_v43.z.union([
|
|
|
498
516
|
allowed_tools: import_v43.z.array(import_v43.z.string()).optional()
|
|
499
517
|
})
|
|
500
518
|
]);
|
|
501
|
-
var perplexityLanguageModelOptions =
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
import_v43.z.
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
519
|
+
var perplexityLanguageModelOptions = (0, import_provider_utils4.lazySchema)(
|
|
520
|
+
() => (0, import_provider_utils4.zodSchema)(
|
|
521
|
+
import_v43.z.looseObject({
|
|
522
|
+
/** Top-level Agent API instructions. */
|
|
523
|
+
instructions: import_v43.z.string().optional(),
|
|
524
|
+
/**
|
|
525
|
+
* Native Agent API tools. AI SDK function tools can also be supplied through
|
|
526
|
+
* the top-level `tools` option on `generateText` and `streamText`.
|
|
527
|
+
*/
|
|
528
|
+
tools: import_v43.z.array(nativeToolSchema()).optional(),
|
|
529
|
+
/** A fallback model list for Agent API routing. */
|
|
530
|
+
models: import_v43.z.array(import_v43.z.string()).optional(),
|
|
531
|
+
/** Maximum number of agentic steps. */
|
|
532
|
+
max_steps: import_v43.z.number().int().positive().optional(),
|
|
533
|
+
/** Maximum number of native tool calls. */
|
|
534
|
+
max_tool_calls: import_v43.z.number().int().nonnegative().optional(),
|
|
535
|
+
/** Continue a conversation from an earlier Agent API response. */
|
|
536
|
+
previous_response_id: import_v43.z.string().optional(),
|
|
537
|
+
/**
|
|
538
|
+
* Whether the response can be retrieved later. Setting this to false does
|
|
539
|
+
* not disable persistence or prevent previous_response_id continuations.
|
|
540
|
+
*/
|
|
541
|
+
store: import_v43.z.boolean().optional(),
|
|
542
|
+
/** Preferred response language as an ISO 639-1 language code. */
|
|
543
|
+
language_preference: import_v43.z.string().optional(),
|
|
544
|
+
/** Agent API reasoning configuration. */
|
|
545
|
+
reasoning: import_v43.z.looseObject({
|
|
546
|
+
effort: import_v43.z.enum(["minimal", "low", "medium", "high", "xhigh"]).optional()
|
|
547
|
+
}).optional(),
|
|
548
|
+
/** Agent API skill configuration. */
|
|
549
|
+
skills: import_v43.z.array(
|
|
550
|
+
import_v43.z.union([
|
|
551
|
+
import_v43.z.looseObject({
|
|
552
|
+
type: import_v43.z.literal("builtin"),
|
|
553
|
+
name: import_v43.z.enum([
|
|
554
|
+
"office",
|
|
555
|
+
"office/docx",
|
|
556
|
+
"office/pdf",
|
|
557
|
+
"office/pptx",
|
|
558
|
+
"office/xlsx"
|
|
559
|
+
])
|
|
560
|
+
}),
|
|
561
|
+
import_v43.z.looseObject({
|
|
562
|
+
type: import_v43.z.literal("inline"),
|
|
563
|
+
name: import_v43.z.string(),
|
|
564
|
+
description: import_v43.z.string(),
|
|
565
|
+
instructions: import_v43.z.string()
|
|
566
|
+
})
|
|
539
567
|
])
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
description: import_v43.z.string(),
|
|
545
|
-
instructions: import_v43.z.string()
|
|
546
|
-
})
|
|
547
|
-
])
|
|
548
|
-
).optional()
|
|
549
|
-
});
|
|
568
|
+
).optional()
|
|
569
|
+
})
|
|
570
|
+
)
|
|
571
|
+
);
|
|
550
572
|
|
|
551
573
|
// src/perplexity-prepare-tools.ts
|
|
552
574
|
function preparePerplexityTools({
|
|
@@ -699,7 +721,7 @@ var PerplexityLanguageModel = class {
|
|
|
699
721
|
}) {
|
|
700
722
|
var _a, _b;
|
|
701
723
|
const warnings = [];
|
|
702
|
-
const perplexityOptions = (_a = await (0,
|
|
724
|
+
const perplexityOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
|
|
703
725
|
provider: "perplexity",
|
|
704
726
|
providerOptions,
|
|
705
727
|
schema: perplexityLanguageModelOptions
|
|
@@ -763,16 +785,16 @@ var PerplexityLanguageModel = class {
|
|
|
763
785
|
responseHeaders,
|
|
764
786
|
value: response,
|
|
765
787
|
rawValue: rawResponse
|
|
766
|
-
} = await (0,
|
|
788
|
+
} = await (0, import_provider_utils5.postJsonToApi)({
|
|
767
789
|
url,
|
|
768
|
-
headers: (0,
|
|
790
|
+
headers: (0, import_provider_utils5.combineHeaders)((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
769
791
|
body,
|
|
770
|
-
failedResponseHandler: (0,
|
|
792
|
+
failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
|
|
771
793
|
errorSchema: perplexityErrorSchema,
|
|
772
794
|
errorToMessage: perplexityErrorToMessage
|
|
773
795
|
}),
|
|
774
|
-
successfulResponseHandler: (0,
|
|
775
|
-
|
|
796
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
797
|
+
perplexityAgentResponseSchemaValidator
|
|
776
798
|
),
|
|
777
799
|
abortSignal: options.abortSignal,
|
|
778
800
|
fetch: this.config.fetch
|
|
@@ -879,15 +901,15 @@ var PerplexityLanguageModel = class {
|
|
|
879
901
|
var _a, _b;
|
|
880
902
|
const { args, warnings } = await this.getArgs(options);
|
|
881
903
|
const body = { ...args, stream: true };
|
|
882
|
-
const { responseHeaders, value: response } = await (0,
|
|
904
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
|
|
883
905
|
url: `${this.config.baseURL}/v1/agent`,
|
|
884
|
-
headers: (0,
|
|
906
|
+
headers: (0, import_provider_utils5.combineHeaders)((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
885
907
|
body,
|
|
886
|
-
failedResponseHandler: (0,
|
|
908
|
+
failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
|
|
887
909
|
errorSchema: perplexityErrorSchema,
|
|
888
910
|
errorToMessage: perplexityErrorToMessage
|
|
889
911
|
}),
|
|
890
|
-
successfulResponseHandler: (0,
|
|
912
|
+
successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(
|
|
891
913
|
perplexityAgentChunkSchema
|
|
892
914
|
),
|
|
893
915
|
abortSignal: options.abortSignal,
|
|
@@ -1253,7 +1275,7 @@ var PerplexityEmbeddingModel = class {
|
|
|
1253
1275
|
values
|
|
1254
1276
|
});
|
|
1255
1277
|
}
|
|
1256
|
-
const perplexityOptions = (_a = await (0,
|
|
1278
|
+
const perplexityOptions = (_a = await (0, import_provider_utils6.parseProviderOptions)({
|
|
1257
1279
|
provider: "perplexity",
|
|
1258
1280
|
providerOptions,
|
|
1259
1281
|
schema: perplexityEmbeddingModelOptions
|
|
@@ -1263,20 +1285,20 @@ var PerplexityEmbeddingModel = class {
|
|
|
1263
1285
|
responseHeaders,
|
|
1264
1286
|
value: response,
|
|
1265
1287
|
rawValue
|
|
1266
|
-
} = await (0,
|
|
1288
|
+
} = await (0, import_provider_utils6.postJsonToApi)({
|
|
1267
1289
|
url: `${this.config.baseURL}/v1/embeddings`,
|
|
1268
|
-
headers: (0,
|
|
1290
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers),
|
|
1269
1291
|
body: {
|
|
1270
1292
|
model: this.modelId,
|
|
1271
1293
|
input: values,
|
|
1272
1294
|
dimensions: perplexityOptions.dimensions,
|
|
1273
1295
|
encoding_format: encodingFormat
|
|
1274
1296
|
},
|
|
1275
|
-
failedResponseHandler: (0,
|
|
1297
|
+
failedResponseHandler: (0, import_provider_utils6.createJsonErrorResponseHandler)({
|
|
1276
1298
|
errorSchema: perplexityErrorSchema,
|
|
1277
1299
|
errorToMessage: perplexityErrorToMessage
|
|
1278
1300
|
}),
|
|
1279
|
-
successfulResponseHandler: (0,
|
|
1301
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
1280
1302
|
perplexityEmbeddingResponseSchema
|
|
1281
1303
|
),
|
|
1282
1304
|
abortSignal,
|
|
@@ -1303,7 +1325,7 @@ var PerplexityEmbeddingModel = class {
|
|
|
1303
1325
|
}
|
|
1304
1326
|
};
|
|
1305
1327
|
function decodeEmbedding(base64, encodingFormat) {
|
|
1306
|
-
const bytes = (0,
|
|
1328
|
+
const bytes = (0, import_provider_utils6.convertBase64ToUint8Array)(base64);
|
|
1307
1329
|
if (encodingFormat === "base64_int8") {
|
|
1308
1330
|
const int8 = new Int8Array(
|
|
1309
1331
|
bytes.buffer,
|
|
@@ -1314,27 +1336,31 @@ function decodeEmbedding(base64, encodingFormat) {
|
|
|
1314
1336
|
}
|
|
1315
1337
|
return Array.from(bytes);
|
|
1316
1338
|
}
|
|
1317
|
-
var perplexityEmbeddingResponseSchema =
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
})
|
|
1339
|
+
var perplexityEmbeddingResponseSchema = (0, import_provider_utils6.lazySchema)(
|
|
1340
|
+
() => (0, import_provider_utils6.zodSchema)(
|
|
1341
|
+
import_v44.z.object({
|
|
1342
|
+
data: import_v44.z.array(import_v44.z.object({ embedding: import_v44.z.string() })),
|
|
1343
|
+
usage: import_v44.z.object({
|
|
1344
|
+
prompt_tokens: import_v44.z.number(),
|
|
1345
|
+
cost: import_v44.z.object({
|
|
1346
|
+
input_cost: import_v44.z.number().nullish(),
|
|
1347
|
+
total_cost: import_v44.z.number().nullish(),
|
|
1348
|
+
currency: import_v44.z.string().nullish()
|
|
1349
|
+
}).nullish()
|
|
1350
|
+
}).nullish()
|
|
1351
|
+
})
|
|
1352
|
+
)
|
|
1353
|
+
);
|
|
1328
1354
|
|
|
1329
1355
|
// src/version.ts
|
|
1330
|
-
var VERSION = true ? "3.1.
|
|
1356
|
+
var VERSION = true ? "3.1.8" : "0.0.0-test";
|
|
1331
1357
|
|
|
1332
1358
|
// src/perplexity-provider.ts
|
|
1333
1359
|
function createPerplexity(options = {}) {
|
|
1334
1360
|
var _a;
|
|
1335
|
-
const getHeaders = () => (0,
|
|
1361
|
+
const getHeaders = () => (0, import_provider_utils7.withUserAgentSuffix)(
|
|
1336
1362
|
{
|
|
1337
|
-
Authorization: `Bearer ${(0,
|
|
1363
|
+
Authorization: `Bearer ${(0, import_provider_utils7.loadApiKey)({
|
|
1338
1364
|
apiKey: options.apiKey,
|
|
1339
1365
|
environmentVariableName: "PERPLEXITY_API_KEY",
|
|
1340
1366
|
description: "Perplexity"
|
|
@@ -1344,14 +1370,14 @@ function createPerplexity(options = {}) {
|
|
|
1344
1370
|
},
|
|
1345
1371
|
`ai-sdk/perplexity/${VERSION}`
|
|
1346
1372
|
);
|
|
1347
|
-
const baseURL = (0,
|
|
1373
|
+
const baseURL = (0, import_provider_utils7.withoutTrailingSlash)(
|
|
1348
1374
|
(_a = options.baseURL) != null ? _a : "https://api.perplexity.ai"
|
|
1349
1375
|
);
|
|
1350
1376
|
const createLanguageModel = (modelId) => {
|
|
1351
1377
|
return new PerplexityLanguageModel(modelId, {
|
|
1352
1378
|
baseURL,
|
|
1353
1379
|
headers: getHeaders,
|
|
1354
|
-
generateId:
|
|
1380
|
+
generateId: import_provider_utils7.generateId,
|
|
1355
1381
|
fetch: options.fetch
|
|
1356
1382
|
});
|
|
1357
1383
|
};
|