pareta 1.1.0 → 1.2.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 +108 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -2
- package/dist/index.d.ts +66 -2
- package/dist/index.mjs +106 -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.2.0";
|
|
178
178
|
|
|
179
179
|
// src/money.ts
|
|
180
180
|
var MICRO_PER_CENT = 10000n;
|
|
@@ -486,6 +486,53 @@ 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
|
+
};
|
|
489
536
|
|
|
490
537
|
// src/resources/chat.ts
|
|
491
538
|
var PATH = "/v1/chat/completions";
|
|
@@ -788,6 +835,60 @@ var Auto = class {
|
|
|
788
835
|
}
|
|
789
836
|
};
|
|
790
837
|
|
|
838
|
+
// src/resources/audio.ts
|
|
839
|
+
var BASE3 = "/v1/audio";
|
|
840
|
+
function bytesToBase64(bytes) {
|
|
841
|
+
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
842
|
+
let bin = "";
|
|
843
|
+
const CHUNK = 32768;
|
|
844
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
845
|
+
bin += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
846
|
+
}
|
|
847
|
+
return btoa(bin);
|
|
848
|
+
}
|
|
849
|
+
async function toBase64(audio) {
|
|
850
|
+
if (typeof audio === "string") {
|
|
851
|
+
const { readFile } = await import('fs/promises');
|
|
852
|
+
return bytesToBase64(new Uint8Array(await readFile(audio)));
|
|
853
|
+
}
|
|
854
|
+
if (typeof audio === "object" && audio !== null && "base64" in audio) {
|
|
855
|
+
if (!audio.base64 || !audio.base64.trim()) throw new ParetaError("audio.base64 is empty");
|
|
856
|
+
return audio.base64;
|
|
857
|
+
}
|
|
858
|
+
if (audio instanceof Blob) return bytesToBase64(new Uint8Array(await audio.arrayBuffer()));
|
|
859
|
+
const bytes = audio instanceof Uint8Array ? audio : new Uint8Array(audio);
|
|
860
|
+
if (bytes.byteLength === 0) throw new ParetaError("audio is empty");
|
|
861
|
+
return bytesToBase64(bytes);
|
|
862
|
+
}
|
|
863
|
+
var Audio = class {
|
|
864
|
+
constructor(client) {
|
|
865
|
+
this.client = client;
|
|
866
|
+
}
|
|
867
|
+
client;
|
|
868
|
+
/** Speech-to-text (the `asr` lane). `audio` is a file path, raw bytes, a
|
|
869
|
+
* Blob, or `{ base64 }`. Metered per minute of input audio. */
|
|
870
|
+
async transcriptions(audio, opts = {}) {
|
|
871
|
+
const body = { audio_base64: await toBase64(audio) };
|
|
872
|
+
if (opts.language) body.language = opts.language;
|
|
873
|
+
return this.client.request("POST", `${BASE3}/transcriptions`, {
|
|
874
|
+
body,
|
|
875
|
+
cast: (raw) => new Transcription(raw)
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
/** Text-to-speech (the `tts` lane). Returns a `Speech` whose `.audio` is
|
|
879
|
+
* decoded bytes (`.save(path)` writes a file in Node). Metered per minute
|
|
880
|
+
* of output audio. */
|
|
881
|
+
speech(text, opts = {}) {
|
|
882
|
+
if (!text || !text.trim()) throw new ParetaError("text is required");
|
|
883
|
+
const body = { text };
|
|
884
|
+
if (opts.voice) body.voice = opts.voice;
|
|
885
|
+
return this.client.request("POST", `${BASE3}/speech`, {
|
|
886
|
+
body,
|
|
887
|
+
cast: (raw) => new Speech(raw)
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
|
|
791
892
|
// src/resources/retrieval.ts
|
|
792
893
|
function makeRerank(client) {
|
|
793
894
|
return (query, documents, opts = {}) => {
|
|
@@ -848,6 +949,8 @@ var Pareta = class _Pareta {
|
|
|
848
949
|
tasks;
|
|
849
950
|
evals;
|
|
850
951
|
auto;
|
|
952
|
+
/** The Speech lanes — `pa.audio.transcriptions(...)` (ASR) + `pa.audio.speech(...)` (TTS). */
|
|
953
|
+
audio;
|
|
851
954
|
/** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
|
|
852
955
|
rerank;
|
|
853
956
|
/** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
|
|
@@ -872,6 +975,7 @@ var Pareta = class _Pareta {
|
|
|
872
975
|
this.tasks = new Tasks(this);
|
|
873
976
|
this.evals = new Evals(this);
|
|
874
977
|
this.auto = new Auto(this);
|
|
978
|
+
this.audio = new Audio(this);
|
|
875
979
|
this.rerank = makeRerank(this);
|
|
876
980
|
this.embeddings = makeEmbeddings(this);
|
|
877
981
|
}
|
|
@@ -1057,6 +1161,7 @@ var Pareta = class _Pareta {
|
|
|
1057
1161
|
exports.APIConnectionError = APIConnectionError;
|
|
1058
1162
|
exports.APIStatusError = APIStatusError;
|
|
1059
1163
|
exports.APITimeoutError = APITimeoutError;
|
|
1164
|
+
exports.Audio = Audio;
|
|
1060
1165
|
exports.AuthenticationError = AuthenticationError;
|
|
1061
1166
|
exports.BadRequestError = BadRequestError;
|
|
1062
1167
|
exports.BaseModel = BaseModel;
|
|
@@ -1084,9 +1189,11 @@ exports.PermissionDeniedError = PermissionDeniedError;
|
|
|
1084
1189
|
exports.RateLimitError = RateLimitError;
|
|
1085
1190
|
exports.Rerank = Rerank;
|
|
1086
1191
|
exports.RerankResult = RerankResult;
|
|
1192
|
+
exports.Speech = Speech;
|
|
1087
1193
|
exports.Task = Task;
|
|
1088
1194
|
exports.TaskMatch = TaskMatch;
|
|
1089
1195
|
exports.TaskMatchCandidate = TaskMatchCandidate;
|
|
1196
|
+
exports.Transcription = Transcription;
|
|
1090
1197
|
exports.Usage = Usage;
|
|
1091
1198
|
exports.VERSION = VERSION;
|
|
1092
1199
|
//# sourceMappingURL=index.cjs.map
|