notdiamond 0.3.1 → 0.3.3

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 CHANGED
@@ -26,26 +26,35 @@ Here's a simple example of how to use NotDiamond to select the best model betwee
26
26
  import { NotDiamond } from 'notdiamond';
27
27
 
28
28
  const notDiamond = new NotDiamond({
29
+ // Optional - automatically loads from environment variable
29
30
  apiKey: process.env.NOTDIAMOND_API_KEY,
30
31
  });
31
32
 
32
33
  async function basicExample() {
34
+ // 1. Select the best model
33
35
  const result = await notDiamond.modelSelect({
36
+ // Define the user's message
34
37
  messages: [{ content: 'What is 12x12?', role: 'user' }],
38
+ // Specify the LLM providers and models to choose from
35
39
  llmProviders: [
36
40
  { provider: 'openai', model: 'gpt-4o-2024-05-13' },
37
41
  { provider: 'anthropic', model: 'claude-3-5-sonnet-20240620' },
38
42
  { provider: 'google', model: 'gemini-1.5-pro-latest' },
39
43
  ],
44
+ // Set the optimization criteria to latency
40
45
  tradeoff: 'latency',
41
46
  });
42
47
 
48
+ // 2. Handle potential errors
43
49
  if ('detail' in result) {
44
50
  console.error('Error:', result.detail);
45
51
  return;
46
52
  }
47
53
 
54
+ // 3. Log the results
55
+ // Display the selected provider(s)
48
56
  console.log('Selected providers:', result.providers);
57
+ // Show the unique session ID for this request
49
58
  console.log('Session ID:', result.session_id);
50
59
  }
51
60
 
