notdiamond 0.3.2 → 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 +14 -3
- package/dist/index.cjs +15 -2
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +15 -2
- package/package.json +1 -1
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.
|
|
19
|
+
const version = "0.3.2";
|
|
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;
|
|
@@ -72,7 +72,20 @@ class NotDiamond {
|
|
|
72
72
|
console.log("Calling modelSelect with options:", options);
|
|
73
73
|
const requestBody = {
|
|
74
74
|
messages: options.messages,
|
|
75
|
-
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
|
+
})),
|
|
76
89
|
...options.tradeoff && {
|
|
77
90
|
tradeoff: options.tradeoff
|
|
78
91
|
},
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as dotenv from 'dotenv';
|
|
2
2
|
|
|
3
|
-
const version = "0.3.
|
|
3
|
+
const version = "0.3.2";
|
|
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;
|
|
@@ -56,7 +56,20 @@ class NotDiamond {
|
|
|
56
56
|
console.log("Calling modelSelect with options:", options);
|
|
57
57
|
const requestBody = {
|
|
58
58
|
messages: options.messages,
|
|
59
|
-
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
|
+
})),
|
|
60
73
|
...options.tradeoff && {
|
|
61
74
|
tradeoff: options.tradeoff
|
|
62
75
|
},
|