notdiamond 2.0.0-rc2 → 2.0.0-rc4

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 +37 -0
  2. package/README.md +14 -16
  3. package/client.d.mts +21 -35
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +21 -35
  6. package/client.d.ts.map +1 -1
  7. package/client.js +23 -39
  8. package/client.js.map +1 -1
  9. package/client.mjs +23 -39
  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 +71 -120
  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
@@ -1,476 +0,0 @@
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 Routing extends APIResource {
11
- /**
12
- * Survey Response
13
- *
14
- * @example
15
- * ```ts
16
- * const response = await client.routing.createSurveyResponse({
17
- * constraint_priorities: 'constraint_priorities',
18
- * email: 'email',
19
- * llm_providers: 'llm_providers',
20
- * use_case_desc: 'use_case_desc',
21
- * user_id: 'user_id',
22
- * 'x-token': 'x-token',
23
- * });
24
- * ```
25
- */
26
- createSurveyResponse(
27
- params: RoutingCreateSurveyResponseParams,
28
- options?: RequestOptions,
29
- ): APIPromise<unknown> {
30
- const { 'x-token': xToken, ...body } = params;
31
- return this._client.post(
32
- '/v2/pzn/surveyResponse',
33
- multipartFormRequestOptions(
34
- { body, ...options, headers: buildHeaders([{ 'x-token': xToken }, options?.headers]) },
35
- this._client,
36
- ),
37
- );
38
- }
39
-
40
- /**
41
- * Select the optimal LLM to handle your query based on Not Diamond's routing
42
- * algorithm.
43
- *
44
- * This endpoint analyzes your messages and returns the best-suited model from your
45
- * specified providers. The router considers factors like query complexity, model
46
- * capabilities, cost, and latency based on your preferences.
47
- *
48
- * **Key Features:**
49
- *
50
- * - Intelligent routing across multiple LLM providers
51
- * - Support for custom routers trained on your evaluation data
52
- * - Optional cost/latency optimization
53
- * - Function calling support for compatible models
54
- * - Privacy-preserving content hashing
55
- *
56
- * **Usage:**
57
- *
58
- * 1. Pass your messages in OpenAI format (array of objects with 'role' and
59
- * 'content')
60
- * 2. Specify which LLM providers you want to route between
61
- * 3. Optionally provide a preference_id for personalized routing
62
- * 4. Receive a recommended model and session_id
63
- * 5. Use the session_id to submit feedback and improve routing
64
- *
65
- * **Related Endpoints:**
66
- *
67
- * - `POST /v2/preferences/userPreferenceCreate` - Create a preference ID for
68
- * personalized routing
69
- * - `POST /v2/report/metrics/feedback` - Submit feedback on routing decisions
70
- * - `POST /v2/pzn/trainCustomRouter` - Train a custom router on your evaluation
71
- * data
72
- *
73
- * @example
74
- * ```ts
75
- * const response = await client.routing.selectModel({
76
- * llm_providers: [
77
- * { provider: 'openai', model: 'gpt-4o' },
78
- * {
79
- * provider: 'anthropic',
80
- * model: 'claude-sonnet-4-5-20250929',
81
- * },
82
- * { provider: 'google', model: 'gemini-1.5-pro' },
83
- * ],
84
- * messages: [
85
- * {
86
- * role: 'system',
87
- * content: 'You are a helpful assistant.',
88
- * },
89
- * {
90
- * role: 'user',
91
- * content: 'Explain quantum computing in simple terms',
92
- * },
93
- * ],
94
- * });
95
- * ```
96
- */
97
- selectModel(
98
- params: RoutingSelectModelParams,
99
- options?: RequestOptions,
100
- ): APIPromise<RoutingSelectModelResponse> {
101
- const { type, ...body } = params;
102
- return this._client.post('/v2/modelRouter/modelSelect', { query: { type }, body, ...options });
103
- }
104
-
105
- /**
106
- * Train a custom router on your evaluation data to optimize routing for your
107
- * specific use case.
108
- *
109
- * This endpoint allows you to train a domain-specific router that learns which
110
- * models perform best for different types of queries in your application. The
111
- * router analyzes your evaluation dataset, clusters similar queries, and learns
112
- * model performance patterns.
113
- *
114
- * **Training Process:**
115
- *
116
- * 1. Upload a CSV file with your evaluation data
117
- * 2. Specify which models to route between
118
- * 3. Define the evaluation metric (score column)
119
- * 4. The system trains asynchronously and returns a preference_id
120
- * 5. Use the preference_id in model_select() calls once training completes
121
- *
122
- * **Dataset Requirements:**
123
- *
124
- * - Format: CSV file
125
- * - Minimum samples: 25 (more is better for accuracy)
126
- * - Required columns:
127
- * - Prompt column (specified in prompt_column parameter)
128
- * - For each model: `{provider}/{model}/score` and `{provider}/{model}/response`
129
- *
130
- * **Example CSV structure:**
131
- *
132
- * ```
133
- * prompt,openai/gpt-4o/score,openai/gpt-4o/response,anthropic/claude-sonnet-4-5-20250929/score,anthropic/claude-sonnet-4-5-20250929/response
134
- * "Explain quantum computing",0.95,"Quantum computing uses...",0.87,"Quantum computers leverage..."
135
- * "Write a Python function",0.82,"def my_function()...",0.91,"Here's a Python function..."
136
- * ```
137
- *
138
- * **Model Selection:**
139
- *
140
- * - Specify standard models: `{"provider": "openai", "model": "gpt-4o"}`
141
- * - Or custom models with pricing:
142
- * `{"provider": "custom", "model": "my-model", "is_custom": true, "input_price": 10.0, "output_price": 30.0, "context_length": 8192, "latency": 1.5}`
143
- *
144
- * **Training Time:**
145
- *
146
- * - Training is asynchronous and typically takes 5-15 minutes
147
- * - Larger datasets or more models take longer
148
- * - You'll receive a preference_id immediately
149
- * - Check training status by attempting to use the preference_id in model_select()
150
- *
151
- * **Best Practices:**
152
- *
153
- * 1. Use diverse, representative examples from your production workload
154
- * 2. Include at least 50-100 samples for best results
155
- * 3. Ensure consistent evaluation metrics across all models
156
- * 4. Use the same models you plan to route between in production
157
- *
158
- * **Related Documentation:** See
159
- * https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed
160
- * guide.
161
- *
162
- * @example
163
- * ```ts
164
- * const response = await client.routing.trainCustomRouter({
165
- * dataset_file: fs.createReadStream('path/to/file'),
166
- * language: 'english',
167
- * llm_providers:
168
- * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
169
- * maximize: true,
170
- * prompt_column: 'prompt',
171
- * });
172
- * ```
173
- */
174
- trainCustomRouter(
175
- body: RoutingTrainCustomRouterParams,
176
- options?: RequestOptions,
177
- ): APIPromise<RoutingTrainCustomRouterResponse> {
178
- return this._client.post(
179
- '/v2/pzn/trainCustomRouter',
180
- multipartFormRequestOptions({ body, ...options }, this._client),
181
- );
182
- }
183
- }
184
-
185
- export type RoutingCreateSurveyResponseResponse = unknown;
186
-
187
- /**
188
- * Response from model selection endpoint.
189
- */
190
- export interface RoutingSelectModelResponse {
191
- /**
192
- * List containing the selected provider
193
- */
194
- providers: Array<RoutingSelectModelResponse.Provider>;
195
-
196
- /**
197
- * Unique session ID for this routing decision
198
- */
199
- session_id: string;
200
- }
201
-
202
- export namespace RoutingSelectModelResponse {
203
- /**
204
- * Selected LLM provider information.
205
- */
206
- export interface Provider {
207
- /**
208
- * Model name
209
- */
210
- model: string;
211
-
212
- /**
213
- * Provider name
214
- */
215
- provider: string;
216
- }
217
- }
218
-
219
- /**
220
- * Response from custom router training endpoint.
221
- */
222
- export interface RoutingTrainCustomRouterResponse {
223
- /**
224
- * The preference ID for the custom router. Training happens asynchronously - use
225
- * this ID to check status and make routing calls once training is complete
226
- */
227
- preference_id: string;
228
- }
229
-
230
- export interface RoutingCreateSurveyResponseParams {
231
- /**
232
- * Body param:
233
- */
234
- constraint_priorities: string;
235
-
236
- /**
237
- * Body param:
238
- */
239
- email: string;
240
-
241
- /**
242
- * Body param:
243
- */
244
- llm_providers: string;
245
-
246
- /**
247
- * Body param:
248
- */
249
- use_case_desc: string;
250
-
251
- /**
252
- * Body param:
253
- */
254
- user_id: string;
255
-
256
- /**
257
- * Header param:
258
- */
259
- 'x-token': string;
260
-
261
- /**
262
- * Body param:
263
- */
264
- additional_preferences?: string | null;
265
-
266
- /**
267
- * Body param:
268
- */
269
- dataset_file?: Uploadable | null;
270
-
271
- /**
272
- * Body param:
273
- */
274
- name?: string | null;
275
-
276
- /**
277
- * Body param:
278
- */
279
- prompt_file?: Uploadable | null;
280
-
281
- /**
282
- * Body param:
283
- */
284
- prompts?: string | null;
285
- }
286
-
287
- export interface RoutingSelectModelParams {
288
- /**
289
- * Body param: List of LLM providers to route between. Specify at least one
290
- * provider in format {provider, model}
291
- */
292
- llm_providers: Array<
293
- RoutingSelectModelParams.RequestProvider | RoutingSelectModelParams.OpenRouterProvider
294
- >;
295
-
296
- /**
297
- * Body param: Array of message objects in OpenAI format (with 'role' and 'content'
298
- * keys)
299
- */
300
- messages: Array<{ [key: string]: string | Array<unknown> }> | string;
301
-
302
- /**
303
- * Query param: Optional format type. Use 'openrouter' to accept and return
304
- * OpenRouter-format model identifiers
305
- */
306
- type?: string | null;
307
-
308
- /**
309
- * Body param: Whether to hash message content for privacy
310
- */
311
- hash_content?: boolean;
312
-
313
- /**
314
- * Body param: Maximum number of models to consider for routing. If not specified,
315
- * considers all provided models
316
- */
317
- max_model_depth?: number | null;
318
-
319
- /**
320
- * Body param: Optimization metric for model selection
321
- */
322
- metric?: string;
323
-
324
- /**
325
- * Body param: Preference ID for personalized routing. Create one via POST
326
- * /v2/preferences/userPreferenceCreate
327
- */
328
- preference_id?: string | null;
329
-
330
- /**
331
- * Body param: Previous session ID to link related requests
332
- */
333
- previous_session?: string | null;
334
-
335
- /**
336
- * Body param: OpenAI-format function calling tools
337
- */
338
- tools?: Array<{ [key: string]: unknown }> | null;
339
-
340
- /**
341
- * Body param: Optimization tradeoff strategy. Use 'cost' to prioritize cost
342
- * savings or 'latency' to prioritize speed
343
- */
344
- tradeoff?: string | null;
345
- }
346
-
347
- export namespace RoutingSelectModelParams {
348
- /**
349
- * Model for specifying an LLM provider in API requests.
350
- */
351
- export interface RequestProvider {
352
- /**
353
- * Model name (e.g., 'gpt-4o', 'claude-sonnet-4-5-20250929')
354
- */
355
- model: string;
356
-
357
- /**
358
- * Provider name (e.g., 'openai', 'anthropic', 'google')
359
- */
360
- provider: string;
361
-
362
- /**
363
- * Maximum context length for the model (required for custom models)
364
- */
365
- context_length?: number | null;
366
-
367
- /**
368
- * Input token price per million tokens in USD (required for custom models)
369
- */
370
- input_price?: number | null;
371
-
372
- /**
373
- * Whether this is a custom model not in Not Diamond's supported model list
374
- */
375
- is_custom?: boolean;
376
-
377
- /**
378
- * Average latency in seconds (required for custom models)
379
- */
380
- latency?: number | null;
381
-
382
- /**
383
- * Output token price per million tokens in USD (required for custom models)
384
- */
385
- output_price?: number | null;
386
- }
387
-
388
- /**
389
- * Model for specifying an LLM provider using OpenRouter format.
390
- */
391
- export interface OpenRouterProvider {
392
- /**
393
- * OpenRouter model identifier in format 'provider/model'
394
- */
395
- model: string;
396
-
397
- /**
398
- * Maximum context length for the model (required for custom models)
399
- */
400
- context_length?: number | null;
401
-
402
- /**
403
- * Input token price per million tokens in USD (required for custom models)
404
- */
405
- input_price?: number | null;
406
-
407
- /**
408
- * Whether this is a custom model not in Not Diamond's supported model list
409
- */
410
- is_custom?: boolean;
411
-
412
- /**
413
- * Average latency in seconds (required for custom models)
414
- */
415
- latency?: number | null;
416
-
417
- /**
418
- * Output token price per million tokens in USD (required for custom models)
419
- */
420
- output_price?: number | null;
421
- }
422
- }
423
-
424
- export interface RoutingTrainCustomRouterParams {
425
- /**
426
- * CSV file containing evaluation data with prompt column and score/response
427
- * columns for each model
428
- */
429
- dataset_file: Uploadable;
430
-
431
- /**
432
- * Language of the evaluation data. Use 'english' for English-only data or
433
- * 'multilingual' for multi-language support
434
- */
435
- language: string;
436
-
437
- /**
438
- * JSON string array of LLM providers to train the router on. Format:
439
- * '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model":
440
- * "claude-sonnet-4-5-20250929"}]'
441
- */
442
- llm_providers: string;
443
-
444
- /**
445
- * Whether higher scores are better. Set to true if higher scores indicate better
446
- * performance, false otherwise
447
- */
448
- maximize: boolean;
449
-
450
- /**
451
- * Name of the column in the CSV file that contains the prompts
452
- */
453
- prompt_column: string;
454
-
455
- /**
456
- * Whether to override an existing custom router for this preference_id
457
- */
458
- override?: boolean | null;
459
-
460
- /**
461
- * Optional preference ID to update an existing router. If not provided, a new
462
- * preference will be created
463
- */
464
- preference_id?: string | null;
465
- }
466
-
467
- export declare namespace Routing {
468
- export {
469
- type RoutingCreateSurveyResponseResponse as RoutingCreateSurveyResponseResponse,
470
- type RoutingSelectModelResponse as RoutingSelectModelResponse,
471
- type RoutingTrainCustomRouterResponse as RoutingTrainCustomRouterResponse,
472
- type RoutingCreateSurveyResponseParams as RoutingCreateSurveyResponseParams,
473
- type RoutingSelectModelParams as RoutingSelectModelParams,
474
- type RoutingTrainCustomRouterParams as RoutingTrainCustomRouterParams,
475
- };
476
- }