notdiamond 2.0.0-rc2 → 2.0.0-rc5

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.
Files changed (167) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +14 -16
  3. package/client.d.mts +20 -34
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +20 -34
  6. package/client.d.ts.map +1 -1
  7. package/client.js +22 -38
  8. package/client.js.map +1 -1
  9. package/client.mjs +22 -38
  10. package/client.mjs.map +1 -1
  11. package/internal/tslib.js +17 -17
  12. package/internal/utils/env.d.mts.map +1 -1
  13. package/internal/utils/env.d.ts.map +1 -1
  14. package/internal/utils/env.js +4 -2
  15. package/internal/utils/env.js.map +1 -1
  16. package/internal/utils/env.mjs +4 -2
  17. package/internal/utils/env.mjs.map +1 -1
  18. package/package.json +10 -11
  19. package/resources/index.d.mts +6 -6
  20. package/resources/index.d.mts.map +1 -1
  21. package/resources/index.d.ts +6 -6
  22. package/resources/index.d.ts.map +1 -1
  23. package/resources/index.js +8 -8
  24. package/resources/index.js.map +1 -1
  25. package/resources/index.mjs +4 -4
  26. package/resources/index.mjs.map +1 -1
  27. package/resources/model-router.d.mts +311 -0
  28. package/resources/model-router.d.mts.map +1 -0
  29. package/resources/model-router.d.ts +311 -0
  30. package/resources/model-router.d.ts.map +1 -0
  31. package/resources/model-router.js +97 -0
  32. package/resources/model-router.js.map +1 -0
  33. package/resources/model-router.mjs +93 -0
  34. package/resources/model-router.mjs.map +1 -0
  35. package/resources/models.d.mts +50 -25
  36. package/resources/models.d.mts.map +1 -1
  37. package/resources/models.d.ts +50 -25
  38. package/resources/models.d.ts.map +1 -1
  39. package/resources/models.js +5 -0
  40. package/resources/models.js.map +1 -1
  41. package/resources/models.mjs +5 -0
  42. package/resources/models.mjs.map +1 -1
  43. package/resources/preferences.d.mts +49 -47
  44. package/resources/preferences.d.mts.map +1 -1
  45. package/resources/preferences.d.ts +49 -47
  46. package/resources/preferences.d.ts.map +1 -1
  47. package/resources/preferences.js +30 -33
  48. package/resources/preferences.js.map +1 -1
  49. package/resources/preferences.mjs +30 -33
  50. package/resources/preferences.mjs.map +1 -1
  51. package/resources/prompt/adapt.d.mts +352 -0
  52. package/resources/prompt/adapt.d.mts.map +1 -0
  53. package/resources/prompt/adapt.d.ts +352 -0
  54. package/resources/prompt/adapt.d.ts.map +1 -0
  55. package/resources/prompt/adapt.js +154 -0
  56. package/resources/prompt/adapt.js.map +1 -0
  57. package/resources/prompt/adapt.mjs +150 -0
  58. package/resources/prompt/adapt.mjs.map +1 -0
  59. package/resources/prompt/index.d.mts +3 -0
  60. package/resources/prompt/index.d.mts.map +1 -0
  61. package/resources/prompt/index.d.ts +3 -0
  62. package/resources/prompt/index.d.ts.map +1 -0
  63. package/resources/prompt/index.js +9 -0
  64. package/resources/prompt/index.js.map +1 -0
  65. package/resources/prompt/index.mjs +4 -0
  66. package/resources/prompt/index.mjs.map +1 -0
  67. package/resources/prompt/prompt.d.mts +338 -0
  68. package/resources/prompt/prompt.d.mts.map +1 -0
  69. package/resources/prompt/prompt.d.ts +338 -0
  70. package/resources/prompt/prompt.d.ts.map +1 -0
  71. package/resources/prompt/prompt.js +128 -0
  72. package/resources/prompt/prompt.js.map +1 -0
  73. package/resources/prompt/prompt.mjs +123 -0
  74. package/resources/prompt/prompt.mjs.map +1 -0
  75. package/resources/prompt.d.mts +2 -0
  76. package/resources/prompt.d.mts.map +1 -0
  77. package/resources/prompt.d.ts +2 -0
  78. package/resources/prompt.d.ts.map +1 -0
  79. package/resources/prompt.js +6 -0
  80. package/resources/prompt.js.map +1 -0
  81. package/resources/prompt.mjs +3 -0
  82. package/resources/prompt.mjs.map +1 -0
  83. package/resources/pzn.d.mts +225 -0
  84. package/resources/pzn.d.mts.map +1 -0
  85. package/resources/pzn.d.ts +225 -0
  86. package/resources/pzn.d.ts.map +1 -0
  87. package/resources/{routing.js → pzn.js} +26 -69
  88. package/resources/pzn.js.map +1 -0
  89. package/resources/{routing.mjs → pzn.mjs} +24 -67
  90. package/resources/pzn.mjs.map +1 -0
  91. package/resources/report/index.d.mts +3 -0
  92. package/resources/report/index.d.mts.map +1 -0
  93. package/resources/report/index.d.ts +3 -0
  94. package/resources/report/index.d.ts.map +1 -0
  95. package/resources/report/index.js +9 -0
  96. package/resources/report/index.js.map +1 -0
  97. package/resources/report/index.mjs +4 -0
  98. package/resources/report/index.mjs.map +1 -0
  99. package/resources/report/metrics.d.mts +87 -0
  100. package/resources/report/metrics.d.mts.map +1 -0
  101. package/resources/report/metrics.d.ts +87 -0
  102. package/resources/report/metrics.d.ts.map +1 -0
  103. package/resources/report/metrics.js +57 -0
  104. package/resources/report/metrics.js.map +1 -0
  105. package/resources/report/metrics.mjs +53 -0
  106. package/resources/report/metrics.mjs.map +1 -0
  107. package/resources/report/report.d.mts +10 -0
  108. package/resources/report/report.d.mts.map +1 -0
  109. package/resources/report/report.d.ts +10 -0
  110. package/resources/report/report.d.ts.map +1 -0
  111. package/resources/report/report.js +17 -0
  112. package/resources/report/report.js.map +1 -0
  113. package/resources/report/report.mjs +12 -0
  114. package/resources/report/report.mjs.map +1 -0
  115. package/resources/report.d.mts +1 -244
  116. package/resources/report.d.mts.map +1 -1
  117. package/resources/report.d.ts +1 -244
  118. package/resources/report.d.ts.map +1 -1
  119. package/resources/report.js +2 -82
  120. package/resources/report.js.map +1 -1
  121. package/resources/report.mjs +1 -80
  122. package/resources/report.mjs.map +1 -1
  123. package/src/client.ts +70 -119
  124. package/src/internal/utils/env.ts +4 -2
  125. package/src/resources/index.ts +24 -34
  126. package/src/resources/model-router.ts +356 -0
  127. package/src/resources/models.ts +55 -32
  128. package/src/resources/preferences.ts +61 -70
  129. package/src/resources/prompt/adapt.ts +402 -0
  130. package/src/resources/prompt/index.ts +16 -0
  131. package/src/resources/prompt/prompt.ts +398 -0
  132. package/src/resources/prompt.ts +3 -0
  133. package/src/resources/pzn.ts +273 -0
  134. package/src/resources/report/index.ts +4 -0
  135. package/src/resources/report/metrics.ts +99 -0
  136. package/src/resources/report/report.ts +19 -0
  137. package/src/resources/report.ts +1 -298
  138. package/src/version.ts +1 -1
  139. package/version.d.mts +1 -1
  140. package/version.d.ts +1 -1
  141. package/version.js +1 -1
  142. package/version.mjs +1 -1
  143. package/resources/admin.d.mts +0 -4
  144. package/resources/admin.d.mts.map +0 -1
  145. package/resources/admin.d.ts +0 -4
  146. package/resources/admin.d.ts.map +0 -1
  147. package/resources/admin.js +0 -9
  148. package/resources/admin.js.map +0 -1
  149. package/resources/admin.mjs +0 -5
  150. package/resources/admin.mjs.map +0 -1
  151. package/resources/prompt-adaptation.d.mts +0 -581
  152. package/resources/prompt-adaptation.d.mts.map +0 -1
  153. package/resources/prompt-adaptation.d.ts +0 -581
  154. package/resources/prompt-adaptation.d.ts.map +0 -1
  155. package/resources/prompt-adaptation.js +0 -289
  156. package/resources/prompt-adaptation.js.map +0 -1
  157. package/resources/prompt-adaptation.mjs +0 -285
  158. package/resources/prompt-adaptation.mjs.map +0 -1
  159. package/resources/routing.d.mts +0 -391
  160. package/resources/routing.d.mts.map +0 -1
  161. package/resources/routing.d.ts +0 -391
  162. package/resources/routing.d.ts.map +0 -1
  163. package/resources/routing.js.map +0 -1
  164. package/resources/routing.mjs.map +0 -1
  165. package/src/resources/admin.ts +0 -5
  166. package/src/resources/prompt-adaptation.ts +0 -707
  167. package/src/resources/routing.ts +0 -476
