@nirmos/sdk 0.3.3 → 0.3.5
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/README.md +24 -1
- package/dist/cjs/core/version.js +1 -1
- package/dist/cjs/evaluations/types.js +3 -0
- package/dist/cjs/evaluations/types.js.map +1 -0
- package/dist/cjs/memory/execution-types.js +3 -0
- package/dist/cjs/memory/execution-types.js.map +1 -0
- package/dist/esm/core/version.d.ts +1 -1
- package/dist/esm/core/version.js +1 -1
- package/dist/esm/evaluations/types.d.ts +13 -0
- package/dist/esm/evaluations/types.d.ts.map +1 -0
- package/dist/esm/evaluations/types.js +2 -0
- package/dist/esm/evaluations/types.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/management/contracts.d.ts +4811 -9037
- package/dist/esm/management/contracts.d.ts.map +1 -1
- package/dist/esm/memory/execution-types.d.ts +35 -0
- package/dist/esm/memory/execution-types.d.ts.map +1 -0
- package/dist/esm/memory/execution-types.js +2 -0
- package/dist/esm/memory/execution-types.js.map +1 -0
- package/dist/esm/memory/types.d.ts +2 -25
- package/dist/esm/memory/types.d.ts.map +1 -1
- package/examples/evaluation-offline.mjs +151 -0
- package/examples/evaluation-quickstart.mjs +210 -0
- package/examples/evaluation-quickstart.ts +255 -0
- package/examples/evaluation-trace-import.mjs +81 -0
- package/examples/evaluation-trace-import.ts +105 -0
- package/examples/tsconfig.json +1 -1
- package/package.json +1 -1
- package/src/core/version.ts +1 -1
- package/src/evaluations/types.ts +18 -0
- package/src/index.ts +11 -0
- package/src/management/contracts.ts +30 -67
- package/src/memory/execution-types.ts +2 -0
- package/src/memory/types.ts +2 -25
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { Nirmos } from "@nirmos/sdk";
|
|
2
|
+
|
|
3
|
+
declare const process: { env: Record<string, string | undefined> };
|
|
4
|
+
|
|
5
|
+
function requireId(value: unknown, label: string): string {
|
|
6
|
+
if (typeof value !== "string" || !value) throw new Error(`Missing ${label}`);
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function evaluationQuickstart(
|
|
11
|
+
client: Nirmos,
|
|
12
|
+
options: {
|
|
13
|
+
providerId: string;
|
|
14
|
+
modelId: string;
|
|
15
|
+
cleanup?: boolean;
|
|
16
|
+
pollMs?: number;
|
|
17
|
+
maxPolls?: number;
|
|
18
|
+
},
|
|
19
|
+
) {
|
|
20
|
+
let datasetId: string | undefined;
|
|
21
|
+
let suiteId: string | undefined;
|
|
22
|
+
let evaluatorId: string | undefined;
|
|
23
|
+
let runId: string | undefined;
|
|
24
|
+
let terminal = false;
|
|
25
|
+
let submissionStarted = false;
|
|
26
|
+
try {
|
|
27
|
+
const dataset = await client.evaluations.datasets.create({
|
|
28
|
+
name: "SDK two-case demo",
|
|
29
|
+
});
|
|
30
|
+
datasetId = requireId(dataset.dataset.id, "dataset ID");
|
|
31
|
+
const datasetVersionId = requireId(
|
|
32
|
+
dataset.initialVersion?.id,
|
|
33
|
+
"dataset version ID",
|
|
34
|
+
);
|
|
35
|
+
console.log({ datasetId, datasetVersionId });
|
|
36
|
+
for (const column of [
|
|
37
|
+
{ key: "question", name: "Question", role: "input" as const },
|
|
38
|
+
{ key: "expected", name: "Expected", role: "expected" as const },
|
|
39
|
+
{ key: "topic", name: "Topic", role: "metadata" as const },
|
|
40
|
+
]) {
|
|
41
|
+
await client.evaluations.datasets.columns.create(datasetId, {
|
|
42
|
+
datasetVersionId,
|
|
43
|
+
...column,
|
|
44
|
+
dataType: "text",
|
|
45
|
+
required: true,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
for (const data of [
|
|
49
|
+
{
|
|
50
|
+
question: "Reply with exactly Paris and nothing else.",
|
|
51
|
+
expected: "Paris",
|
|
52
|
+
topic: "cities",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
question: "Reply with exactly Tokyo and nothing else.",
|
|
56
|
+
expected: "Tokyo",
|
|
57
|
+
topic: "cities",
|
|
58
|
+
},
|
|
59
|
+
]) {
|
|
60
|
+
await client.evaluations.datasets.cases.create(datasetId, {
|
|
61
|
+
datasetVersionId,
|
|
62
|
+
data,
|
|
63
|
+
tags: ["sdk-demo"],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
await client.evaluations.datasets.versions.freeze(
|
|
67
|
+
datasetId,
|
|
68
|
+
datasetVersionId,
|
|
69
|
+
);
|
|
70
|
+
const suite = await client.evaluations.suites.create({
|
|
71
|
+
name: "SDK exact-match demo",
|
|
72
|
+
datasetVersionId,
|
|
73
|
+
});
|
|
74
|
+
suiteId = requireId(suite.id, "suite ID");
|
|
75
|
+
console.log({ suiteId });
|
|
76
|
+
const target = await client.evaluations.columns.create({
|
|
77
|
+
suiteId,
|
|
78
|
+
key: "candidate",
|
|
79
|
+
name: "Candidate",
|
|
80
|
+
category: "target",
|
|
81
|
+
enabled: true,
|
|
82
|
+
config: { role: "candidate", dataType: "output" },
|
|
83
|
+
target: {
|
|
84
|
+
type: "model",
|
|
85
|
+
name: "Demo model",
|
|
86
|
+
providerId: options.providerId,
|
|
87
|
+
modelId: options.modelId,
|
|
88
|
+
inputMapping: { user_message: "dataset.question" },
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
// The target's logical ID is distinct from the immutable version used in runs.
|
|
92
|
+
const targetId = requireId(target.target?.id, "target ID");
|
|
93
|
+
const targetVersionId = requireId(
|
|
94
|
+
target.targetVersion?.id,
|
|
95
|
+
"target version ID",
|
|
96
|
+
);
|
|
97
|
+
const evaluator = await client.evaluations.evaluators.create({
|
|
98
|
+
name: "SDK exact match",
|
|
99
|
+
version: {
|
|
100
|
+
type: "exact_match",
|
|
101
|
+
category: "deterministic",
|
|
102
|
+
scope: "output",
|
|
103
|
+
inputSchema: [
|
|
104
|
+
{ key: "actual", type: "any", required: true },
|
|
105
|
+
{ key: "expected", type: "any", required: true },
|
|
106
|
+
],
|
|
107
|
+
config: {
|
|
108
|
+
caseSensitive: true,
|
|
109
|
+
trimWhitespace: true,
|
|
110
|
+
normalizeWhitespace: false,
|
|
111
|
+
},
|
|
112
|
+
outputType: "boolean",
|
|
113
|
+
scoreDirection: "none",
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
evaluatorId = requireId(evaluator.evaluator.id, "evaluator ID");
|
|
117
|
+
const evaluatorVersionId = requireId(
|
|
118
|
+
evaluator.version?.id,
|
|
119
|
+
"evaluator version ID",
|
|
120
|
+
);
|
|
121
|
+
console.log({ evaluatorId, targetVersionId, evaluatorVersionId });
|
|
122
|
+
await client.evaluations.columns.create({
|
|
123
|
+
suiteId,
|
|
124
|
+
key: "exact_match",
|
|
125
|
+
name: "Exact match",
|
|
126
|
+
category: "evaluator",
|
|
127
|
+
enabled: true,
|
|
128
|
+
evaluatorVersionId,
|
|
129
|
+
config: {
|
|
130
|
+
inputMapping: {
|
|
131
|
+
actual: { source: "target", path: "output" },
|
|
132
|
+
expected: { source: "dataset", key: "expected" },
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
const experiment = await client.evaluations.experiments.prepare({
|
|
137
|
+
suiteId,
|
|
138
|
+
datasetVersionId,
|
|
139
|
+
targetVersionIds: [targetVersionId],
|
|
140
|
+
evaluatorVersionIds: [evaluatorVersionId],
|
|
141
|
+
trialCount: 1,
|
|
142
|
+
});
|
|
143
|
+
const experimentId = requireId(experiment.id, "experiment ID");
|
|
144
|
+
// Persist this input and submissionId if implementing replay across process restarts.
|
|
145
|
+
const submissionId = crypto.randomUUID();
|
|
146
|
+
console.log({ experimentId, submissionId });
|
|
147
|
+
submissionStarted = true;
|
|
148
|
+
const created = await client.evaluations.runs.create(
|
|
149
|
+
{
|
|
150
|
+
experimentId,
|
|
151
|
+
cases: "all",
|
|
152
|
+
targetIds: [targetVersionId],
|
|
153
|
+
evaluatorIds: [evaluatorVersionId],
|
|
154
|
+
trialCount: 1,
|
|
155
|
+
},
|
|
156
|
+
{ idempotencyKey: submissionId, maxRetries: 0 },
|
|
157
|
+
);
|
|
158
|
+
runId = created.id;
|
|
159
|
+
console.log({ runId });
|
|
160
|
+
for (let attempt = 0; attempt < (options.maxPolls ?? 60); attempt++) {
|
|
161
|
+
const run = await client.evaluations.runs.get(runId, {
|
|
162
|
+
timeoutMs: 10_000,
|
|
163
|
+
maxRetries: 0,
|
|
164
|
+
});
|
|
165
|
+
if (["COMPLETED", "FAILED", "CANCELLED"].includes(run.status)) {
|
|
166
|
+
terminal = true;
|
|
167
|
+
const results = await client.evaluations.runs.results(runId, {
|
|
168
|
+
page: 1,
|
|
169
|
+
pageSize: 25,
|
|
170
|
+
});
|
|
171
|
+
for (const trial of results.data) {
|
|
172
|
+
console.log({
|
|
173
|
+
caseId: trial.caseId,
|
|
174
|
+
trialStatus: trial.status,
|
|
175
|
+
error: trial.error,
|
|
176
|
+
});
|
|
177
|
+
for (const score of trial.scores) {
|
|
178
|
+
console.log({
|
|
179
|
+
evaluatorVersionId: score.evaluatorVersionId,
|
|
180
|
+
status: score.status,
|
|
181
|
+
value: score.value,
|
|
182
|
+
passed: score.passed,
|
|
183
|
+
error: score.error,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Two cases × one target × one trial fit on one page.
|
|
188
|
+
if (run.status !== "COMPLETED")
|
|
189
|
+
throw new Error(`Run ${runId}: ${run.status}`);
|
|
190
|
+
if (
|
|
191
|
+
results.data.length !== 2 ||
|
|
192
|
+
results.data.some(
|
|
193
|
+
(trial) =>
|
|
194
|
+
trial.status !== "COMPLETED" ||
|
|
195
|
+
trial.scores.length !== 1 ||
|
|
196
|
+
trial.scores.some(
|
|
197
|
+
(score) => score.status !== "COMPLETED" || score.error,
|
|
198
|
+
),
|
|
199
|
+
)
|
|
200
|
+
) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
"Run ended with missing or failed trials/scores; inspect results",
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
// Runtime GET returns persisted aggregates after terminal processing.
|
|
206
|
+
const summary = run.summary;
|
|
207
|
+
if (!summary || typeof summary.overallPassRate !== "number")
|
|
208
|
+
throw new Error("Missing aggregate scores; inspect the terminal run");
|
|
209
|
+
console.log({ overallPassRate: summary.overallPassRate, byEvaluator: summary.byEvaluator });
|
|
210
|
+
return { runId, results, summary }; // passed:false is a valid evaluation outcome.
|
|
211
|
+
}
|
|
212
|
+
await new Promise((resolve) =>
|
|
213
|
+
setTimeout(resolve, options.pollMs ?? 2000),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
await client.evaluations.runs.cancel(runId);
|
|
217
|
+
throw new Error(
|
|
218
|
+
`Polling limit reached; cancellation requested for ${runId}. Confirm terminal state before cleanup.`,
|
|
219
|
+
);
|
|
220
|
+
} finally {
|
|
221
|
+
// Never archive inputs while background execution might still use them.
|
|
222
|
+
if (options.cleanup && (!submissionStarted || terminal)) {
|
|
223
|
+
const cleanup = await Promise.allSettled([
|
|
224
|
+
...(suiteId ? [client.evaluations.suites.archive(suiteId)] : []),
|
|
225
|
+
...(evaluatorId
|
|
226
|
+
? [client.evaluations.evaluators.archive(evaluatorId)]
|
|
227
|
+
: []),
|
|
228
|
+
...(datasetId ? [client.evaluations.datasets.archive(datasetId)] : []),
|
|
229
|
+
]);
|
|
230
|
+
for (const result of cleanup)
|
|
231
|
+
if (result.status === "rejected")
|
|
232
|
+
console.error("Archive failed:", result.reason);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (process.env.NIRMOS_RUN_EVALUATION_EXAMPLE === "1") {
|
|
238
|
+
const key = requireId(process.env.NIRMOS_API_KEY, "NIRMOS_API_KEY");
|
|
239
|
+
await evaluationQuickstart(
|
|
240
|
+
new Nirmos({
|
|
241
|
+
auth: { type: "api-key", key },
|
|
242
|
+
apiBaseUrl: process.env.NIRMOS_API_URL,
|
|
243
|
+
runtimeBaseUrl: process.env.NIRMOS_RUNTIME_URL,
|
|
244
|
+
maxRetries: 0,
|
|
245
|
+
}),
|
|
246
|
+
{
|
|
247
|
+
providerId: requireId(
|
|
248
|
+
process.env.NIRMOS_PROVIDER_ID,
|
|
249
|
+
"NIRMOS_PROVIDER_ID",
|
|
250
|
+
),
|
|
251
|
+
modelId: requireId(process.env.NIRMOS_MODEL_ID, "NIRMOS_MODEL_ID"),
|
|
252
|
+
cleanup: process.env.EVALUATION_CLEANUP === "1",
|
|
253
|
+
},
|
|
254
|
+
);
|
|
255
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Generated from evaluation-trace-import.ts. Do not edit.
|
|
2
|
+
import { APIError, Nirmos } from "@nirmos/sdk";
|
|
3
|
+
/** Destination draft needs required JSON columns named input and output. */
|
|
4
|
+
export async function importGatewayTrace(client, options) {
|
|
5
|
+
const response = await client.gateway.chat.create({
|
|
6
|
+
model: options.model,
|
|
7
|
+
messages: [{ role: "user", content: "What is the capital of France?" }],
|
|
8
|
+
}, { maxRetries: 0 });
|
|
9
|
+
const requestId = response.metadata.requestId;
|
|
10
|
+
if (!requestId)
|
|
11
|
+
throw new Error("Gateway response omitted public request ID");
|
|
12
|
+
const deadline = Date.now() + (options.maxWaitMs ?? 30_000);
|
|
13
|
+
while (true) {
|
|
14
|
+
const remaining = deadline - Date.now();
|
|
15
|
+
if (remaining <= 0)
|
|
16
|
+
throw new Error(`Trace ${requestId} unavailable after bounded wait; check logging and retention`);
|
|
17
|
+
try {
|
|
18
|
+
// Logs API accepts the same public request ID. Existence confirms persistence,
|
|
19
|
+
// not eligibility: import performs the authoritative payload/operation checks.
|
|
20
|
+
await client.logs.get(requestId, {
|
|
21
|
+
timeoutMs: Math.min(5_000, remaining),
|
|
22
|
+
maxRetries: 0,
|
|
23
|
+
});
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (!(error instanceof APIError) || error.status !== 404)
|
|
28
|
+
throw error;
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(options.pollMs ?? 1_000, Math.max(0, deadline - Date.now()))));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const imported = await client.evaluations.datasets.importTrace({
|
|
33
|
+
requestLogId: requestId,
|
|
34
|
+
datasetVersionId: options.datasetVersionId,
|
|
35
|
+
mapping: { input: "input", output: "output" },
|
|
36
|
+
tags: ["gateway-regression"],
|
|
37
|
+
}, { maxRetries: 0 });
|
|
38
|
+
const datasetCase = await client.evaluations.datasets.cases.get(imported.case.id);
|
|
39
|
+
return { requestId, imported, datasetCase };
|
|
40
|
+
}
|
|
41
|
+
if (process.env.NIRMOS_RUN_TRACE_EXAMPLE === "1") {
|
|
42
|
+
const apiKey = process.env.NIRMOS_API_KEY;
|
|
43
|
+
const model = process.env.NIRMOS_CHAT_MODEL;
|
|
44
|
+
if (!apiKey || !model)
|
|
45
|
+
throw new Error("Set NIRMOS_API_KEY and NIRMOS_CHAT_MODEL");
|
|
46
|
+
const client = new Nirmos({
|
|
47
|
+
auth: { type: "api-key", key: apiKey },
|
|
48
|
+
apiBaseUrl: process.env.NIRMOS_API_URL,
|
|
49
|
+
runtimeBaseUrl: process.env.NIRMOS_RUNTIME_URL,
|
|
50
|
+
maxRetries: 0,
|
|
51
|
+
});
|
|
52
|
+
const dataset = await client.evaluations.datasets.create({
|
|
53
|
+
name: "Gateway trace demo",
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
for (const key of ["input", "output"]) {
|
|
57
|
+
await client.evaluations.datasets.columns.create(dataset.dataset.id, {
|
|
58
|
+
datasetVersionId: dataset.initialVersion.id,
|
|
59
|
+
key,
|
|
60
|
+
name: key,
|
|
61
|
+
dataType: "json",
|
|
62
|
+
role: key === "input" ? "input" : "expected",
|
|
63
|
+
required: true,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const result = await importGatewayTrace(client, {
|
|
67
|
+
datasetVersionId: dataset.initialVersion.id,
|
|
68
|
+
model,
|
|
69
|
+
});
|
|
70
|
+
console.log(result.requestId, result.imported.case.id, result.datasetCase.values);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof APIError)
|
|
74
|
+
console.error(error.code, error.message);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
if (process.env.EVALUATION_CLEANUP === "1")
|
|
79
|
+
await client.evaluations.datasets.archive(dataset.dataset.id);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { APIError, Nirmos } from "@nirmos/sdk";
|
|
2
|
+
|
|
3
|
+
declare const process: { env: Record<string, string | undefined> };
|
|
4
|
+
|
|
5
|
+
/** Destination draft needs required JSON columns named input and output. */
|
|
6
|
+
export async function importGatewayTrace(
|
|
7
|
+
client: Nirmos,
|
|
8
|
+
options: {
|
|
9
|
+
datasetVersionId: string;
|
|
10
|
+
model: string;
|
|
11
|
+
maxWaitMs?: number;
|
|
12
|
+
pollMs?: number;
|
|
13
|
+
},
|
|
14
|
+
) {
|
|
15
|
+
const response = await client.gateway.chat.create(
|
|
16
|
+
{
|
|
17
|
+
model: options.model,
|
|
18
|
+
messages: [{ role: "user", content: "What is the capital of France?" }],
|
|
19
|
+
},
|
|
20
|
+
{ maxRetries: 0 },
|
|
21
|
+
);
|
|
22
|
+
const requestId = response.metadata.requestId;
|
|
23
|
+
if (!requestId) throw new Error("Gateway response omitted public request ID");
|
|
24
|
+
const deadline = Date.now() + (options.maxWaitMs ?? 30_000);
|
|
25
|
+
while (true) {
|
|
26
|
+
const remaining = deadline - Date.now();
|
|
27
|
+
if (remaining <= 0)
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Trace ${requestId} unavailable after bounded wait; check logging and retention`,
|
|
30
|
+
);
|
|
31
|
+
try {
|
|
32
|
+
// Logs API accepts the same public request ID. Existence confirms persistence,
|
|
33
|
+
// not eligibility: import performs the authoritative payload/operation checks.
|
|
34
|
+
await client.logs.get(requestId, {
|
|
35
|
+
timeoutMs: Math.min(5_000, remaining),
|
|
36
|
+
maxRetries: 0,
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (!(error instanceof APIError) || error.status !== 404) throw error;
|
|
41
|
+
await new Promise((resolve) =>
|
|
42
|
+
setTimeout(
|
|
43
|
+
resolve,
|
|
44
|
+
Math.min(options.pollMs ?? 1_000, Math.max(0, deadline - Date.now())),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const imported = await client.evaluations.datasets.importTrace(
|
|
50
|
+
{
|
|
51
|
+
requestLogId: requestId,
|
|
52
|
+
datasetVersionId: options.datasetVersionId,
|
|
53
|
+
mapping: { input: "input", output: "output" },
|
|
54
|
+
tags: ["gateway-regression"],
|
|
55
|
+
},
|
|
56
|
+
{ maxRetries: 0 },
|
|
57
|
+
);
|
|
58
|
+
const datasetCase = await client.evaluations.datasets.cases.get(
|
|
59
|
+
imported.case.id,
|
|
60
|
+
);
|
|
61
|
+
return { requestId, imported, datasetCase };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (process.env.NIRMOS_RUN_TRACE_EXAMPLE === "1") {
|
|
65
|
+
const apiKey = process.env.NIRMOS_API_KEY;
|
|
66
|
+
const model = process.env.NIRMOS_CHAT_MODEL;
|
|
67
|
+
if (!apiKey || !model)
|
|
68
|
+
throw new Error("Set NIRMOS_API_KEY and NIRMOS_CHAT_MODEL");
|
|
69
|
+
const client = new Nirmos({
|
|
70
|
+
auth: { type: "api-key", key: apiKey },
|
|
71
|
+
apiBaseUrl: process.env.NIRMOS_API_URL,
|
|
72
|
+
runtimeBaseUrl: process.env.NIRMOS_RUNTIME_URL,
|
|
73
|
+
maxRetries: 0,
|
|
74
|
+
});
|
|
75
|
+
const dataset = await client.evaluations.datasets.create({
|
|
76
|
+
name: "Gateway trace demo",
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
for (const key of ["input", "output"]) {
|
|
80
|
+
await client.evaluations.datasets.columns.create(dataset.dataset.id, {
|
|
81
|
+
datasetVersionId: dataset.initialVersion.id,
|
|
82
|
+
key,
|
|
83
|
+
name: key,
|
|
84
|
+
dataType: "json",
|
|
85
|
+
role: key === "input" ? "input" : "expected",
|
|
86
|
+
required: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const result = await importGatewayTrace(client, {
|
|
90
|
+
datasetVersionId: dataset.initialVersion.id,
|
|
91
|
+
model,
|
|
92
|
+
});
|
|
93
|
+
console.log(
|
|
94
|
+
result.requestId,
|
|
95
|
+
result.imported.case.id,
|
|
96
|
+
result.datasetCase.values,
|
|
97
|
+
);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof APIError) console.error(error.code, error.message);
|
|
100
|
+
throw error;
|
|
101
|
+
} finally {
|
|
102
|
+
if (process.env.EVALUATION_CLEANUP === "1")
|
|
103
|
+
await client.evaluations.datasets.archive(dataset.dataset.id);
|
|
104
|
+
}
|
|
105
|
+
}
|
package/examples/tsconfig.json
CHANGED
package/package.json
CHANGED
package/src/core/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated from package.json by scripts/generate-version.mjs.
|
|
2
|
-
export const SDK_VERSION = "0.3.
|
|
2
|
+
export const SDK_VERSION = "0.3.5";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Requests } from "../management/contracts.js";
|
|
2
|
+
|
|
3
|
+
/** Built-in evaluator versions are discriminated by type. Configs follow the API schemas. */
|
|
4
|
+
export type EvaluationEvaluatorVersion = Requests["createEvaluatorVersion"];
|
|
5
|
+
export type EvaluationTargetConfig = NonNullable<
|
|
6
|
+
Requests["createEvaluationColumn"]["target"]
|
|
7
|
+
>;
|
|
8
|
+
export type EvaluationColumnCreate = Requests["createEvaluationColumn"];
|
|
9
|
+
export type EvaluationInputBinding = NonNullable<
|
|
10
|
+
NonNullable<EvaluationColumnCreate["config"]>["inputMapping"]
|
|
11
|
+
>[string];
|
|
12
|
+
export type EvaluationSegmentCriteria = Requests["createSegment"]["criteria"];
|
|
13
|
+
|
|
14
|
+
export type EvaluationEvaluatorType = EvaluationEvaluatorVersion["type"];
|
|
15
|
+
export type EvaluationEvaluatorConfig<T extends EvaluationEvaluatorType> =
|
|
16
|
+
Extract<EvaluationEvaluatorVersion, { type: T }>["config"];
|
|
17
|
+
export type EvaluationExpression =
|
|
18
|
+
EvaluationEvaluatorConfig<"custom_expression">["expression"];
|
package/src/index.ts
CHANGED
|
@@ -150,3 +150,14 @@ export {
|
|
|
150
150
|
validatePromptVariableValues,
|
|
151
151
|
validatePromptSettings,
|
|
152
152
|
} from "./prompts/variables.js";
|
|
153
|
+
|
|
154
|
+
export type {
|
|
155
|
+
EvaluationEvaluatorVersion,
|
|
156
|
+
EvaluationEvaluatorType,
|
|
157
|
+
EvaluationEvaluatorConfig,
|
|
158
|
+
EvaluationExpression,
|
|
159
|
+
EvaluationTargetConfig,
|
|
160
|
+
EvaluationColumnCreate,
|
|
161
|
+
EvaluationInputBinding,
|
|
162
|
+
EvaluationSegmentCriteria,
|
|
163
|
+
} from "./evaluations/types.js";
|