pareta 1.0.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 +191 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +122 -2
- package/dist/index.d.ts +122 -2
- package/dist/index.mjs +186 -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;
|
|
@@ -445,6 +445,94 @@ var EvalRun = class extends BaseModel {
|
|
|
445
445
|
return (this.raw.results ?? []).map((r) => new EvalResult(r));
|
|
446
446
|
}
|
|
447
447
|
};
|
|
448
|
+
var RerankResult = class extends BaseModel {
|
|
449
|
+
/** Position of this document in YOUR request's documents array. */
|
|
450
|
+
get index() {
|
|
451
|
+
return Number(this.raw.index ?? -1);
|
|
452
|
+
}
|
|
453
|
+
/** Calibrated P(relevant) in (0, 1) — thresholdable, not just ordinal. */
|
|
454
|
+
get relevanceScore() {
|
|
455
|
+
return Number(this.raw.relevance_score ?? 0);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
var Rerank = class extends BaseModel {
|
|
459
|
+
get results() {
|
|
460
|
+
return (this.raw.results ?? []).map((r) => new RerankResult(r));
|
|
461
|
+
}
|
|
462
|
+
get model() {
|
|
463
|
+
return this.raw.model ?? null;
|
|
464
|
+
}
|
|
465
|
+
get pairs() {
|
|
466
|
+
return this.raw.pairs ?? null;
|
|
467
|
+
}
|
|
468
|
+
/** Map the ranked indices back onto the documents you sent — best first. */
|
|
469
|
+
topDocuments(documents) {
|
|
470
|
+
return this.results.filter((r) => r.index >= 0 && r.index < documents.length).map((r) => documents[r.index]);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
var Embeddings = class extends BaseModel {
|
|
474
|
+
get vectors() {
|
|
475
|
+
const rows = [...this.raw.data ?? []];
|
|
476
|
+
rows.sort((a, b) => Number(a.index ?? 0) - Number(b.index ?? 0));
|
|
477
|
+
return rows.map((r) => r.embedding ?? []);
|
|
478
|
+
}
|
|
479
|
+
get model() {
|
|
480
|
+
return this.raw.model ?? null;
|
|
481
|
+
}
|
|
482
|
+
get promptTokens() {
|
|
483
|
+
return this.raw.usage?.prompt_tokens ?? null;
|
|
484
|
+
}
|
|
485
|
+
get length() {
|
|
486
|
+
return (this.raw.data ?? []).length;
|
|
487
|
+
}
|
|
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
|
+
};
|
|
448
536
|
|
|
449
537
|
// src/resources/chat.ts
|
|
450
538
|
var PATH = "/v1/chat/completions";
|
|
@@ -747,6 +835,93 @@ var Auto = class {
|
|
|
747
835
|
}
|
|
748
836
|
};
|
|
749
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
|
+
|
|
892
|
+
// src/resources/retrieval.ts
|
|
893
|
+
function makeRerank(client) {
|
|
894
|
+
return (query, documents, opts = {}) => {
|
|
895
|
+
if (!query || !query.trim()) throw new ParetaError("query is required");
|
|
896
|
+
if (!Array.isArray(documents) || documents.length === 0) {
|
|
897
|
+
throw new ParetaError("documents must be a non-empty array of strings");
|
|
898
|
+
}
|
|
899
|
+
const body = { query, documents };
|
|
900
|
+
if (opts.topN !== void 0) body.top_n = opts.topN;
|
|
901
|
+
return client.request("POST", "/v1/rerank", {
|
|
902
|
+
body,
|
|
903
|
+
cast: (raw) => new Rerank(raw)
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
function makeEmbeddings(client) {
|
|
908
|
+
return (input, opts = {}) => {
|
|
909
|
+
const texts = typeof input === "string" ? [input] : input;
|
|
910
|
+
if (!Array.isArray(texts) || texts.length === 0 || texts.some((t) => typeof t !== "string" || !t.trim())) {
|
|
911
|
+
throw new ParetaError("input must be a non-empty string or array of non-empty strings");
|
|
912
|
+
}
|
|
913
|
+
if (opts.inputType !== void 0 && opts.inputType !== "query" && opts.inputType !== "document") {
|
|
914
|
+
throw new ParetaError('inputType must be "query" or "document"');
|
|
915
|
+
}
|
|
916
|
+
const body = { input: texts };
|
|
917
|
+
if (opts.inputType !== void 0) body.input_type = opts.inputType;
|
|
918
|
+
return client.request("POST", "/v1/embeddings", {
|
|
919
|
+
body,
|
|
920
|
+
cast: (raw) => new Embeddings(raw)
|
|
921
|
+
});
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
|
|
750
925
|
// src/client.ts
|
|
751
926
|
var DEFAULT_BASE_URL = "https://api.pareta.ai";
|
|
752
927
|
function randomKey() {
|
|
@@ -774,6 +949,12 @@ var Pareta = class _Pareta {
|
|
|
774
949
|
tasks;
|
|
775
950
|
evals;
|
|
776
951
|
auto;
|
|
952
|
+
/** The Speech lanes — `pa.audio.transcriptions(...)` (ASR) + `pa.audio.speech(...)` (TTS). */
|
|
953
|
+
audio;
|
|
954
|
+
/** Document reranking (the Retrieval precision lane) — `pa.rerank(query, docs, {topN})`. */
|
|
955
|
+
rerank;
|
|
956
|
+
/** Text embeddings (the Retrieval recall lane) — `pa.embeddings(input, {inputType})`. */
|
|
957
|
+
embeddings;
|
|
777
958
|
constructor(options = {}) {
|
|
778
959
|
if (!options.apiKey) {
|
|
779
960
|
throw new ParetaError(
|
|
@@ -794,6 +975,9 @@ var Pareta = class _Pareta {
|
|
|
794
975
|
this.tasks = new Tasks(this);
|
|
795
976
|
this.evals = new Evals(this);
|
|
796
977
|
this.auto = new Auto(this);
|
|
978
|
+
this.audio = new Audio(this);
|
|
979
|
+
this.rerank = makeRerank(this);
|
|
980
|
+
this.embeddings = makeEmbeddings(this);
|
|
797
981
|
}
|
|
798
982
|
/** Build from PARETA_API_KEY (+ optional PARETA_BASE_URL); explicit opts win. */
|
|
799
983
|
static fromEnv(options = {}) {
|
|
@@ -977,6 +1161,7 @@ var Pareta = class _Pareta {
|
|
|
977
1161
|
exports.APIConnectionError = APIConnectionError;
|
|
978
1162
|
exports.APIStatusError = APIStatusError;
|
|
979
1163
|
exports.APITimeoutError = APITimeoutError;
|
|
1164
|
+
exports.Audio = Audio;
|
|
980
1165
|
exports.AuthenticationError = AuthenticationError;
|
|
981
1166
|
exports.BadRequestError = BadRequestError;
|
|
982
1167
|
exports.BaseModel = BaseModel;
|
|
@@ -984,6 +1169,7 @@ exports.ChatCompletion = ChatCompletion;
|
|
|
984
1169
|
exports.ChatCompletionChunk = ChatCompletionChunk;
|
|
985
1170
|
exports.Choice = Choice;
|
|
986
1171
|
exports.ConflictError = ConflictError;
|
|
1172
|
+
exports.Embeddings = Embeddings;
|
|
987
1173
|
exports.EndpointNotReadyError = EndpointNotReadyError;
|
|
988
1174
|
exports.EvalItemResult = EvalItemResult;
|
|
989
1175
|
exports.EvalResult = EvalResult;
|
|
@@ -1001,9 +1187,13 @@ exports.Pareta = Pareta;
|
|
|
1001
1187
|
exports.ParetaError = ParetaError;
|
|
1002
1188
|
exports.PermissionDeniedError = PermissionDeniedError;
|
|
1003
1189
|
exports.RateLimitError = RateLimitError;
|
|
1190
|
+
exports.Rerank = Rerank;
|
|
1191
|
+
exports.RerankResult = RerankResult;
|
|
1192
|
+
exports.Speech = Speech;
|
|
1004
1193
|
exports.Task = Task;
|
|
1005
1194
|
exports.TaskMatch = TaskMatch;
|
|
1006
1195
|
exports.TaskMatchCandidate = TaskMatchCandidate;
|
|
1196
|
+
exports.Transcription = Transcription;
|
|
1007
1197
|
exports.Usage = Usage;
|
|
1008
1198
|
exports.VERSION = VERSION;
|
|
1009
1199
|
//# sourceMappingURL=index.cjs.map
|