@@ -59,10 +68,9 @@ You can also use NotDiamond with custom tools:
59
68
  ```typescript
60
69
  import { NotDiamond, Tool } from 'notdiamond';
61
70
 
62
- const notDiamond = new NotDiamond({
63
- apiKey: process.env.NOTDIAMOND_API_KEY,
64
- });
71
+ const notDiamond = new NotDiamond();
65
72
 
73
+ // Define custom tools for the AI to use
66
74
  const tools: Tool[] = [
67
75
  {
68
76
  type: 'function',
@@ -88,8 +96,11 @@ async function toolCallingExample() {
88
96
  { provider: 'openai', model: 'gpt-4-1106-preview' },
89
97
  { provider: 'anthropic', model: 'claude-3-sonnet-20240229' },
90
98
  ],
99
+ // Include custom tools in the request
91
100
  tools: tools,
101
+ // Optimize for cost instead of latency
92
102
  tradeoff: 'cost',
103
+ // Allow selection of up to 2 models
93
104
  maxModelDepth: 2,
94
105
  });
95
106
 
package/dist/index.cjs CHANGED
@@ -16,6 +16,8 @@ function _interopNamespaceCompat(e) {
16
16
 
17
17
  const dotenv__namespace = /*#__PURE__*/_interopNamespaceCompat(dotenv);
18
18
 
19
+ const version = "0.3.2";
20
+
19
21
  var __defProp = Object.defineProperty;
20
22
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
21
23
  var __publicField = (obj, key, value) => {
@@ -24,7 +26,7 @@ var __publicField = (obj, key, value) => {
24
26
  };
25
27
  dotenv__namespace.config();
26
28
  const BASE_URL = "https://not-diamond-server.onrender.com";
27
- const MODEL_SELECT_URL = `${BASE_URL}/v2/optimizer/modelSelect`;
29
+ const MODEL_SELECT_URL = `${BASE_URL}/v2/modelRouter/modelSelect`;
28
30
  const FEEDBACK_URL = `${BASE_URL}/v2/report/metrics/feedback`;
29
31
  const DEFAULT_TIMEOUT = 5;
30
32
  class NotDiamond {
@@ -47,7 +49,8 @@ class NotDiamond {
47
49
  headers: {
48
50
  Authorization: this.getAuthHeader(),
49
51
  accept: "application/json",
50
- "content-type": "application/json"
52
+ "content-type": "application/json",
53
+ "User-Agent": `TS-SDK/${version}`
51
54
  },
52
55
  body: JSON.stringify(body)
53
56
  });
@@ -69,7 +72,20 @@ class NotDiamond {
69
72
  console.log("Calling modelSelect with options:", options);
70
73
  const requestBody = {
71
74
  messages: options.messages,
72
- llm_providers: options.llmProviders,
75
+ llm_providers: options.llmProviders.map((provider) => ({
76
+ provider: provider.provider,
77
+ model: provider.model,
78
+ ...provider.contextLength !== void 0 && {
79
+ context_length: provider.contextLength
80
+ },
81
+ ...provider.inputPrice !== void 0 && {
82
+ input_price: provider.inputPrice
83
+ },
84
+ ...provider.outputPrice !== void 0 && {
85
+ output_price: provider.outputPrice
86
+ },
87
+ ...provider.latency !== void 0 && { latency: provider.latency }
88
+ })),
73
89
  ...options.tradeoff && {
74
90
  tradeoff: options.tradeoff
75
91
  },
package/dist/index.d.cts CHANGED
@@ -4,6 +4,10 @@ interface NotDiamondOptions {
4
4
  interface Provider {
5
5
  provider: string;
6
6
  model: string;
7
+ contextLength?: number;
8
+ inputPrice?: number;
9
+ outputPrice?: number;
10
+ latency?: number;
7
11
  }
8
12
  interface NotDiamondErrorResponse {
9
13
  detail: string;
package/dist/index.d.mts CHANGED
@@ -4,6 +4,10 @@ interface NotDiamondOptions {
4
4
  interface Provider {
5
5
  provider: string;
6
6
  model: string;
7
+ contextLength?: number;
8
+ inputPrice?: number;
9
+ outputPrice?: number;
10
+ latency?: number;
7
11
  }
8
12
  interface NotDiamondErrorResponse {
9
13
  detail: string;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,10 @@ interface NotDiamondOptions {
4
4
  interface Provider {
5
5
  provider: string;
6
6
  model: string;
7
+ contextLength?: number;
8
+ inputPrice?: number;
9
+ outputPrice?: number;
10
+ latency?: number;
7
11
  }
8
12
  interface NotDiamondErrorResponse {
9
13
  detail: string;
package/dist/index.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as dotenv from 'dotenv';
2
2
 
3
+ const version = "0.3.2";
4
+
3
5
  var __defProp = Object.defineProperty;
4
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
7
  var __publicField = (obj, key, value) => {
@@ -8,7 +10,7 @@ var __publicField = (obj, key, value) => {
8
10
  };
9
11
  dotenv.config();
10
12
  const BASE_URL = "https://not-diamond-server.onrender.com";
11
- const MODEL_SELECT_URL = `${BASE_URL}/v2/optimizer/modelSelect`;
13
+ const MODEL_SELECT_URL = `${BASE_URL}/v2/modelRouter/modelSelect`;
12
14
  const FEEDBACK_URL = `${BASE_URL}/v2/report/metrics/feedback`;
13
15
  const DEFAULT_TIMEOUT = 5;
14
16
  class NotDiamond {
@@ -31,7 +33,8 @@ class NotDiamond {
31
33
  headers: {
32
34
  Authorization: this.getAuthHeader(),
33
35
  accept: "application/json",
34
- "content-type": "application/json"
36
+ "content-type": "application/json",
37
+ "User-Agent": `TS-SDK/${version}`
35
38
  },
36
39
  body: JSON.stringify(body)
37
40
  });
@@ -53,7 +56,20 @@ class NotDiamond {
53
56
  console.log("Calling modelSelect with options:", options);
54
57
  const requestBody = {
55
58
  messages: options.messages,
56
- llm_providers: options.llmProviders,
59
+ llm_providers: options.llmProviders.map((provider) => ({
60
+ provider: provider.provider,
61
+ model: provider.model,
62
+ ...provider.contextLength !== void 0 && {
63
+ context_length: provider.contextLength
64
+ },
65
+ ...provider.inputPrice !== void 0 && {
66
+ input_price: provider.inputPrice
67
+ },
68
+ ...provider.outputPrice !== void 0 && {
69
+ output_price: provider.outputPrice
70
+ },
71
+ ...provider.latency !== void 0 && { latency: provider.latency }
72
+ })),
57
73
  ...options.tradeoff && {
58
74
  tradeoff: options.tradeoff
59
75
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "notdiamond",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.3.3",
5
5
  "author": "not-diamond",
6
6
  "license": "MIT",
7
7
  "description": "TS/JS client for the NotDiamond API",