@@ -0,0 +1,398 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../core/resource';
4
+ import * as PromptAPI from './prompt';
5
+ import * as AdaptAPI from './adapt';
6
+ import {
7
+ Adapt,
8
+ AdaptCreateParams,
9
+ AdaptCreateResponse,
10
+ AdaptGetCostsResponse,
11
+ GoldenRecord,
12
+ RequestProvider,
13
+ } from './adapt';
14
+ import { APIPromise } from '../../core/api-promise';
15
+ import { RequestOptions } from '../../internal/request-options';
16
+ import { path } from '../../internal/utils/path';
17
+
18
+ export class Prompt extends APIResource {
19
+ adapt: AdaptAPI.Adapt = new AdaptAPI.Adapt(this._client);
20
+
21
+ /**
22
+ * Retrieve the complete results of a prompt adaptation run, including optimized
23
+ * prompts for all target models.
24
+ *
25
+ * This endpoint returns the adapted prompts and evaluation metrics for each target
26
+ * model in your adaptation request. Call this endpoint after the adaptation status
27
+ * is 'completed' to get your optimized prompts.
28
+ *
29
+ * **Response Structure:**
30
+ *
31
+ * - **origin_model**: Baseline performance of your original prompt on the origin
32
+ * model
33
+ * - Includes: system_prompt, user_message_template, score, evaluation metrics,
34
+ * cost
35
+ * - **target_models**: Array of results for each target model
36
+ * - Includes: optimized system_prompt, user_message_template, template_fields
37
+ * - pre_optimization_score: Performance before adaptation
38
+ * - post_optimization_score: Performance after adaptation
39
+ * - Evaluation metrics and cost information
40
+ *
41
+ * **Using Adapted Prompts:**
42
+ *
43
+ * 1. Extract the `system_prompt` and `user_message_template` from each target
44
+ * model result
45
+ * 2. Use `user_message_template_fields` to know which fields to substitute
46
+ * 3. Apply the optimized prompts when calling the respective target models
47
+ * 4. Compare pre/post optimization scores to see improvement
48
+ *
49
+ * **Evaluation Scores:**
50
+ *
51
+ * - Scores range from 0-10 (higher is better)
52
+ * - Compare origin_model score with target_models pre_optimization_score for
53
+ * baseline
54
+ * - Compare pre_optimization_score with post_optimization_score to see improvement
55
+ * from adaptation
56
+ * - Typical improvements range from 5-30% on evaluation metrics
57
+ *
58
+ * **Status Handling:**
59
+ *
60
+ * - If adaptation is still processing, target model results will have
61
+ * `result_status: "processing"`
62
+ * - Only completed target models will have system_prompt and template values
63
+ * - Failed target models will have `result_status: "failed"` with null values
64
+ *
65
+ * **Cost Information:**
66
+ *
67
+ * - Each model result includes cost in USD for the adaptation process
68
+ * - Costs vary based on model pricing and number of evaluation examples
69
+ * - Typical range: $0.10 - $2.00 per target model
70
+ *
71
+ * **Best Practices:**
72
+ *
73
+ * 1. Wait for status 'completed' before calling this endpoint
74
+ * 2. Check result_status for each target model
75
+ * 3. Validate that post_optimization_score > pre_optimization_score
76
+ * 4. Save optimized prompts for production use
77
+ * 5. A/B test adapted prompts against originals in production
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const response = await client.prompt.getAdaptResults(
82
+ * 'adaptation_run_id',
83
+ * );
84
+ * ```
85
+ */
86
+ getAdaptResults(
87
+ adaptationRunID: string,
88
+ options?: RequestOptions,
89
+ ): APIPromise<PromptGetAdaptResultsResponse> {
90
+ return this._client.get(path`/v2/prompt/adaptResults/${adaptationRunID}`, options);
91
+ }
92
+
93
+ /**
94
+ * Check the status of a prompt adaptation run.
95
+ *
96
+ * Use this endpoint to poll the status of your adaptation request. Processing is
97
+ * asynchronous, so you'll need to check periodically until the status indicates
98
+ * completion.
99
+ *
100
+ * **Status Values:**
101
+ *
102
+ * - `created`: Initial state, not yet processing
103
+ * - `queued`: Waiting for processing capacity (check queue_position)
104
+ * - `processing`: Currently optimizing prompts
105
+ * - `completed`: All target models have been processed successfully
106
+ * - `failed`: One or more target models failed to process
107
+ *
108
+ * **Polling Recommendations:**
109
+ *
110
+ * - Poll every 30-60 seconds during processing
111
+ * - Check queue_position if status is 'queued' to estimate wait time
112
+ * - Stop polling once status is 'completed' or 'failed'
113
+ * - Use GET /v2/prompt/adaptResults to retrieve results after completion
114
+ *
115
+ * **Queue Position:**
116
+ *
117
+ * - Only present when status is 'queued'
118
+ * - Lower numbers mean earlier processing (position 1 is next)
119
+ * - Typical wait time: 1-5 minutes per position
120
+ *
121
+ * **Note:** This endpoint only returns status information. To get the actual
122
+ * adapted prompts and evaluation results, use GET /v2/prompt/adaptResults once
123
+ * status is 'completed'.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * const response = await client.prompt.getAdaptStatus(
128
+ * 'adaptation_run_id',
129
+ * );
130
+ * ```
131
+ */
132
+ getAdaptStatus(
133
+ adaptationRunID: string,
134
+ options?: RequestOptions,
135
+ ): APIPromise<PromptGetAdaptStatusResponse> {
136
+ return this._client.get(path`/v2/prompt/adaptStatus/${adaptationRunID}`, options);
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Status enum for asynchronous jobs (prompt adaptation, custom router training,
142
+ * etc.).
143
+ *
144
+ * Represents the current state of a long-running operation:
145
+ *
146
+ * - **created**: Job has been initialized but not yet queued
147
+ * - **queued**: Job is waiting in the queue to be processed
148
+ * - **processing**: Job is currently being executed
149
+ * - **completed**: Job finished successfully and results are available
150
+ * - **failed**: Job encountered an error and did not complete
151
+ */
152
+ export type JobStatus = 'created' | 'queued' | 'processing' | 'completed' | 'failed';
153
+
154
+ /**
155
+ * Response model for GET /v2/prompt/adaptResults/{adaptation_run_id} endpoint.
156
+ *
157
+ * Contains the complete results of a prompt adaptation run, including optimized
158
+ * prompts and evaluation metrics for all target models. Use this to retrieve your
159
+ * adapted prompts after the adaptation status is 'completed'.
160
+ *
161
+ * The response includes:
162
+ *
163
+ * - Baseline performance of your original prompt on the origin model
164
+ * - Optimized prompts for each target model with pre/post optimization scores
165
+ * - Evaluation metrics and cost information for each model
166
+ */
167
+ export interface PromptGetAdaptResultsResponse {
168
+ /**
169
+ * Unique ID for this adaptation run
170
+ */
171
+ id: string;
172
+
173
+ /**
174
+ * Timestamp when this adaptation run was created
175
+ */
176
+ created_at: string;
177
+
178
+ /**
179
+ * Overall status of the adaptation run (queued, running, completed, failed)
180
+ */
181
+ job_status: JobStatus;
182
+
183
+ /**
184
+ * Results for each target model with optimized prompts and improvement scores
185
+ */
186
+ target_models: Array<PromptGetAdaptResultsResponse.TargetModel>;
187
+
188
+ /**
189
+ * Timestamp of last update to this adaptation run
190
+ */
191
+ updated_at: string | null;
192
+
193
+ evaluation_config?: string | null;
194
+
195
+ evaluation_metric?: string | null;
196
+
197
+ /**
198
+ * Metrics for the LLM requests made during the adaptation run (e.g.,
199
+ * total_requests, avg_latency)
200
+ */
201
+ llm_request_metrics?: { [key: string]: number };
202
+
203
+ /**
204
+ * Baseline results for the origin model in prompt adaptation.
205
+ *
206
+ * Part of AdaptationRunResultsResponse. Contains the performance metrics and
207
+ * prompt configuration for your original prompt on the origin model. This serves
208
+ * as the baseline to compare against optimized prompts for target models.
209
+ *
210
+ * **Fields include:**
211
+ *
212
+ * - Original system prompt and user message template
213
+ * - Baseline performance score and evaluation metrics
214
+ * - Cost of running the baseline evaluation
215
+ * - Job status for the origin model evaluation
216
+ */
217
+ origin_model?: PromptGetAdaptResultsResponse.OriginModel | null;
218
+ }
219
+
220
+ export namespace PromptGetAdaptResultsResponse {
221
+ /**
222
+ * Optimized prompt results for a single target model in prompt adaptation.
223
+ *
224
+ * Part of AdaptationRunResultsResponse. Contains the optimized system prompt and
225
+ * user message template for a specific target model, along with performance scores
226
+ * before and after optimization. Use these optimized prompts with the target model
227
+ * to achieve better performance than the original prompt.
228
+ *
229
+ * **Key metrics:**
230
+ *
231
+ * - **pre_optimization_score**: Performance with original prompt on this target
232
+ * model
233
+ * - **post_optimization_score**: Performance with optimized prompt on this target
234
+ * model
235
+ * - **Score improvement**: post - pre shows how much optimization helped
236
+ *
237
+ * **Usage:**
238
+ *
239
+ * 1. Extract the optimized system_prompt and user_message_template
240
+ * 2. Replace placeholders in user_message_template using fields from your data
241
+ * 3. Use these prompts when calling this target model
242
+ * 4. Compare pre/post scores to see improvement gained
243
+ */
244
+ export interface TargetModel {
245
+ cost: number | null;
246
+
247
+ model_name: string;
248
+
249
+ post_optimization_evals: { [key: string]: unknown } | null;
250
+
251
+ post_optimization_score: number | null;
252
+
253
+ pre_optimization_evals: { [key: string]: unknown } | null;
254
+
255
+ pre_optimization_score: number | null;
256
+
257
+ task_type: string | null;
258
+
259
+ /**
260
+ * Status enum for asynchronous jobs (prompt adaptation, custom router training,
261
+ * etc.).
262
+ *
263
+ * Represents the current state of a long-running operation:
264
+ *
265
+ * - **created**: Job has been initialized but not yet queued
266
+ * - **queued**: Job is waiting in the queue to be processed
267
+ * - **processing**: Job is currently being executed
268
+ * - **completed**: Job finished successfully and results are available
269
+ * - **failed**: Job encountered an error and did not complete
270
+ */
271
+ result_status?: PromptAPI.JobStatus | null;
272
+
273
+ /**
274
+ * Optimized system prompt for this target model. Use this as the system message in
275
+ * your LLM calls
276
+ */
277
+ system_prompt?: string | null;
278
+
279
+ /**
280
+ * Optimized user message template with placeholders. Substitute fields using your
281
+ * data before calling the LLM
282
+ */
283
+ user_message_template?: string | null;
284
+
285
+ /**
286
+ * List of field names to substitute in the template (e.g., ['question',
287
+ * 'context']). These match the curly-brace placeholders in user_message_template
288
+ */
289
+ user_message_template_fields?: Array<string> | null;
290
+ }
291
+
292
+ /**
293
+ * Baseline results for the origin model in prompt adaptation.
294
+ *
295
+ * Part of AdaptationRunResultsResponse. Contains the performance metrics and
296
+ * prompt configuration for your original prompt on the origin model. This serves
297
+ * as the baseline to compare against optimized prompts for target models.
298
+ *
299
+ * **Fields include:**
300
+ *
301
+ * - Original system prompt and user message template
302
+ * - Baseline performance score and evaluation metrics
303
+ * - Cost of running the baseline evaluation
304
+ * - Job status for the origin model evaluation
305
+ */
306
+ export interface OriginModel {
307
+ cost: number | null;
308
+
309
+ evals: { [key: string]: unknown } | null;
310
+
311
+ model_name: string | null;
312
+
313
+ score: number | null;
314
+
315
+ /**
316
+ * Status enum for asynchronous jobs (prompt adaptation, custom router training,
317
+ * etc.).
318
+ *
319
+ * Represents the current state of a long-running operation:
320
+ *
321
+ * - **created**: Job has been initialized but not yet queued
322
+ * - **queued**: Job is waiting in the queue to be processed
323
+ * - **processing**: Job is currently being executed
324
+ * - **completed**: Job finished successfully and results are available
325
+ * - **failed**: Job encountered an error and did not complete
326
+ */
327
+ result_status?: PromptAPI.JobStatus | null;
328
+
329
+ /**
330
+ * Original system prompt used for the origin model
331
+ */
332
+ system_prompt?: string | null;
333
+
334
+ /**
335
+ * Original user message template used for the origin model
336
+ */
337
+ user_message_template?: string | null;
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Response model for GET /v2/prompt/adaptStatus/{adaptation_run_id} endpoint.
343
+ *
344
+ * Returns the current status of an asynchronous prompt adaptation job. Poll this
345
+ * endpoint periodically to track progress. When status is 'completed', you can
346
+ * retrieve the optimized prompts using the /adaptResults endpoint.
347
+ *
348
+ * **Status values:**
349
+ *
350
+ * - **created**: Job has been initialized
351
+ * - **queued**: Waiting in queue (check queue_position for your place in line)
352
+ * - **processing**: Currently running optimization
353
+ * - **completed**: Finished successfully, results available via /adaptResults
354
+ * - **failed**: Encountered an error during processing
355
+ *
356
+ * **Polling recommendations:**
357
+ *
358
+ * - Poll every 30-60 seconds while status is incomplete
359
+ * - Stop polling once status is 'completed' or 'failed'
360
+ * - Adaptation typically takes 10-30 minutes total
361
+ */
362
+ export interface PromptGetAdaptStatusResponse {
363
+ /**
364
+ * Unique identifier for this adaptation run. Use this to poll status and retrieve
365
+ * optimized prompts when complete
366
+ */
367
+ adaptation_run_id: string;
368
+
369
+ /**
370
+ * Current status of the adaptation run. Poll until this is 'completed' or 'failed'
371
+ */
372
+ status: JobStatus;
373
+
374
+ /**
375
+ * Position in queue when status is 'queued'. Lower numbers process sooner. Null
376
+ * when not queued
377
+ */
378
+ queue_position?: number | null;
379
+ }
380
+
381
+ Prompt.Adapt = Adapt;
382
+
383
+ export declare namespace Prompt {
384
+ export {
385
+ type JobStatus as JobStatus,
386
+ type PromptGetAdaptResultsResponse as PromptGetAdaptResultsResponse,
387
+ type PromptGetAdaptStatusResponse as PromptGetAdaptStatusResponse,
388
+ };
389
+
390
+ export {
391
+ Adapt as Adapt,
392
+ type GoldenRecord as GoldenRecord,
393
+ type RequestProvider as RequestProvider,
394
+ type AdaptCreateResponse as AdaptCreateResponse,
395
+ type AdaptGetCostsResponse as AdaptGetCostsResponse,
396
+ type AdaptCreateParams as AdaptCreateParams,
397
+ };
398
+ }
@@ -0,0 +1,3 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export * from './prompt/index';
@@ -0,0 +1,273 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import { APIPromise } from '../core/api-promise';
5
+ import { type Uploadable } from '../core/uploads';
6
+ import { buildHeaders } from '../internal/headers';
7
+ import { RequestOptions } from '../internal/request-options';
8
+ import { multipartFormRequestOptions } from '../internal/uploads';
9
+
10
+ export class Pzn extends APIResource {
11
+ /**
12
+ * Submit a survey response for personalized routing setup.
13
+ *
14
+ * This admin endpoint processes survey responses to set up personalized routing
15
+ * configurations for users based on their use case, LLM preferences, and
16
+ * constraints.
17
+ *
18
+ * **Survey Data:**
19
+ *
20
+ * - User information and use case description
21
+ * - Preferred LLM providers and models
22
+ * - Constraint priorities (quality, cost, latency)
23
+ * - Optional prompts and evaluation datasets
24
+ *
25
+ * **File Uploads:**
26
+ *
27
+ * - `prompt_file`: Optional CSV file with prompts
28
+ * - `dataset_file`: Optional CSV file with evaluation dataset
29
+ *
30
+ * **Note:** This is an admin-only endpoint for internal use.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const response = await client.pzn.submitSurveyResponse({
35
+ * constraint_priorities: 'constraint_priorities',
36
+ * email: 'email',
37
+ * llm_providers: 'llm_providers',
38
+ * use_case_desc: 'use_case_desc',
39
+ * user_id: 'user_id',
40
+ * 'x-token': 'x-token',
41
+ * });
42
+ * ```
43
+ */
44
+ submitSurveyResponse(params: PznSubmitSurveyResponseParams, options?: RequestOptions): APIPromise<unknown> {
45
+ const { 'x-token': xToken, ...body } = params;
46
+ return this._client.post(
47
+ '/v2/pzn/surveyResponse',
48
+ multipartFormRequestOptions(
49
+ { body, ...options, headers: buildHeaders([{ 'x-token': xToken }, options?.headers]) },
50
+ this._client,
51
+ ),
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Train a custom router on your evaluation data to optimize routing for your
57
+ * specific use case.
58
+ *
59
+ * This endpoint allows you to train a domain-specific router that learns which
60
+ * models perform best for different types of queries in your application. The
61
+ * router analyzes your evaluation dataset, clusters similar queries, and learns
62
+ * model performance patterns.
63
+ *
64
+ * **Training Process:**
65
+ *
66
+ * 1. Upload a CSV file with your evaluation data
67
+ * 2. Specify which models to route between
68
+ * 3. Define the evaluation metric (score column)
69
+ * 4. The system trains asynchronously and returns a preference_id
70
+ * 5. Use the preference_id in model_select() calls once training completes
71
+ *
72
+ * **Dataset Requirements:**
73
+ *
74
+ * - Format: CSV file
75
+ * - Minimum samples: 25 (more is better for accuracy)
76
+ * - Required columns:
77
+ * - Prompt column (specified in prompt_column parameter)
78
+ * - For each model: `{provider}/{model}/score` and `{provider}/{model}/response`
79
+ *
80
+ * **Example CSV structure:**
81
+ *
82
+ * ```
83
+ * prompt,openai/gpt-4o/score,openai/gpt-4o/response,anthropic/claude-sonnet-4-5-20250929/score,anthropic/claude-sonnet-4-5-20250929/response
84
+ * "Explain quantum computing",0.95,"Quantum computing uses...",0.87,"Quantum computers leverage..."
85
+ * "Write a Python function",0.82,"def my_function()...",0.91,"Here's a Python function..."
86
+ * ```
87
+ *
88
+ * **Model Selection:**
89
+ *
90
+ * - Specify standard models: `{"provider": "openai", "model": "gpt-4o"}`
91
+ * - Or custom models with pricing:
92
+ * `{"provider": "custom", "model": "my-model", "is_custom": true, "input_price": 10.0, "output_price": 30.0, "context_length": 8192, "latency": 1.5}`
93
+ *
94
+ * **Training Time:**
95
+ *
96
+ * - Training is asynchronous and typically takes 5-15 minutes
97
+ * - Larger datasets or more models take longer
98
+ * - You'll receive a preference_id immediately
99
+ * - Check training status by attempting to use the preference_id in model_select()
100
+ *
101
+ * **Best Practices:**
102
+ *
103
+ * 1. Use diverse, representative examples from your production workload
104
+ * 2. Include at least 50-100 samples for best results
105
+ * 3. Ensure consistent evaluation metrics across all models
106
+ * 4. Use the same models you plan to route between in production
107
+ *
108
+ * **Related Documentation:** See
109
+ * https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed
110
+ * guide.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const response = await client.pzn.trainCustomRouter({
115
+ * dataset_file: fs.createReadStream('path/to/file'),
116
+ * language: 'english',
117
+ * llm_providers:
118
+ * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
119
+ * maximize: true,
120
+ * prompt_column: 'prompt',
121
+ * });
122
+ * ```
123
+ */
124
+ trainCustomRouter(
125
+ body: PznTrainCustomRouterParams,
126
+ options?: RequestOptions,
127
+ ): APIPromise<PznTrainCustomRouterResponse> {
128
+ return this._client.post(
129
+ '/v2/pzn/trainCustomRouter',
130
+ multipartFormRequestOptions({ body, ...options }, this._client),
131
+ );
132
+ }
133
+ }
134
+
135
+ export type PznSubmitSurveyResponseResponse = unknown;
136
+
137
+ /**
138
+ * Response model for POST /v2/pzn/trainCustomRouter endpoint.
139
+ *
140
+ * Returned immediately after submitting a custom router training request. The
141
+ * training process runs asynchronously (typically 5-15 minutes), so use the
142
+ * returned preference_id to make routing calls once training completes.
143
+ *
144
+ * **Next steps:**
145
+ *
146
+ * 1. Store the preference_id
147
+ * 2. Wait for training to complete (typically 5-15 minutes)
148
+ * 3. Use this preference_id in POST /v2/modelRouter/modelSelect requests
149
+ * 4. The router will use your custom-trained model to make routing decisions
150
+ *
151
+ * **How to use the preference_id:**
152
+ *
153
+ * - Include it in the 'preference_id' field of model_select() calls
154
+ * - The system automatically uses your custom router once training is complete
155
+ * - No need to poll status - you can start using it immediately (will use default
156
+ * until ready)
157
+ */
158
+ export interface PznTrainCustomRouterResponse {
159
+ /**
160
+ * Unique identifier for the custom router. Use this in model_select() calls to
161
+ * enable routing with your custom-trained router
162
+ */
163
+ preference_id: string;
164
+ }
165
+
166
+ export interface PznSubmitSurveyResponseParams {
167
+ /**
168
+ * Body param: JSON string of constraint priorities object
169
+ */
170
+ constraint_priorities: string;
171
+
172
+ /**
173
+ * Body param: User email address
174
+ */
175
+ email: string;
176
+
177
+ /**
178
+ * Body param: JSON string of LLM providers array
179
+ */
180
+ llm_providers: string;
181
+
182
+ /**
183
+ * Body param: Description of the user's use case
184
+ */
185
+ use_case_desc: string;
186
+
187
+ /**
188
+ * Body param: User ID from Supabase
189
+ */
190
+ user_id: string;
191
+
192
+ /**
193
+ * Header param:
194
+ */
195
+ 'x-token': string;
196
+
197
+ /**
198
+ * Body param: Optional additional preferences text
199
+ */
200
+ additional_preferences?: string | null;
201
+
202
+ /**
203
+ * Body param: Optional CSV file with evaluation dataset
204
+ */
205
+ dataset_file?: Uploadable | null;
206
+
207
+ /**
208
+ * Body param: Optional preference name
209
+ */
210
+ name?: string | null;
211
+
212
+ /**
213
+ * Body param: Optional CSV file with prompts
214
+ */
215
+ prompt_file?: Uploadable | null;
216
+
217
+ /**
218
+ * Body param: Optional JSON string of prompts array
219
+ */
220
+ prompts?: string | null;
221
+ }
222
+
223
+ export interface PznTrainCustomRouterParams {
224
+ /**
225
+ * CSV file containing evaluation data with prompt column and score/response
226
+ * columns for each model
227
+ */
228
+ dataset_file: Uploadable;
229
+
230
+ /**
231
+ * Language of the evaluation data. Use 'english' for English-only data or
232
+ * 'multilingual' for multi-language support
233
+ */
234
+ language: string;
235
+
236
+ /**
237
+ * JSON string array of LLM providers to train the router on. Format:
238
+ * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model":
239
+ * "claude-sonnet-4-5-20250929"}]'
240
+ */
241
+ llm_providers: string;
242
+
243
+ /**
244
+ * Whether higher scores are better. Set to true if higher scores indicate better
245
+ * performance, false otherwise
246
+ */
247
+ maximize: boolean;
248
+
249
+ /**
250
+ * Name of the column in the CSV file that contains the prompts
251
+ */
252
+ prompt_column: string;
253
+
254
+ /**
255
+ * Whether to override an existing custom router for this preference_id
256
+ */
257
+ override?: boolean | null;
258
+
259
+ /**
260
+ * Optional preference ID to update an existing router. If not provided, a new
261
+ * preference will be created
262
+ */
263
+ preference_id?: string | null;
264
+ }
265
+
266
+ export declare namespace Pzn {
267
+ export {
268
+ type PznSubmitSurveyResponseResponse as PznSubmitSurveyResponseResponse,
269
+ type PznTrainCustomRouterResponse as PznTrainCustomRouterResponse,
270
+ type PznSubmitSurveyResponseParams as PznSubmitSurveyResponseParams,
271
+ type PznTrainCustomRouterParams as PznTrainCustomRouterParams,
272
+ };
273
+ }
@@ -0,0 +1,4 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export { Metrics, type MetricSubmitFeedbackResponse, type MetricSubmitFeedbackParams } from './metrics';
4
+ export { Report } from './report';