pareta 1.1.0 → 1.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.
- package/dist/index.cjs +161 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -5
- package/dist/index.d.ts +117 -5
- package/dist/index.mjs +157 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -174,7 +174,7 @@ function parseSSE(reader, opts) {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// src/version.ts
|
|
177
|
-
var VERSION = "1.
|
|
177
|
+
var VERSION = "1.3.0";
|
|
178
178
|
|
|
179
179
|
// src/money.ts
|
|
180
180
|
var MICRO_PER_CENT = 10000n;
|
|
@@ -486,6 +486,79 @@ var Embeddings = class extends BaseModel {
|
|
|
486
486
|
return (this.raw.data ?? []).length;
|
|
487
487
|
}
|
|
488
488
|
};
|
|
489
|
+
function base64ToBytes(b64) {
|
|
490
|
+
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(b64, "base64"));
|
|
491
|
+
const bin = atob(b64);
|
|
492
|
+
const bytes = new Uint8Array(bin.length);
|
|
493
|
+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
494
|
+
return bytes;
|
|
495
|
+
}
|
|
496
|
+
var Transcription = class extends BaseModel {
|
|
497
|
+
get text() {
|
|
498
|
+
return this.raw.text ?? null;
|
|
499
|
+
}
|
|
500
|
+
get language() {
|
|
501
|
+
return this.raw.language ?? null;
|
|
502
|
+
}
|
|
503
|
+
get durationS() {
|
|
504
|
+
return this.raw.duration_s ?? null;
|
|
505
|
+
}
|
|
506
|
+
toString() {
|
|
507
|
+
return this.text ?? "";
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
var Speech = class extends BaseModel {
|
|
511
|
+
/** The synthesized audio, base64-decoded to raw bytes. */
|
|
512
|
+
get audio() {
|
|
513
|
+
const b64 = this.raw.audio_base64 || "";
|
|
514
|
+
return b64 ? base64ToBytes(b64) : new Uint8Array(0);
|
|
515
|
+
}
|
|
516
|
+
get audioBase64() {
|
|
517
|
+
return this.raw.audio_base64 ?? null;
|
|
518
|
+
}
|
|
519
|
+
get sampleRate() {
|
|
520
|
+
return this.raw.sample_rate ?? null;
|
|
521
|
+
}
|
|
522
|
+
get durationS() {
|
|
523
|
+
return this.raw.duration_s ?? null;
|
|
524
|
+
}
|
|
525
|
+
/** Container/codec of the returned audio (e.g. "wav"). */
|
|
526
|
+
get format() {
|
|
527
|
+
return this.raw.format ?? null;
|
|
528
|
+
}
|
|
529
|
+
/** Write the decoded audio to `path` (Node only — lazy node:fs). */
|
|
530
|
+
async save(path) {
|
|
531
|
+
const { writeFile } = await import('fs/promises');
|
|
532
|
+
await writeFile(path, this.audio);
|
|
533
|
+
return this;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
var ImageGeneration = class extends BaseModel {
|
|
537
|
+
/** The generated image, base64-decoded to raw PNG bytes. */
|
|
538
|
+
get image() {
|
|
539
|
+
const b64 = this.b64Json ?? "";
|
|
540
|
+
return b64 ? base64ToBytes(b64) : new Uint8Array(0);
|
|
541
|
+
}
|
|
542
|
+
get b64Json() {
|
|
543
|
+
const data = this.raw.data ?? [];
|
|
544
|
+
return data[0]?.b64_json ?? null;
|
|
545
|
+
}
|
|
546
|
+
get size() {
|
|
547
|
+
return this.raw.size ?? null;
|
|
548
|
+
}
|
|
549
|
+
get model() {
|
|
550
|
+
return this.raw.model ?? null;
|
|
551
|
+
}
|
|
552
|
+
get created() {
|
|
553
|
+
return this.raw.created ?? null;
|
|
554
|
+
}
|
|
555
|
+
/** Write the decoded PNG to `path` (Node only — lazy node:fs). */
|
|
556
|
+
async save(path) {
|
|
557
|
+
const { writeFile } = await import('fs/promises');
|
|
558
|
+
await writeFile(path, this.image);
|
|
559
|
+
return this;
|
|
560
|
+
}
|
|
561
|
+
};
|
|
489
562
|
|
|
490
563
|
// src/resources/chat.ts
|
|
491
564
|
var PATH = "/v1/chat/completions";
|
|
@@ -788,6 +861,82 @@ var Auto = class {
|
|
|
788
861
|
}
|
|
789
862
|
};
|
|
790
863
|
|
|
864
|
+
// src/resources/audio.ts
|
|
865
|
+
var BASE3 = "/v1/audio";
|
|
866
|
+
function bytesToBase64(bytes) {
|
|
867
|
+
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
868
|
+
let bin = "";
|
|
869
|
+
const CHUNK = 32768;
|
|
870
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
871
|
+
bin += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
872
|
+
}
|
|
873
|
+
return btoa(bin);
|
|
874
|
+
}
|
|
875
|
+
async function toBase64(audio) {
|
|
876
|
+
if (typeof audio === "string") {
|
|
877
|
+
const { readFile } = await import('fs/promises');
|
|
878
|
+
return bytesToBase64(new Uint8Array(await readFile(audio)));
|
|
879
|
+
}
|
|
880
|
+
if (typeof audio === "object" && audio !== null && "base64" in audio) {
|
|
881
|
+
if (!audio.base64 || !audio.base64.trim()) throw new ParetaError("audio.base64 is empty");
|
|
882
|
+
return audio.base64;
|
|
883
|
+
}
|
|
884
|
+
if (audio instanceof Blob) return bytesToBase64(new Uint8Array(await audio.arrayBuffer()));
|
|
885
|
+
const bytes = audio instanceof Uint8Array ? audio : new Uint8Array(audio);
|
|
886
|
+
if (bytes.byteLength === 0) throw new ParetaError("audio is empty");
|
|
887
|
+
return bytesToBase64(bytes);
|
|
888
|
+
}
|
|
889
|
+
var Audio = class {
|
|
890
|
+
constructor(client) {
|
|
891
|
+
this.client = client;
|
|
892
|
+
}
|
|
893
|
+
client;
|
|
894
|
+
/** Speech-to-text (the `asr` lane). `audio` is a file path, raw bytes, a
|
|
895
|
+
* Blob, or `{ base64 }`. Metered per minute of input audio. */
|
|
896
|
+
async transcriptions(audio, opts = {}) {
|
|
897
|
+
const body = { audio_base64: await toBase64(audio) };
|
|
898
|
+
if (opts.language) body.language = opts.language;
|
|
899
|
+
return this.client.request("POST", `${BASE3}/transcriptions`, {
|
|
900
|
+
body,
|
|
901
|
+
cast: (raw) => new Transcription(raw)
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
/** Text-to-speech (the `tts` lane). Returns a `Speech` whose `.audio` is
|
|
905
|
+
* decoded bytes (`.save(path)` writes a file in Node). Metered per minute
|
|
906
|
+
* of output audio. */
|
|
907
|
+
speech(text, opts = {}) {
|
|
908
|
+
if (!text || !text.trim()) throw new ParetaError("text is required");
|
|
909
|
+
const body = { text };
|
|
910
|
+
if (opts.voice) body.voice = opts.voice;
|
|
911
|
+
return this.client.request("POST", `${BASE3}/speech`, {
|
|
912
|
+
body,
|
|
913
|
+
cast: (raw) => new Speech(raw)
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
// src/resources/images.ts
|
|
919
|
+
var PATH3 = "/v1/images/generations";
|
|
920
|
+
var Images = class {
|
|
921
|
+
constructor(client) {
|
|
922
|
+
this.client = client;
|
|
923
|
+
}
|
|
924
|
+
client;
|
|
925
|
+
/** Generate one image from a text prompt. Returns an `ImageGeneration`
|
|
926
|
+
* whose `.image` is decoded PNG bytes (`.save(path)` writes a file in
|
|
927
|
+
* Node). Billed flat per image. */
|
|
928
|
+
generate(prompt, opts = {}) {
|
|
929
|
+
if (!prompt || !prompt.trim()) throw new ParetaError("prompt is required");
|
|
930
|
+
const body = { prompt };
|
|
931
|
+
if (opts.size) body.size = opts.size;
|
|
932
|
+
if (opts.seed !== void 0) body.seed = opts.seed;
|
|
933
|
+
return this.client.request("POST", PATH3, {
|
|
934
|
+
body,
|
|
935
|
+
cast: (raw) => new ImageGeneration(raw)
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
|
|
791
940
|
// src/resources/retrieval.ts
|
|
792
941
|
function makeRerank(client) {
|
|
793
942
|
return (query, documents, opts = {}) => {
|
|
@@ -848,10 +997,14 @@ var Pareta = class _Pareta {
|
|
|
848
997
|
tasks;
|
|
849
998
|
evals;
|
|
850
999
|
auto;
|
|
1000
|
+
/** The Speech lanes — `pa.audio.transcriptions(...)` (ASR) + `pa.audio.speech(...)` (TTS). */
|
|
1001
|
+
audio;
|
|
851
1002
|
/** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
|
|
852
1003
|
rerank;
|
|
853
1004
|
/** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
|
|
854
1005
|
embeddings;
|
|
1006
|
+
/** Image generation — `pa.images.generate(prompt, {size, seed})`, flat price per image. */
|
|
1007
|
+
images;
|
|
855
1008
|
constructor(options = {}) {
|
|
856
1009
|
if (!options.apiKey) {
|
|
857
1010
|
throw new ParetaError(
|
|
@@ -872,8 +1025,10 @@ var Pareta = class _Pareta {
|
|
|
872
1025
|
this.tasks = new Tasks(this);
|
|
873
1026
|
this.evals = new Evals(this);
|
|
874
1027
|
this.auto = new Auto(this);
|
|
1028
|
+
this.audio = new Audio(this);
|
|
875
1029
|
this.rerank = makeRerank(this);
|
|
876
1030
|
this.embeddings = makeEmbeddings(this);
|
|
1031
|
+
this.images = new Images(this);
|
|
877
1032
|
}
|
|
878
1033
|
/** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
|
|
879
1034
|
static fromEnv(options = {}) {
|
|
@@ -1057,6 +1212,7 @@ var Pareta = class _Pareta {
|
|
|
1057
1212
|
exports.APIConnectionError = APIConnectionError;
|
|
1058
1213
|
exports.APIStatusError = APIStatusError;
|
|
1059
1214
|
exports.APITimeoutError = APITimeoutError;
|
|
1215
|
+
exports.Audio = Audio;
|
|
1060
1216
|
exports.AuthenticationError = AuthenticationError;
|
|
1061
1217
|
exports.BadRequestError = BadRequestError;
|
|
1062
1218
|
exports.BaseModel = BaseModel;
|
|
@@ -1073,6 +1229,8 @@ exports.EvalRuns = EvalRuns;
|
|
|
1073
1229
|
exports.EvalSet = EvalSet;
|
|
1074
1230
|
exports.EvalSets = EvalSets;
|
|
1075
1231
|
exports.FrontierModel = FrontierModel;
|
|
1232
|
+
exports.ImageGeneration = ImageGeneration;
|
|
1233
|
+
exports.Images = Images;
|
|
1076
1234
|
exports.InsufficientCreditsError = InsufficientCreditsError;
|
|
1077
1235
|
exports.Message = Message;
|
|
1078
1236
|
exports.Model = Model;
|
|
@@ -1084,9 +1242,11 @@ exports.PermissionDeniedError = PermissionDeniedError;
|
|
|
1084
1242
|
exports.RateLimitError = RateLimitError;
|
|
1085
1243
|
exports.Rerank = Rerank;
|
|
1086
1244
|
exports.RerankResult = RerankResult;
|
|
1245
|
+
exports.Speech = Speech;
|
|
1087
1246
|
exports.Task = Task;
|
|
1088
1247
|
exports.TaskMatch = TaskMatch;
|
|
1089
1248
|
exports.TaskMatchCandidate = TaskMatchCandidate;
|
|
1249
|
+
exports.Transcription = Transcription;
|
|
1090
1250
|
exports.Usage = Usage;
|
|
1091
1251
|
exports.VERSION = VERSION;
|
|
1092
1252
|
//# sourceMappingURL=index.cjs.map
|