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,402 @@
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 { RequestOptions } from '../../internal/request-options';
6
+ import { path } from '../../internal/utils/path';
7
+
8
+ export class Adapt extends APIResource {
9
+ /**
10
+ * Adapt your prompt from one LLM to work optimally across different target LLMs.
11
+ *
12
+ * This endpoint automatically optimizes your prompt (system prompt + user message
13
+ * template) to achieve better performance when switching between different
14
+ * language models. Each model has unique characteristics, and what works well for
15
+ * GPT-4 might not work as well for Claude or Gemini.
16
+ *
17
+ * **How Prompt Adaptation Works:**
18
+ *
19
+ * 1. You provide your current prompt optimized for an origin model
20
+ * 2. You specify target models you want to adapt to
21
+ * 3. You provide evaluation examples (golden records) with expected answers
22
+ * 4. The system runs optimization to find the best prompt for each target model
23
+ * 5. You receive adapted prompts that perform well on your target models
24
+ *
25
+ * **Evaluation Metrics:** Choose either a standard metric or provide custom
26
+ * evaluation:
27
+ *
28
+ * - **Standard metrics**: LLMaaJ:SQL, LLMaaJ:Sem_Sim_1/3/10 (semantic similarity),
29
+ * JSON_Match
30
+ * - **Custom evaluation**: Provide evaluation_config with your own LLM judge,
31
+ * prompt, and cutoff
32
+ *
33
+ * **Dataset Requirements:**
34
+ *
35
+ * - Minimum 25 examples in train_goldens (more examples = better adaptation)
36
+ * - Each example must have fields matching your template placeholders
37
+ * - Supervised evaluation requires 'answer' field in each golden record
38
+ * - Unsupervised evaluation can work without answers
39
+ *
40
+ * **Training Time:**
41
+ *
42
+ * - Processing is asynchronous and typically takes 10-30 minutes
43
+ * - Time depends on: number of target models, dataset size, model availability
44
+ * - Use the returned adaptation_run_id to check status and retrieve results
45
+ *
46
+ * **Subscription Tiers:**
47
+ *
48
+ * - Free: 1 target model
49
+ * - Starter: 3 target models
50
+ * - Startup: 5 target models
51
+ * - Enterprise: 10 target models
52
+ *
53
+ * **Best Practices:**
54
+ *
55
+ * 1. Use diverse, representative examples from your production workload
56
+ * 2. Include examples for best results (25 minimum)
57
+ * 3. Ensure consistent evaluation across all examples
58
+ * 4. Test both train_goldens and test_goldens split for validation
59
+ * 5. Use the same model versions you'll use in production
60
+ *
61
+ * **Example Workflow:**
62
+ *
63
+ * ```
64
+ * 1. POST /v2/prompt/adapt - Submit adaptation request
65
+ * 2. GET /v2/prompt/adaptStatus/{id} - Poll status until completed
66
+ * 3. GET /v2/prompt/adaptResults/{id} - Retrieve optimized prompts
67
+ * 4. Use optimized prompts in production with target models
68
+ * ```
69
+ *
70
+ * **Related Documentation:** See
71
+ * https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed
72
+ * guide.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const adapt = await client.prompt.adapt.create({
77
+ * fields: ['question'],
78
+ * system_prompt: 'You are a helpful assistant that answers questions accurately.',
79
+ * target_models: [
80
+ * { provider: 'anthropic', model: 'claude-sonnet-4-5-20250929' },
81
+ * { provider: 'google', model: 'gemini-1.5-pro' },
82
+ * ],
83
+ * template: 'Question: {question}\nAnswer:',
84
+ * evaluation_metric: 'LLMaaJ:Sem_Sim_3',
85
+ * origin_model: { provider: 'openai', model: 'gpt-4o' },
86
+ * test_goldens: [
87
+ * {
88
+ * fields: { ... },
89
+ * answer: '9',
90
+ * },
91
+ * {
92
+ * fields: { ... },
93
+ * answer: 'Pacific Ocean',
94
+ * },
95
+ * ],
96
+ * train_goldens: [
97
+ * {
98
+ * fields: { ... },
99
+ * answer: '4',
100
+ * },
101
+ * {
102
+ * fields: { ... },
103
+ * answer: 'Paris',
104
+ * },
105
+ * {
106
+ * fields: { ... },
107
+ * answer: 'William Shakespeare',
108
+ * },
109
+ * {
110
+ * fields: { ... },
111
+ * answer: 'Water',
112
+ * },
113
+ * {
114
+ * fields: { ... },
115
+ * answer: '7',
116
+ * },
117
+ * ],
118
+ * });
119
+ * ```
120
+ */
121
+ create(body: AdaptCreateParams, options?: RequestOptions): APIPromise<AdaptCreateResponse> {
122
+ return this._client.post('/v2/prompt/adapt', { body, ...options });
123
+ }
124
+
125
+ /**
126
+ * Get LLM usage costs for a specific prompt adaptation run.
127
+ *
128
+ * This endpoint returns the total cost and detailed usage records for all LLM
129
+ * requests made during a prompt adaptation run. Use this to track costs associated
130
+ * with optimizing prompts for different target models.
131
+ *
132
+ * **Cost Breakdown:**
133
+ *
134
+ * - Total cost across all models used in the adaptation
135
+ * - Individual usage records with provider, model, tokens, and costs
136
+ * - Timestamps for each LLM request
137
+ * - Task type (e.g., optimization, evaluation)
138
+ *
139
+ * **Access Control:**
140
+ *
141
+ * - Only accessible by the user who created the adaptation run
142
+ * - Requires prompt adaptation access
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const response = await client.prompt.adapt.getCosts(
147
+ * 'adaptation_run_id',
148
+ * );
149
+ * ```
150
+ */
151
+ getCosts(adaptationRunID: string, options?: RequestOptions): APIPromise<AdaptGetCostsResponse> {
152
+ return this._client.get(path`/v2/prompt/adapt/${adaptationRunID}/costs`, options);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * A training or test example for prompt adaptation.
158
+ */
159
+ export interface GoldenRecord {
160
+ /**
161
+ * Dictionary mapping field names to their values. Keys must match the fields
162
+ * specified in the template
163
+ */
164
+ fields: { [key: string]: string };
165
+
166
+ /**
167
+ * Expected answer for supervised evaluation. Required for supervised metrics,
168
+ * optional for unsupervised
169
+ */
170
+ answer?: string | null;
171
+ }
172
+
173
+ /**
174
+ * Model for specifying an LLM provider in API requests.
175
+ */
176
+ export interface RequestProvider {
177
+ /**
178
+ * Model name (e.g., 'gpt-4o', 'claude-sonnet-4-5-20250929')
179
+ */
180
+ model: string;
181
+
182
+ /**
183
+ * Provider name (e.g., 'openai', 'anthropic', 'google')
184
+ */
185
+ provider: string;
186
+
187
+ /**
188
+ * Maximum context length for the model (required for custom models)
189
+ */
190
+ context_length?: number | null;
191
+
192
+ /**
193
+ * Input token price per million tokens in USD (required for custom models)
194
+ */
195
+ input_price?: number | null;
196
+
197
+ /**
198
+ * Whether this is a custom model not in Not Diamond's supported model list
199
+ */
200
+ is_custom?: boolean;
201
+
202
+ /**
203
+ * Average latency in seconds (required for custom models)
204
+ */
205
+ latency?: number | null;
206
+
207
+ /**
208
+ * Output token price per million tokens in USD (required for custom models)
209
+ */
210
+ output_price?: number | null;
211
+ }
212
+
213
+ /**
214
+ * Response model for POST /v2/prompt/adapt endpoint.
215
+ *
216
+ * Returned immediately after submitting a prompt adaptation request. The
217
+ * adaptation process runs asynchronously, so use the returned adaptation_run_id to
218
+ * track progress and retrieve results when complete.
219
+ *
220
+ * **Next steps:**
221
+ *
222
+ * 1. Store the adaptation_run_id
223
+ * 2. Poll GET /v2/prompt/adaptStatus/{adaptation_run_id} to check progress
224
+ * 3. When status is 'completed', retrieve optimized prompts from GET
225
+ * /v2/prompt/adaptResults/{adaptation_run_id}
226
+ * 4. Use the optimized prompts with your target models
227
+ */
228
+ export interface AdaptCreateResponse {
229
+ /**
230
+ * Unique identifier for this adaptation run. Use this to poll status and retrieve
231
+ * optimized prompts when complete
232
+ */
233
+ adaptation_run_id: string;
234
+ }
235
+
236
+ /**
237
+ * Response model for GET /v2/prompt/adapt/{adaptation_run_id}/costs endpoint.
238
+ *
239
+ * Contains the total LLM costs and detailed usage records for a prompt adaptation
240
+ * run. Use this to track costs associated with optimizing prompts for different
241
+ * target models.
242
+ */
243
+ export interface AdaptGetCostsResponse {
244
+ /**
245
+ * Unique identifier for the adaptation run
246
+ */
247
+ adaptation_run_id: string;
248
+
249
+ /**
250
+ * Total cost in USD across all LLM requests in this adaptation run
251
+ */
252
+ total_cost: number;
253
+
254
+ /**
255
+ * Detailed usage records for each LLM request made during the adaptation
256
+ */
257
+ usage_records: Array<AdaptGetCostsResponse.UsageRecord>;
258
+ }
259
+
260
+ export namespace AdaptGetCostsResponse {
261
+ /**
262
+ * Individual LLM usage record with token counts and cost breakdown.
263
+ *
264
+ * Returned by GET /llm-usage endpoint and included in AdaptationRunCostResponse.
265
+ * Each record represents a single LLM API call with detailed usage metrics.
266
+ */
267
+ export interface UsageRecord {
268
+ /**
269
+ * Unique identifier for this usage record
270
+ */
271
+ id: string;
272
+
273
+ /**
274
+ * Adaptation run ID this usage is associated with
275
+ */
276
+ adaptation_run_id: string;
277
+
278
+ /**
279
+ * Cost of input tokens in USD
280
+ */
281
+ input_cost: number;
282
+
283
+ /**
284
+ * Number of input tokens consumed
285
+ */
286
+ input_tokens: number;
287
+
288
+ /**
289
+ * Model name (e.g., 'gpt-4', 'claude-3-opus-20240229')
290
+ */
291
+ model: string;
292
+
293
+ /**
294
+ * Organization ID associated with the request
295
+ */
296
+ organization_id: string;
297
+
298
+ /**
299
+ * Cost of output tokens in USD
300
+ */
301
+ output_cost: number;
302
+
303
+ /**
304
+ * Number of output tokens generated
305
+ */
306
+ output_tokens: number;
307
+
308
+ /**
309
+ * LLM provider (e.g., 'openai', 'anthropic', 'google')
310
+ */
311
+ provider: string;
312
+
313
+ /**
314
+ * Type of task (e.g., 'optimization', 'evaluation')
315
+ */
316
+ task_type: string;
317
+
318
+ /**
319
+ * Unix timestamp when the request was made
320
+ */
321
+ timestamp: number;
322
+
323
+ /**
324
+ * Total cost (input + output) in USD
325
+ */
326
+ total_cost: number;
327
+
328
+ /**
329
+ * User ID who made the request
330
+ */
331
+ user_id: string;
332
+ }
333
+ }
334
+
335
+ export interface AdaptCreateParams {
336
+ /**
337
+ * List of field names that will be substituted into the template. Must match keys
338
+ * in golden records
339
+ */
340
+ fields: Array<string>;
341
+
342
+ /**
343
+ * System prompt to use with the origin model. This sets the context and role for
344
+ * the LLM
345
+ */
346
+ system_prompt: string;
347
+
348
+ /**
349
+ * List of models to adapt the prompt for. Maximum count depends on your
350
+ * subscription tier (Free: 1, Starter: 3, Startup: 5, Enterprise: 10)
351
+ */
352
+ target_models: Array<RequestProvider>;
353
+
354
+ /**
355
+ * User message template with placeholders for fields. Use curly braces for field
356
+ * substitution
357
+ */
358
+ template: string;
359
+
360
+ evaluation_config?: string | null;
361
+
362
+ evaluation_metric?: string | null;
363
+
364
+ /**
365
+ * Training examples (legacy parameter). Use train_goldens and test_goldens for
366
+ * better control. Minimum 25 examples
367
+ */
368
+ goldens?: Array<GoldenRecord> | null;
369
+
370
+ /**
371
+ * Model for specifying an LLM provider in API requests.
372
+ */
373
+ origin_model?: RequestProvider | null;
374
+
375
+ /**
376
+ * Optional baseline score for the origin model. If provided, can skip origin model
377
+ * evaluation
378
+ */
379
+ origin_model_evaluation_score?: number | null;
380
+
381
+ /**
382
+ * Test examples for evaluation. Required if train_goldens is provided. Used to
383
+ * measure final performance on held-out data
384
+ */
385
+ test_goldens?: Array<GoldenRecord> | null;
386
+
387
+ /**
388
+ * Training examples for prompt optimization. Minimum 25 examples required. Cannot
389
+ * be used with 'goldens' parameter
390
+ */
391
+ train_goldens?: Array<GoldenRecord> | null;
392
+ }
393
+
394
+ export declare namespace Adapt {
395
+ export {
396
+ type GoldenRecord as GoldenRecord,
397
+ type RequestProvider as RequestProvider,
398
+ type AdaptCreateResponse as AdaptCreateResponse,
399
+ type AdaptGetCostsResponse as AdaptGetCostsResponse,
400
+ type AdaptCreateParams as AdaptCreateParams,
401
+ };
402
+ }
@@ -0,0 +1,16 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export {
4
+ Adapt,
5
+ type GoldenRecord,
6
+ type RequestProvider,
7
+ type AdaptCreateResponse,
8
+ type AdaptGetCostsResponse,
9
+ type AdaptCreateParams,
10
+ } from './adapt';
11
+ export {
12
+ Prompt,
13
+ type JobStatus,
14
+ type PromptGetAdaptResultsResponse,
15
+ type PromptGetAdaptStatusResponse,
16
+ } from './prompt';