opik 1.9.49 → 1.9.51
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 +27 -27
- package/dist/index.d.cts +409 -394
- package/dist/index.d.ts +409 -394
- package/dist/index.js +25 -25
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -10324,6 +10324,307 @@ interface ConstructorOpikConfig extends OpikConfig {
|
|
|
10324
10324
|
headers?: Record<string, string>;
|
|
10325
10325
|
}
|
|
10326
10326
|
|
|
10327
|
+
/**
|
|
10328
|
+
* Supported template engine types for prompts
|
|
10329
|
+
* Re-exported from REST API with uppercase values for consistency
|
|
10330
|
+
*/
|
|
10331
|
+
declare const PromptType: {
|
|
10332
|
+
/** Mustache template syntax with {{variable}} placeholders */
|
|
10333
|
+
readonly MUSTACHE: "mustache";
|
|
10334
|
+
/** Jinja2 template syntax with {% %} blocks and {{ }} variables */
|
|
10335
|
+
readonly JINJA2: "jinja2";
|
|
10336
|
+
};
|
|
10337
|
+
type PromptType = (typeof PromptType)[keyof typeof PromptType];
|
|
10338
|
+
/**
|
|
10339
|
+
* Configuration options for creating a new prompt
|
|
10340
|
+
* Extends REST API PromptWrite with renamed 'prompt' field
|
|
10341
|
+
*/
|
|
10342
|
+
interface CreatePromptOptions {
|
|
10343
|
+
/** Name of the prompt (unique identifier) */
|
|
10344
|
+
name: string;
|
|
10345
|
+
/** Template text content with placeholders */
|
|
10346
|
+
prompt: string;
|
|
10347
|
+
/** Optional prompt ID (generated if not provided) */
|
|
10348
|
+
promptId?: string;
|
|
10349
|
+
/** Optional description for the prompt */
|
|
10350
|
+
description?: string;
|
|
10351
|
+
/** Optional metadata for tracking and filtering */
|
|
10352
|
+
metadata?: JsonNodeWrite;
|
|
10353
|
+
/** Optional change description for version tracking */
|
|
10354
|
+
changeDescription?: string;
|
|
10355
|
+
/** Template engine type, defaults to mustache */
|
|
10356
|
+
type?: PromptType;
|
|
10357
|
+
/** Optional tags for categorization */
|
|
10358
|
+
tags?: string[];
|
|
10359
|
+
}
|
|
10360
|
+
/**
|
|
10361
|
+
* Options for retrieving a specific prompt version
|
|
10362
|
+
* Re-exported from REST API PromptVersionRetrieveDetail
|
|
10363
|
+
*/
|
|
10364
|
+
type GetPromptOptions = PromptVersionRetrieveDetail;
|
|
10365
|
+
/**
|
|
10366
|
+
* Variables to be substituted into prompt template.
|
|
10367
|
+
*/
|
|
10368
|
+
type PromptVariables = Record<string, unknown>;
|
|
10369
|
+
/**
|
|
10370
|
+
* Data structure for creating a PromptVersion instance
|
|
10371
|
+
*/
|
|
10372
|
+
interface PromptVersionData {
|
|
10373
|
+
name: string;
|
|
10374
|
+
prompt: string;
|
|
10375
|
+
commit: string;
|
|
10376
|
+
promptId: string;
|
|
10377
|
+
versionId: string;
|
|
10378
|
+
type: PromptType;
|
|
10379
|
+
metadata?: JsonNode;
|
|
10380
|
+
changeDescription?: string;
|
|
10381
|
+
createdAt?: Date;
|
|
10382
|
+
createdBy?: string;
|
|
10383
|
+
}
|
|
10384
|
+
|
|
10385
|
+
/**
|
|
10386
|
+
* Represents a specific immutable snapshot of a prompt template at a point in time.
|
|
10387
|
+
* Pure data object with formatting capabilities.
|
|
10388
|
+
*/
|
|
10389
|
+
declare class PromptVersion {
|
|
10390
|
+
readonly id: string;
|
|
10391
|
+
readonly name: string;
|
|
10392
|
+
readonly prompt: string;
|
|
10393
|
+
readonly commit: string;
|
|
10394
|
+
readonly type: PromptType;
|
|
10395
|
+
readonly metadata?: JsonNode;
|
|
10396
|
+
readonly changeDescription?: string;
|
|
10397
|
+
readonly createdAt?: Date;
|
|
10398
|
+
readonly createdBy?: string;
|
|
10399
|
+
constructor(data: PromptVersionData);
|
|
10400
|
+
/**
|
|
10401
|
+
* Format the prompt template with the provided variables
|
|
10402
|
+
*/
|
|
10403
|
+
format(variables: PromptVariables): string;
|
|
10404
|
+
/**
|
|
10405
|
+
* Get human-readable version age (e.g., "2 days ago", "Today")
|
|
10406
|
+
*/
|
|
10407
|
+
getVersionAge(): string;
|
|
10408
|
+
/**
|
|
10409
|
+
* Get formatted version information string
|
|
10410
|
+
* Format: "[commitHash] YYYY-MM-DD by user@email.com - Change description"
|
|
10411
|
+
*/
|
|
10412
|
+
getVersionInfo(): string;
|
|
10413
|
+
/**
|
|
10414
|
+
* Compare this version's template with another version and return a formatted diff.
|
|
10415
|
+
* Displays a git-style unified diff showing additions, deletions, and changes.
|
|
10416
|
+
* The diff is automatically logged to the terminal and also returned as a string.
|
|
10417
|
+
* The output is colored and formatted for terminal display.
|
|
10418
|
+
*
|
|
10419
|
+
* @param other - The version to compare against
|
|
10420
|
+
* @returns A formatted string showing the differences between versions
|
|
10421
|
+
*
|
|
10422
|
+
* @example
|
|
10423
|
+
* ```typescript
|
|
10424
|
+
* const currentVersion = await prompt.getVersion("commit123");
|
|
10425
|
+
* const previousVersion = await prompt.getVersion("commit456");
|
|
10426
|
+
*
|
|
10427
|
+
* // Logs diff to terminal and returns it
|
|
10428
|
+
* const diff = currentVersion.compareTo(previousVersion);
|
|
10429
|
+
* ```
|
|
10430
|
+
*/
|
|
10431
|
+
compareTo(other: PromptVersion): string;
|
|
10432
|
+
/**
|
|
10433
|
+
* Factory method to create PromptVersion from API response
|
|
10434
|
+
*/
|
|
10435
|
+
static fromApiResponse(name: string, apiResponse: PromptVersionDetail): PromptVersion;
|
|
10436
|
+
}
|
|
10437
|
+
|
|
10438
|
+
interface PromptData {
|
|
10439
|
+
promptId: string;
|
|
10440
|
+
versionId: string;
|
|
10441
|
+
name: string;
|
|
10442
|
+
prompt: string;
|
|
10443
|
+
commit?: string;
|
|
10444
|
+
metadata?: JsonNode;
|
|
10445
|
+
type?: PromptType;
|
|
10446
|
+
changeDescription?: string;
|
|
10447
|
+
description?: string;
|
|
10448
|
+
tags?: string[];
|
|
10449
|
+
}
|
|
10450
|
+
/**
|
|
10451
|
+
* Domain object representing a versioned prompt template.
|
|
10452
|
+
* Provides immutable access to prompt properties and template formatting.
|
|
10453
|
+
* Integrates with backend for persistence and version management.
|
|
10454
|
+
*/
|
|
10455
|
+
declare class Prompt {
|
|
10456
|
+
private opik;
|
|
10457
|
+
readonly id: string;
|
|
10458
|
+
readonly versionId: string;
|
|
10459
|
+
readonly prompt: string;
|
|
10460
|
+
readonly commit: string | undefined;
|
|
10461
|
+
readonly type: PromptType;
|
|
10462
|
+
readonly changeDescription: string | undefined;
|
|
10463
|
+
private _name;
|
|
10464
|
+
private _description;
|
|
10465
|
+
private _tags;
|
|
10466
|
+
private readonly _metadata;
|
|
10467
|
+
/**
|
|
10468
|
+
* Creates a new Prompt instance.
|
|
10469
|
+
* This should not be created directly, use OpikClient.createPrompt() instead.
|
|
10470
|
+
*/
|
|
10471
|
+
constructor({ promptId, versionId, name, prompt, commit, metadata, type, changeDescription, description, tags, }: PromptData, opik: OpikClient);
|
|
10472
|
+
get name(): string;
|
|
10473
|
+
get description(): string | undefined;
|
|
10474
|
+
get tags(): readonly string[] | undefined;
|
|
10475
|
+
/**
|
|
10476
|
+
* Read-only metadata property.
|
|
10477
|
+
* Returns deep copy to prevent external mutation.
|
|
10478
|
+
*/
|
|
10479
|
+
get metadata(): JsonNode | undefined;
|
|
10480
|
+
/**
|
|
10481
|
+
* Formats prompt template by substituting variables.
|
|
10482
|
+
* Validates that all template placeholders are provided (for Mustache templates).
|
|
10483
|
+
*
|
|
10484
|
+
* @param variables - Object with values to substitute into template
|
|
10485
|
+
* @returns Formatted prompt text with variables substituted
|
|
10486
|
+
* @throws PromptValidationError if template processing or validation fails
|
|
10487
|
+
*
|
|
10488
|
+
* @example
|
|
10489
|
+
* ```typescript
|
|
10490
|
+
* const prompt = new Prompt({
|
|
10491
|
+
* name: "greeting",
|
|
10492
|
+
* prompt: "Hello {{name}}, your score is {{score}}",
|
|
10493
|
+
* type: "mustache"
|
|
10494
|
+
* }, client);
|
|
10495
|
+
*
|
|
10496
|
+
* // Valid - all placeholders provided
|
|
10497
|
+
* prompt.format({ name: "Alice", score: 95 });
|
|
10498
|
+
* // Returns: "Hello Alice, your score is 95"
|
|
10499
|
+
*
|
|
10500
|
+
* // Invalid - missing 'score' placeholder
|
|
10501
|
+
* prompt.format({ name: "Alice" });
|
|
10502
|
+
* // Throws: PromptValidationError
|
|
10503
|
+
* ```
|
|
10504
|
+
*/
|
|
10505
|
+
format(variables: PromptVariables): string;
|
|
10506
|
+
/**
|
|
10507
|
+
* Static factory method to create Prompt from backend API response.
|
|
10508
|
+
*
|
|
10509
|
+
* @param name - Name of the prompt
|
|
10510
|
+
* @param apiResponse - REST API PromptVersionDetail response
|
|
10511
|
+
* @param opik - OpikClient instance
|
|
10512
|
+
* @param promptPublicData - Optional PromptPublic data containing description and tags
|
|
10513
|
+
* @returns Prompt instance constructed from response data
|
|
10514
|
+
* @throws PromptValidationError if response structure invalid
|
|
10515
|
+
*/
|
|
10516
|
+
static fromApiResponse(promptData: PromptPublic, apiResponse: PromptVersionDetail, opik: OpikClient): Prompt;
|
|
10517
|
+
/**
|
|
10518
|
+
* Updates prompt properties (name, description, and/or tags).
|
|
10519
|
+
* Performs immediate update (no batching).
|
|
10520
|
+
*
|
|
10521
|
+
* @param updates - Partial updates with optional name, description, and tags
|
|
10522
|
+
* @returns Promise resolving to this Prompt instance for method chaining
|
|
10523
|
+
*
|
|
10524
|
+
* @example
|
|
10525
|
+
* ```typescript
|
|
10526
|
+
* const prompt = await client.getPrompt({ name: "my-prompt" });
|
|
10527
|
+
* await prompt.updateProperties({
|
|
10528
|
+
* name: "renamed-prompt",
|
|
10529
|
+
* description: "Updated description",
|
|
10530
|
+
* tags: ["tag1", "tag2"]
|
|
10531
|
+
* });
|
|
10532
|
+
* ```
|
|
10533
|
+
*/
|
|
10534
|
+
updateProperties(updates: {
|
|
10535
|
+
name?: string;
|
|
10536
|
+
description?: string;
|
|
10537
|
+
tags?: string[];
|
|
10538
|
+
}): Promise<this>;
|
|
10539
|
+
/**
|
|
10540
|
+
* Deletes this prompt from the backend.
|
|
10541
|
+
* Performs immediate deletion (no batching).
|
|
10542
|
+
*/
|
|
10543
|
+
delete(): Promise<void>;
|
|
10544
|
+
/**
|
|
10545
|
+
* Retrieves all version history for this prompt.
|
|
10546
|
+
* Fetches and returns complete version history, sorted by creation date (newest first).
|
|
10547
|
+
* Automatically handles pagination to fetch all versions.
|
|
10548
|
+
*
|
|
10549
|
+
* @returns Promise resolving to array of all PromptVersion instances for this prompt
|
|
10550
|
+
* @throws OpikApiError if REST API call fails
|
|
10551
|
+
*
|
|
10552
|
+
* @example
|
|
10553
|
+
* ```typescript
|
|
10554
|
+
* const prompt = await client.getPrompt({ name: "my-prompt" });
|
|
10555
|
+
* const versions = await prompt.getVersions();
|
|
10556
|
+
*
|
|
10557
|
+
* console.log(`Found ${versions.length} versions`);
|
|
10558
|
+
* versions.forEach(v => {
|
|
10559
|
+
* console.log(`Commit: ${v.commit}, Age: ${v.getVersionAge()}`);
|
|
10560
|
+
* });
|
|
10561
|
+
* ```
|
|
10562
|
+
*/
|
|
10563
|
+
getVersions(): Promise<PromptVersion[]>;
|
|
10564
|
+
/**
|
|
10565
|
+
* Restores a specific version by creating a new version with content from the specified version.
|
|
10566
|
+
* The version must be obtained from the backend (e.g., via getVersions()).
|
|
10567
|
+
* Returns a new Prompt instance with the restored content as the latest version.
|
|
10568
|
+
*
|
|
10569
|
+
* @param version - PromptVersion object to restore (must be from backend)
|
|
10570
|
+
* @returns Promise resolving to a new Prompt instance with the restored version
|
|
10571
|
+
* @throws OpikApiError if REST API call fails
|
|
10572
|
+
*
|
|
10573
|
+
* @example
|
|
10574
|
+
* ```typescript
|
|
10575
|
+
* const prompt = await client.getPrompt({ name: "my-prompt" });
|
|
10576
|
+
*
|
|
10577
|
+
* // Get all versions
|
|
10578
|
+
* const versions = await prompt.getVersions();
|
|
10579
|
+
*
|
|
10580
|
+
* // Restore a specific version
|
|
10581
|
+
* const targetVersion = versions.find(v => v.commit === "abc123de");
|
|
10582
|
+
* if (targetVersion) {
|
|
10583
|
+
* const restoredPrompt = await prompt.useVersion(targetVersion);
|
|
10584
|
+
* console.log(`Restored to commit: ${restoredPrompt.commit}`);
|
|
10585
|
+
* console.log(`New template: ${restoredPrompt.prompt}`);
|
|
10586
|
+
*
|
|
10587
|
+
* // Continue using the restored prompt
|
|
10588
|
+
* const formatted = restoredPrompt.format({ name: "World" });
|
|
10589
|
+
* }
|
|
10590
|
+
* ```
|
|
10591
|
+
*/
|
|
10592
|
+
useVersion(version: PromptVersion): Promise<Prompt>;
|
|
10593
|
+
/**
|
|
10594
|
+
* Get a Prompt with a specific version by commit hash.
|
|
10595
|
+
*
|
|
10596
|
+
* @param commit - Commit hash (8-char short form or full)
|
|
10597
|
+
* @returns Prompt instance representing that version, or null if not found
|
|
10598
|
+
*
|
|
10599
|
+
* @example
|
|
10600
|
+
* ```typescript
|
|
10601
|
+
* const prompt = await client.getPrompt({ name: "greeting" });
|
|
10602
|
+
*
|
|
10603
|
+
* // Get a specific version directly as a Prompt
|
|
10604
|
+
* const versionedPrompt = await prompt.getVersion("abc123de");
|
|
10605
|
+
* if (versionedPrompt) {
|
|
10606
|
+
* const text = versionedPrompt.format({ name: "Alice" });
|
|
10607
|
+
* }
|
|
10608
|
+
* ```
|
|
10609
|
+
*/
|
|
10610
|
+
getVersion(commit: string): Promise<Prompt | null>;
|
|
10611
|
+
}
|
|
10612
|
+
|
|
10613
|
+
/**
|
|
10614
|
+
* Extended TraceUpdate type that includes prompts field.
|
|
10615
|
+
* Allows associating prompt versions with trace updates.
|
|
10616
|
+
*/
|
|
10617
|
+
interface TraceUpdateData extends Omit<TraceUpdate, "projectId"> {
|
|
10618
|
+
prompts?: Prompt[];
|
|
10619
|
+
}
|
|
10620
|
+
/**
|
|
10621
|
+
* Extended SpanUpdate type that includes prompts field.
|
|
10622
|
+
* Allows associating prompt versions with span updates.
|
|
10623
|
+
*/
|
|
10624
|
+
interface SpanUpdateData extends Omit<SpanUpdate$1, "traceId" | "parentSpanId" | "projectId" | "projectName"> {
|
|
10625
|
+
prompts?: Prompt[];
|
|
10626
|
+
}
|
|
10627
|
+
|
|
10327
10628
|
interface SavedSpan extends Span$1 {
|
|
10328
10629
|
id: string;
|
|
10329
10630
|
}
|
|
@@ -10339,7 +10640,7 @@ declare class Span {
|
|
|
10339
10640
|
value: number;
|
|
10340
10641
|
reason?: string;
|
|
10341
10642
|
}) => void;
|
|
10342
|
-
update: (updates:
|
|
10643
|
+
update: (updates: SpanUpdateData) => this;
|
|
10343
10644
|
span: (spanData: Omit<Span$1, "startTime" | "traceId" | "parentSpanId" | "projectId" | "projectName" | "id"> & {
|
|
10344
10645
|
startTime?: Date;
|
|
10345
10646
|
}) => Span;
|
|
@@ -10364,7 +10665,7 @@ declare class Trace {
|
|
|
10364
10665
|
reason?: string;
|
|
10365
10666
|
}) => void;
|
|
10366
10667
|
span: (spanData: SpanData) => Span;
|
|
10367
|
-
update: (updates:
|
|
10668
|
+
update: (updates: TraceUpdateData) => this;
|
|
10368
10669
|
}
|
|
10369
10670
|
|
|
10370
10671
|
interface BatchQueueOptions {
|
|
@@ -10487,433 +10788,147 @@ declare class DatasetBatchQueue extends BatchQueue<DatasetWrite> {
|
|
|
10487
10788
|
* @param datasets The array of datasets to create
|
|
10488
10789
|
*/
|
|
10489
10790
|
protected createEntities(datasets: DatasetWrite[]): Promise<void>;
|
|
10490
|
-
/**
|
|
10491
|
-
* Retrieves a dataset by its ID.
|
|
10492
|
-
*
|
|
10493
|
-
* @param id The ID of the dataset to retrieve
|
|
10494
|
-
* @returns The retrieved dataset or undefined if not found
|
|
10495
|
-
*/
|
|
10496
|
-
protected getEntity(id: string): Promise<DatasetPublic | undefined>;
|
|
10497
|
-
/**
|
|
10498
|
-
* Updates a dataset by its ID with the provided updates.
|
|
10499
|
-
*
|
|
10500
|
-
* @param id The ID of the dataset to update
|
|
10501
|
-
* @param updates Partial dataset properties to update
|
|
10502
|
-
*/
|
|
10503
|
-
protected updateEntity(id: string, updates: Partial<DatasetWrite>): Promise<void>;
|
|
10504
|
-
/**
|
|
10505
|
-
* Deletes multiple datasets by their IDs.
|
|
10506
|
-
*
|
|
10507
|
-
* @param ids Array of dataset IDs to delete
|
|
10508
|
-
*/
|
|
10509
|
-
protected deleteEntities(ids: string[]): Promise<void>;
|
|
10510
|
-
}
|
|
10511
|
-
|
|
10512
|
-
type DatasetItemData = JsonNode & {
|
|
10513
|
-
id?: string;
|
|
10514
|
-
};
|
|
10515
|
-
|
|
10516
|
-
interface DatasetData {
|
|
10517
|
-
name: string;
|
|
10518
|
-
description?: string;
|
|
10519
|
-
id?: string;
|
|
10520
|
-
}
|
|
10521
|
-
declare class Dataset<T extends DatasetItemData = DatasetItemData> {
|
|
10522
|
-
private opik;
|
|
10523
|
-
readonly id: string;
|
|
10524
|
-
readonly name: string;
|
|
10525
|
-
readonly description?: string;
|
|
10526
|
-
private idToHash;
|
|
10527
|
-
private hashes;
|
|
10528
|
-
/**
|
|
10529
|
-
* Configuration object for creating a new Dataset instance.
|
|
10530
|
-
* This should not be created directly, use static factory methods instead.
|
|
10531
|
-
*/
|
|
10532
|
-
constructor({ name, description, id }: DatasetData, opik: OpikClient);
|
|
10533
|
-
/**
|
|
10534
|
-
* Insert new items into the dataset.
|
|
10535
|
-
*
|
|
10536
|
-
* @param items List of objects to add to the dataset
|
|
10537
|
-
*/
|
|
10538
|
-
insert(items: T[]): Promise<void>;
|
|
10539
|
-
/**
|
|
10540
|
-
* Update existing items in the dataset.
|
|
10541
|
-
* You need to provide the full item object as it will override what has been supplied previously.
|
|
10542
|
-
*
|
|
10543
|
-
* @param items List of objects to update in the dataset
|
|
10544
|
-
*/
|
|
10545
|
-
update(items: T[]): Promise<void>;
|
|
10546
|
-
/**
|
|
10547
|
-
* Delete items from the dataset.
|
|
10548
|
-
*
|
|
10549
|
-
* @param itemIds List of item ids to delete
|
|
10550
|
-
*/
|
|
10551
|
-
delete(itemIds: string[]): Promise<void>;
|
|
10552
|
-
/**
|
|
10553
|
-
* Delete all items from the dataset.
|
|
10554
|
-
*/
|
|
10555
|
-
clear(): Promise<void>;
|
|
10556
|
-
/**
|
|
10557
|
-
* Retrieve a fixed number of dataset items.
|
|
10558
|
-
*
|
|
10559
|
-
* @param nbSamples The number of samples to retrieve. If not set - all items are returned
|
|
10560
|
-
* @param lastRetrievedId Optional ID of the last retrieved item for pagination
|
|
10561
|
-
* @returns A list of objects representing the dataset items
|
|
10562
|
-
*/
|
|
10563
|
-
getItems(nbSamples?: number, lastRetrievedId?: string): Promise<(T & {
|
|
10564
|
-
id: string;
|
|
10565
|
-
})[]>;
|
|
10566
|
-
private getItemsAsDataclasses;
|
|
10567
|
-
/**
|
|
10568
|
-
* Insert items from a JSON string array into the dataset.
|
|
10569
|
-
*
|
|
10570
|
-
* @param jsonArray JSON string of format: "[{...}, {...}, {...}]" where every object is transformed into a dataset item
|
|
10571
|
-
* @param keysMapping Optional dictionary that maps JSON keys to dataset item field names (e.g., {'Expected output': 'expected_output'})
|
|
10572
|
-
* @param ignoreKeys Optional array of keys that should be ignored when constructing dataset items
|
|
10573
|
-
*/
|
|
10574
|
-
insertFromJson(jsonArray: string, keysMapping?: Record<string, string>, ignoreKeys?: string[]): Promise<void>;
|
|
10575
|
-
/**
|
|
10576
|
-
* Convert the dataset to a JSON string.
|
|
10577
|
-
*
|
|
10578
|
-
* @param keysMapping Optional dictionary that maps dataset item field names to output JSON keys
|
|
10579
|
-
* @returns A JSON string representation of all items in the dataset
|
|
10580
|
-
*/
|
|
10581
|
-
toJson(keysMapping?: Record<string, string>): Promise<string>;
|
|
10582
|
-
/**
|
|
10583
|
-
* Retrieves all items from the dataset, deduplicates them, and returns them.
|
|
10584
|
-
*
|
|
10585
|
-
* @returns A list of deduplicated dataset items
|
|
10586
|
-
*/
|
|
10587
|
-
private getDeduplicatedItems;
|
|
10588
|
-
/**
|
|
10589
|
-
* Clears both hash tracking data structures
|
|
10590
|
-
*/
|
|
10591
|
-
private clearHashState;
|
|
10592
|
-
syncHashes(): Promise<void>;
|
|
10593
|
-
}
|
|
10594
|
-
|
|
10595
|
-
/**
|
|
10596
|
-
* References to a dataset item and trace in an experiment.
|
|
10597
|
-
*/
|
|
10598
|
-
declare class ExperimentItemReferences {
|
|
10599
|
-
readonly datasetItemId: string;
|
|
10600
|
-
readonly traceId: string;
|
|
10601
|
-
constructor(params: {
|
|
10602
|
-
datasetItemId: string;
|
|
10603
|
-
traceId: string;
|
|
10604
|
-
});
|
|
10605
|
-
}
|
|
10606
|
-
/**
|
|
10607
|
-
* Content of an experiment item including evaluation data and feedback scores.
|
|
10608
|
-
*/
|
|
10609
|
-
declare class ExperimentItemContent {
|
|
10610
|
-
readonly id?: string;
|
|
10611
|
-
readonly datasetItemId: string;
|
|
10612
|
-
readonly traceId: string;
|
|
10613
|
-
readonly datasetItemData?: JsonListStringCompare;
|
|
10614
|
-
readonly evaluationTaskOutput?: JsonListStringCompare;
|
|
10615
|
-
readonly feedbackScores: FeedbackScore[];
|
|
10616
|
-
constructor(params: {
|
|
10617
|
-
id?: string;
|
|
10618
|
-
datasetItemId: string;
|
|
10619
|
-
traceId: string;
|
|
10620
|
-
datasetItemData?: JsonListStringCompare;
|
|
10621
|
-
evaluationTaskOutput?: JsonListStringCompare;
|
|
10622
|
-
feedbackScores: FeedbackScore[];
|
|
10623
|
-
});
|
|
10624
|
-
/**
|
|
10625
|
-
* Creates an ExperimentItemContent from a REST API ExperimentItemCompare object.
|
|
10626
|
-
*
|
|
10627
|
-
* @param value The REST API ExperimentItemCompare object
|
|
10628
|
-
* @returns A new ExperimentItemContent instance
|
|
10629
|
-
*/
|
|
10630
|
-
static fromRestExperimentItemCompare(value: ExperimentItemCompare): ExperimentItemContent;
|
|
10631
|
-
}
|
|
10632
|
-
|
|
10633
|
-
/**
|
|
10634
|
-
* Supported template engine types for prompts
|
|
10635
|
-
* Re-exported from REST API with uppercase values for consistency
|
|
10636
|
-
*/
|
|
10637
|
-
declare const PromptType: {
|
|
10638
|
-
/** Mustache template syntax with {{variable}} placeholders */
|
|
10639
|
-
readonly MUSTACHE: "mustache";
|
|
10640
|
-
/** Jinja2 template syntax with {% %} blocks and {{ }} variables */
|
|
10641
|
-
readonly JINJA2: "jinja2";
|
|
10642
|
-
};
|
|
10643
|
-
type PromptType = (typeof PromptType)[keyof typeof PromptType];
|
|
10644
|
-
/**
|
|
10645
|
-
* Configuration options for creating a new prompt
|
|
10646
|
-
* Extends REST API PromptWrite with renamed 'prompt' field
|
|
10647
|
-
*/
|
|
10648
|
-
interface CreatePromptOptions {
|
|
10649
|
-
/** Name of the prompt (unique identifier) */
|
|
10650
|
-
name: string;
|
|
10651
|
-
/** Template text content with placeholders */
|
|
10652
|
-
prompt: string;
|
|
10653
|
-
/** Optional prompt ID (generated if not provided) */
|
|
10654
|
-
promptId?: string;
|
|
10655
|
-
/** Optional description for the prompt */
|
|
10656
|
-
description?: string;
|
|
10657
|
-
/** Optional metadata for tracking and filtering */
|
|
10658
|
-
metadata?: JsonNodeWrite;
|
|
10659
|
-
/** Optional change description for version tracking */
|
|
10660
|
-
changeDescription?: string;
|
|
10661
|
-
/** Template engine type, defaults to mustache */
|
|
10662
|
-
type?: PromptType;
|
|
10663
|
-
/** Optional tags for categorization */
|
|
10664
|
-
tags?: string[];
|
|
10665
|
-
}
|
|
10666
|
-
/**
|
|
10667
|
-
* Options for retrieving a specific prompt version
|
|
10668
|
-
* Re-exported from REST API PromptVersionRetrieveDetail
|
|
10669
|
-
*/
|
|
10670
|
-
type GetPromptOptions = PromptVersionRetrieveDetail;
|
|
10671
|
-
/**
|
|
10672
|
-
* Variables to be substituted into prompt template.
|
|
10673
|
-
*/
|
|
10674
|
-
type PromptVariables = Record<string, unknown>;
|
|
10675
|
-
/**
|
|
10676
|
-
* Data structure for creating a PromptVersion instance
|
|
10677
|
-
*/
|
|
10678
|
-
interface PromptVersionData {
|
|
10679
|
-
name: string;
|
|
10680
|
-
prompt: string;
|
|
10681
|
-
commit: string;
|
|
10682
|
-
promptId: string;
|
|
10683
|
-
versionId: string;
|
|
10684
|
-
type: PromptType;
|
|
10685
|
-
metadata?: JsonNode;
|
|
10686
|
-
changeDescription?: string;
|
|
10687
|
-
createdAt?: Date;
|
|
10688
|
-
createdBy?: string;
|
|
10689
|
-
}
|
|
10690
|
-
|
|
10691
|
-
/**
|
|
10692
|
-
* Represents a specific immutable snapshot of a prompt template at a point in time.
|
|
10693
|
-
* Pure data object with formatting capabilities.
|
|
10694
|
-
*/
|
|
10695
|
-
declare class PromptVersion {
|
|
10696
|
-
readonly id: string;
|
|
10697
|
-
readonly name: string;
|
|
10698
|
-
readonly prompt: string;
|
|
10699
|
-
readonly commit: string;
|
|
10700
|
-
readonly type: PromptType;
|
|
10701
|
-
readonly metadata?: JsonNode;
|
|
10702
|
-
readonly changeDescription?: string;
|
|
10703
|
-
readonly createdAt?: Date;
|
|
10704
|
-
readonly createdBy?: string;
|
|
10705
|
-
constructor(data: PromptVersionData);
|
|
10706
|
-
/**
|
|
10707
|
-
* Format the prompt template with the provided variables
|
|
10708
|
-
*/
|
|
10709
|
-
format(variables: PromptVariables): string;
|
|
10710
|
-
/**
|
|
10711
|
-
* Get human-readable version age (e.g., "2 days ago", "Today")
|
|
10712
|
-
*/
|
|
10713
|
-
getVersionAge(): string;
|
|
10714
|
-
/**
|
|
10715
|
-
* Get formatted version information string
|
|
10716
|
-
* Format: "[commitHash] YYYY-MM-DD by user@email.com - Change description"
|
|
10717
|
-
*/
|
|
10718
|
-
getVersionInfo(): string;
|
|
10719
|
-
/**
|
|
10720
|
-
* Compare this version's template with another version and return a formatted diff.
|
|
10721
|
-
* Displays a git-style unified diff showing additions, deletions, and changes.
|
|
10722
|
-
* The diff is automatically logged to the terminal and also returned as a string.
|
|
10723
|
-
* The output is colored and formatted for terminal display.
|
|
10724
|
-
*
|
|
10725
|
-
* @param other - The version to compare against
|
|
10726
|
-
* @returns A formatted string showing the differences between versions
|
|
10727
|
-
*
|
|
10728
|
-
* @example
|
|
10729
|
-
* ```typescript
|
|
10730
|
-
* const currentVersion = await prompt.getVersion("commit123");
|
|
10731
|
-
* const previousVersion = await prompt.getVersion("commit456");
|
|
10791
|
+
/**
|
|
10792
|
+
* Retrieves a dataset by its ID.
|
|
10732
10793
|
*
|
|
10733
|
-
*
|
|
10734
|
-
*
|
|
10735
|
-
* ```
|
|
10794
|
+
* @param id The ID of the dataset to retrieve
|
|
10795
|
+
* @returns The retrieved dataset or undefined if not found
|
|
10736
10796
|
*/
|
|
10737
|
-
|
|
10797
|
+
protected getEntity(id: string): Promise<DatasetPublic | undefined>;
|
|
10738
10798
|
/**
|
|
10739
|
-
*
|
|
10799
|
+
* Updates a dataset by its ID with the provided updates.
|
|
10800
|
+
*
|
|
10801
|
+
* @param id The ID of the dataset to update
|
|
10802
|
+
* @param updates Partial dataset properties to update
|
|
10740
10803
|
*/
|
|
10741
|
-
|
|
10804
|
+
protected updateEntity(id: string, updates: Partial<DatasetWrite>): Promise<void>;
|
|
10805
|
+
/**
|
|
10806
|
+
* Deletes multiple datasets by their IDs.
|
|
10807
|
+
*
|
|
10808
|
+
* @param ids Array of dataset IDs to delete
|
|
10809
|
+
*/
|
|
10810
|
+
protected deleteEntities(ids: string[]): Promise<void>;
|
|
10742
10811
|
}
|
|
10743
10812
|
|
|
10744
|
-
|
|
10745
|
-
|
|
10746
|
-
|
|
10813
|
+
type DatasetItemData = JsonNode & {
|
|
10814
|
+
id?: string;
|
|
10815
|
+
};
|
|
10816
|
+
|
|
10817
|
+
interface DatasetData {
|
|
10747
10818
|
name: string;
|
|
10748
|
-
prompt: string;
|
|
10749
|
-
commit?: string;
|
|
10750
|
-
metadata?: JsonNode;
|
|
10751
|
-
type?: PromptType;
|
|
10752
|
-
changeDescription?: string;
|
|
10753
10819
|
description?: string;
|
|
10754
|
-
|
|
10820
|
+
id?: string;
|
|
10755
10821
|
}
|
|
10756
|
-
|
|
10757
|
-
* Domain object representing a versioned prompt template.
|
|
10758
|
-
* Provides immutable access to prompt properties and template formatting.
|
|
10759
|
-
* Integrates with backend for persistence and version management.
|
|
10760
|
-
*/
|
|
10761
|
-
declare class Prompt {
|
|
10822
|
+
declare class Dataset<T extends DatasetItemData = DatasetItemData> {
|
|
10762
10823
|
private opik;
|
|
10763
10824
|
readonly id: string;
|
|
10764
|
-
readonly
|
|
10765
|
-
readonly
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
readonly changeDescription: string | undefined;
|
|
10769
|
-
private _name;
|
|
10770
|
-
private _description;
|
|
10771
|
-
private _tags;
|
|
10772
|
-
private readonly _metadata;
|
|
10773
|
-
/**
|
|
10774
|
-
* Creates a new Prompt instance.
|
|
10775
|
-
* This should not be created directly, use OpikClient.createPrompt() instead.
|
|
10776
|
-
*/
|
|
10777
|
-
constructor({ promptId, versionId, name, prompt, commit, metadata, type, changeDescription, description, tags, }: PromptData, opik: OpikClient);
|
|
10778
|
-
get name(): string;
|
|
10779
|
-
get description(): string | undefined;
|
|
10780
|
-
get tags(): readonly string[] | undefined;
|
|
10825
|
+
readonly name: string;
|
|
10826
|
+
readonly description?: string;
|
|
10827
|
+
private idToHash;
|
|
10828
|
+
private hashes;
|
|
10781
10829
|
/**
|
|
10782
|
-
*
|
|
10783
|
-
*
|
|
10830
|
+
* Configuration object for creating a new Dataset instance.
|
|
10831
|
+
* This should not be created directly, use static factory methods instead.
|
|
10784
10832
|
*/
|
|
10785
|
-
|
|
10833
|
+
constructor({ name, description, id }: DatasetData, opik: OpikClient);
|
|
10786
10834
|
/**
|
|
10787
|
-
*
|
|
10788
|
-
* Validates that all template placeholders are provided (for Mustache templates).
|
|
10789
|
-
*
|
|
10790
|
-
* @param variables - Object with values to substitute into template
|
|
10791
|
-
* @returns Formatted prompt text with variables substituted
|
|
10792
|
-
* @throws PromptValidationError if template processing or validation fails
|
|
10793
|
-
*
|
|
10794
|
-
* @example
|
|
10795
|
-
* ```typescript
|
|
10796
|
-
* const prompt = new Prompt({
|
|
10797
|
-
* name: "greeting",
|
|
10798
|
-
* prompt: "Hello {{name}}, your score is {{score}}",
|
|
10799
|
-
* type: "mustache"
|
|
10800
|
-
* }, client);
|
|
10801
|
-
*
|
|
10802
|
-
* // Valid - all placeholders provided
|
|
10803
|
-
* prompt.format({ name: "Alice", score: 95 });
|
|
10804
|
-
* // Returns: "Hello Alice, your score is 95"
|
|
10835
|
+
* Insert new items into the dataset.
|
|
10805
10836
|
*
|
|
10806
|
-
*
|
|
10807
|
-
* prompt.format({ name: "Alice" });
|
|
10808
|
-
* // Throws: PromptValidationError
|
|
10809
|
-
* ```
|
|
10837
|
+
* @param items List of objects to add to the dataset
|
|
10810
10838
|
*/
|
|
10811
|
-
|
|
10839
|
+
insert(items: T[]): Promise<void>;
|
|
10812
10840
|
/**
|
|
10813
|
-
*
|
|
10841
|
+
* Update existing items in the dataset.
|
|
10842
|
+
* You need to provide the full item object as it will override what has been supplied previously.
|
|
10814
10843
|
*
|
|
10815
|
-
* @param
|
|
10816
|
-
* @param apiResponse - REST API PromptVersionDetail response
|
|
10817
|
-
* @param opik - OpikClient instance
|
|
10818
|
-
* @param promptPublicData - Optional PromptPublic data containing description and tags
|
|
10819
|
-
* @returns Prompt instance constructed from response data
|
|
10820
|
-
* @throws PromptValidationError if response structure invalid
|
|
10844
|
+
* @param items List of objects to update in the dataset
|
|
10821
10845
|
*/
|
|
10822
|
-
|
|
10846
|
+
update(items: T[]): Promise<void>;
|
|
10823
10847
|
/**
|
|
10824
|
-
*
|
|
10825
|
-
* Performs immediate update (no batching).
|
|
10826
|
-
*
|
|
10827
|
-
* @param updates - Partial updates with optional name, description, and tags
|
|
10828
|
-
* @returns Promise resolving to this Prompt instance for method chaining
|
|
10848
|
+
* Delete items from the dataset.
|
|
10829
10849
|
*
|
|
10830
|
-
* @
|
|
10831
|
-
* ```typescript
|
|
10832
|
-
* const prompt = await client.getPrompt({ name: "my-prompt" });
|
|
10833
|
-
* await prompt.updateProperties({
|
|
10834
|
-
* name: "renamed-prompt",
|
|
10835
|
-
* description: "Updated description",
|
|
10836
|
-
* tags: ["tag1", "tag2"]
|
|
10837
|
-
* });
|
|
10838
|
-
* ```
|
|
10850
|
+
* @param itemIds List of item ids to delete
|
|
10839
10851
|
*/
|
|
10840
|
-
|
|
10841
|
-
name?: string;
|
|
10842
|
-
description?: string;
|
|
10843
|
-
tags?: string[];
|
|
10844
|
-
}): Promise<this>;
|
|
10852
|
+
delete(itemIds: string[]): Promise<void>;
|
|
10845
10853
|
/**
|
|
10846
|
-
*
|
|
10847
|
-
* Performs immediate deletion (no batching).
|
|
10854
|
+
* Delete all items from the dataset.
|
|
10848
10855
|
*/
|
|
10849
|
-
|
|
10856
|
+
clear(): Promise<void>;
|
|
10850
10857
|
/**
|
|
10851
|
-
*
|
|
10852
|
-
* Fetches and returns complete version history, sorted by creation date (newest first).
|
|
10853
|
-
* Automatically handles pagination to fetch all versions.
|
|
10854
|
-
*
|
|
10855
|
-
* @returns Promise resolving to array of all PromptVersion instances for this prompt
|
|
10856
|
-
* @throws OpikApiError if REST API call fails
|
|
10857
|
-
*
|
|
10858
|
-
* @example
|
|
10859
|
-
* ```typescript
|
|
10860
|
-
* const prompt = await client.getPrompt({ name: "my-prompt" });
|
|
10861
|
-
* const versions = await prompt.getVersions();
|
|
10858
|
+
* Retrieve a fixed number of dataset items.
|
|
10862
10859
|
*
|
|
10863
|
-
*
|
|
10864
|
-
*
|
|
10865
|
-
*
|
|
10866
|
-
* });
|
|
10867
|
-
* ```
|
|
10860
|
+
* @param nbSamples The number of samples to retrieve. If not set - all items are returned
|
|
10861
|
+
* @param lastRetrievedId Optional ID of the last retrieved item for pagination
|
|
10862
|
+
* @returns A list of objects representing the dataset items
|
|
10868
10863
|
*/
|
|
10869
|
-
|
|
10864
|
+
getItems(nbSamples?: number, lastRetrievedId?: string): Promise<(T & {
|
|
10865
|
+
id: string;
|
|
10866
|
+
})[]>;
|
|
10867
|
+
private getItemsAsDataclasses;
|
|
10870
10868
|
/**
|
|
10871
|
-
*
|
|
10872
|
-
* The version must be obtained from the backend (e.g., via getVersions()).
|
|
10873
|
-
* Returns a new Prompt instance with the restored content as the latest version.
|
|
10874
|
-
*
|
|
10875
|
-
* @param version - PromptVersion object to restore (must be from backend)
|
|
10876
|
-
* @returns Promise resolving to a new Prompt instance with the restored version
|
|
10877
|
-
* @throws OpikApiError if REST API call fails
|
|
10878
|
-
*
|
|
10879
|
-
* @example
|
|
10880
|
-
* ```typescript
|
|
10881
|
-
* const prompt = await client.getPrompt({ name: "my-prompt" });
|
|
10882
|
-
*
|
|
10883
|
-
* // Get all versions
|
|
10884
|
-
* const versions = await prompt.getVersions();
|
|
10885
|
-
*
|
|
10886
|
-
* // Restore a specific version
|
|
10887
|
-
* const targetVersion = versions.find(v => v.commit === "abc123de");
|
|
10888
|
-
* if (targetVersion) {
|
|
10889
|
-
* const restoredPrompt = await prompt.useVersion(targetVersion);
|
|
10890
|
-
* console.log(`Restored to commit: ${restoredPrompt.commit}`);
|
|
10891
|
-
* console.log(`New template: ${restoredPrompt.prompt}`);
|
|
10869
|
+
* Insert items from a JSON string array into the dataset.
|
|
10892
10870
|
*
|
|
10893
|
-
*
|
|
10894
|
-
*
|
|
10895
|
-
*
|
|
10896
|
-
* ```
|
|
10871
|
+
* @param jsonArray JSON string of format: "[{...}, {...}, {...}]" where every object is transformed into a dataset item
|
|
10872
|
+
* @param keysMapping Optional dictionary that maps JSON keys to dataset item field names (e.g., {'Expected output': 'expected_output'})
|
|
10873
|
+
* @param ignoreKeys Optional array of keys that should be ignored when constructing dataset items
|
|
10897
10874
|
*/
|
|
10898
|
-
|
|
10875
|
+
insertFromJson(jsonArray: string, keysMapping?: Record<string, string>, ignoreKeys?: string[]): Promise<void>;
|
|
10899
10876
|
/**
|
|
10900
|
-
*
|
|
10877
|
+
* Convert the dataset to a JSON string.
|
|
10901
10878
|
*
|
|
10902
|
-
* @param
|
|
10903
|
-
* @returns
|
|
10879
|
+
* @param keysMapping Optional dictionary that maps dataset item field names to output JSON keys
|
|
10880
|
+
* @returns A JSON string representation of all items in the dataset
|
|
10881
|
+
*/
|
|
10882
|
+
toJson(keysMapping?: Record<string, string>): Promise<string>;
|
|
10883
|
+
/**
|
|
10884
|
+
* Retrieves all items from the dataset, deduplicates them, and returns them.
|
|
10904
10885
|
*
|
|
10905
|
-
* @
|
|
10906
|
-
|
|
10907
|
-
|
|
10886
|
+
* @returns A list of deduplicated dataset items
|
|
10887
|
+
*/
|
|
10888
|
+
private getDeduplicatedItems;
|
|
10889
|
+
/**
|
|
10890
|
+
* Clears both hash tracking data structures
|
|
10891
|
+
*/
|
|
10892
|
+
private clearHashState;
|
|
10893
|
+
syncHashes(): Promise<void>;
|
|
10894
|
+
}
|
|
10895
|
+
|
|
10896
|
+
/**
|
|
10897
|
+
* References to a dataset item and trace in an experiment.
|
|
10898
|
+
*/
|
|
10899
|
+
declare class ExperimentItemReferences {
|
|
10900
|
+
readonly datasetItemId: string;
|
|
10901
|
+
readonly traceId: string;
|
|
10902
|
+
constructor(params: {
|
|
10903
|
+
datasetItemId: string;
|
|
10904
|
+
traceId: string;
|
|
10905
|
+
});
|
|
10906
|
+
}
|
|
10907
|
+
/**
|
|
10908
|
+
* Content of an experiment item including evaluation data and feedback scores.
|
|
10909
|
+
*/
|
|
10910
|
+
declare class ExperimentItemContent {
|
|
10911
|
+
readonly id?: string;
|
|
10912
|
+
readonly datasetItemId: string;
|
|
10913
|
+
readonly traceId: string;
|
|
10914
|
+
readonly datasetItemData?: JsonListStringCompare;
|
|
10915
|
+
readonly evaluationTaskOutput?: JsonListStringCompare;
|
|
10916
|
+
readonly feedbackScores: FeedbackScore[];
|
|
10917
|
+
constructor(params: {
|
|
10918
|
+
id?: string;
|
|
10919
|
+
datasetItemId: string;
|
|
10920
|
+
traceId: string;
|
|
10921
|
+
datasetItemData?: JsonListStringCompare;
|
|
10922
|
+
evaluationTaskOutput?: JsonListStringCompare;
|
|
10923
|
+
feedbackScores: FeedbackScore[];
|
|
10924
|
+
});
|
|
10925
|
+
/**
|
|
10926
|
+
* Creates an ExperimentItemContent from a REST API ExperimentItemCompare object.
|
|
10908
10927
|
*
|
|
10909
|
-
*
|
|
10910
|
-
*
|
|
10911
|
-
* if (versionedPrompt) {
|
|
10912
|
-
* const text = versionedPrompt.format({ name: "Alice" });
|
|
10913
|
-
* }
|
|
10914
|
-
* ```
|
|
10928
|
+
* @param value The REST API ExperimentItemCompare object
|
|
10929
|
+
* @returns A new ExperimentItemContent instance
|
|
10915
10930
|
*/
|
|
10916
|
-
|
|
10931
|
+
static fromRestExperimentItemCompare(value: ExperimentItemCompare): ExperimentItemContent;
|
|
10917
10932
|
}
|
|
10918
10933
|
|
|
10919
10934
|
interface ExperimentData {
|