notdiamond 0.3.2 → 0.3.4

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,7 +16,7 @@ function _interopNamespaceCompat(e) {
16
16
 
17
17
  const dotenv__namespace = /*#__PURE__*/_interopNamespaceCompat(dotenv);
18
18
 
19
- const version = "0.3.1";
19
+ const version = "0.3.3";
20
20
 
21
21
  var __defProp = Object.defineProperty;
22
22
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -33,16 +33,11 @@ class NotDiamond {
33
33
  constructor(options = {}) {
34
34
  __publicField(this, "apiKey");
35
35
  this.apiKey = options.apiKey || process.env.NOTDIAMOND_API_KEY || "";
36
- console.log("NotDiamond initialized with apiKey:", this.apiKey);
37
36
  }
38
37
  getAuthHeader() {
39
- const authHeader = `Bearer ${this.apiKey}`;
40
- console.log("Generated auth header:", authHeader);
41
- return authHeader;
38
+ return `Bearer ${this.apiKey}`;
42
39
  }
43
40
  async postRequest(url, body) {
44
- console.log("Sending POST request to URL:", url);
45
- console.log("Request body:", body);
46
41
  try {
47
42
  const response = await fetch(url, {
48
43
  method: "POST",
@@ -54,25 +49,32 @@ class NotDiamond {
54
49
  },
55
50
  body: JSON.stringify(body)
56
51
  });
57
- console.log("Response status:", response.status);
58
52
  if (!response.ok) {
59
53
  const errorData = await response.json();
60
- console.error("Error response data:", errorData);
61
54
  return { detail: errorData.detail };
62
55
  }
63
- const responseData = await response.json();
64
- console.log("Response data:", responseData);
65
- return responseData;
56
+ return await response.json();
66
57
  } catch (error) {
67
- console.error("An unexpected error occurred:", error);
68
58
  return { detail: "An unexpected error occurred." };
69
59
  }
70
60
  }
71
61
  async modelSelect(options) {
72
- console.log("Calling modelSelect with options:", options);
73
62
  const requestBody = {
74
63
  messages: options.messages,
75
- llm_providers: options.llmProviders,
64
+ llm_providers: options.llmProviders.map((provider) => ({
65
+ provider: provider.provider,
66
+ model: provider.model,
67
+ ...provider.contextLength !== void 0 && {
68
+ context_length: provider.contextLength
69
+ },
70
+ ...provider.inputPrice !== void 0 && {
71
+ input_price: provider.inputPrice
72
+ },
73
+ ...provider.outputPrice !== void 0 && {
74
+ output_price: provider.outputPrice
75
+ },
76
+ ...provider.latency !== void 0 && { latency: provider.latency }
77
+ })),
76
78
  ...options.tradeoff && {
77
79
  tradeoff: options.tradeoff
78
80
  },
@@ -89,14 +91,12 @@ class NotDiamond {
89
91
  },
90
92
  ...options.default && { default: options.default }
91
93
  };
92
- console.log("Request body:", JSON.stringify(requestBody, null, 2));
93
94
  return this.postRequest(
94
95
  MODEL_SELECT_URL,
95
96
  requestBody
96
97
  );
97
98
  }
98
99
  async feedback(options) {
99
- console.log("Calling feedback with options:", options);
100
100
  return this.postRequest(FEEDBACK_URL, {
101
101
  session_id: options.sessionId,
102
102
  feedback: options.feedback,
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,6 +1,6 @@
1
1
  import * as dotenv from 'dotenv';
2
2
 
3
- const version = "0.3.1";
3
+ const version = "0.3.3";
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -17,16 +17,11 @@ class NotDiamond {
17
17
  constructor(options = {}) {
18
18
  __publicField(this, "apiKey");
19
19
  this.apiKey = options.apiKey || process.env.NOTDIAMOND_API_KEY || "";
20
- console.log("NotDiamond initialized with apiKey:", this.apiKey);
21
20
  }
22
21
  getAuthHeader() {
23
- const authHeader = `Bearer ${this.apiKey}`;
24
- console.log("Generated auth header:", authHeader);
25
- return authHeader;
22
+ return `Bearer ${this.apiKey}`;
26
23
  }
27
24
  async postRequest(url, body) {
28
- console.log("Sending POST request to URL:", url);
29
- console.log("Request body:", body);
30
25
  try {
31
26
  const response = await fetch(url, {
32
27
  method: "POST",
@@ -38,25 +33,32 @@ class NotDiamond {
38
33
  },
39
34
  body: JSON.stringify(body)
40
35
  });
41
- console.log("Response status:", response.status);
42
36
  if (!response.ok) {
43
37
  const errorData = await response.json();
44
- console.error("Error response data:", errorData);
45
38
  return { detail: errorData.detail };
46
39
  }
47
- const responseData = await response.json();
48
- console.log("Response data:", responseData);
49
- return responseData;
40
+ return await response.json();
50
41
  } catch (error) {
51
- console.error("An unexpected error occurred:", error);
52
42
  return { detail: "An unexpected error occurred." };
53
43
  }
54
44
  }
55
45
  async modelSelect(options) {
56
- console.log("Calling modelSelect with options:", options);
57
46
  const requestBody = {
58
47
  messages: options.messages,
59
- llm_providers: options.llmProviders,
48
+ llm_providers: options.llmProviders.map((provider) => ({
49
+ provider: provider.provider,
50
+ model: provider.model,
51
+ ...provider.contextLength !== void 0 && {
52
+ context_length: provider.contextLength
53
+ },
54
+ ...provider.inputPrice !== void 0 && {
55
+ input_price: provider.inputPrice
56
+ },
57
+ ...provider.outputPrice !== void 0 && {
58
+ output_price: provider.outputPrice
59
+ },
60
+ ...provider.latency !== void 0 && { latency: provider.latency }
61
+ })),
60
62
  ...options.tradeoff && {
61
63
  tradeoff: options.tradeoff
62
64
  },
@@ -73,14 +75,12 @@ class NotDiamond {
73
75
  },
74
76
  ...options.default && { default: options.default }
75
77
  };
76
- console.log("Request body:", JSON.stringify(requestBody, null, 2));
77
78
  return this.postRequest(
78
79
  MODEL_SELECT_URL,
79
80
  requestBody
80
81
  );
81
82
  }
82
83
  async feedback(options) {
83
- console.log("Calling feedback with options:", options);
84
84
  return this.postRequest(FEEDBACK_URL, {
85
85
  session_id: options.sessionId,
86
86
  feedback: options.feedback,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "notdiamond",
3
3
  "type": "module",
4
- "version": "0.3.2",
4
+ "version": "0.3.4",
5
5
  "author": "not-diamond",
6
6
  "license": "MIT",
7
7
  "description": "TS/JS client for the NotDiamond API",