notdiamond 0.3.3 → 0.3.5
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/dist/index.cjs +10 -18
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +10 -18
- package/package.json +1 -1
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.4";
|
|
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;
|
|
@@ -25,24 +25,21 @@ var __publicField = (obj, key, value) => {
|
|
|
25
25
|
return value;
|
|
26
26
|
};
|
|
27
27
|
dotenv__namespace.config();
|
|
28
|
+
const DEFAULT_TIMEOUT = 5;
|
|
28
29
|
const BASE_URL = "https://not-diamond-server.onrender.com";
|
|
29
30
|
const MODEL_SELECT_URL = `${BASE_URL}/v2/modelRouter/modelSelect`;
|
|
30
31
|
const FEEDBACK_URL = `${BASE_URL}/v2/report/metrics/feedback`;
|
|
31
|
-
const DEFAULT_TIMEOUT = 5;
|
|
32
32
|
class NotDiamond {
|
|
33
33
|
constructor(options = {}) {
|
|
34
34
|
__publicField(this, "apiKey");
|
|
35
|
+
__publicField(this, "apiUrl");
|
|
35
36
|
this.apiKey = options.apiKey || process.env.NOTDIAMOND_API_KEY || "";
|
|
36
|
-
|
|
37
|
+
this.apiUrl = options.apiUrl || process.env.NOTDIAMOND_API_URL || BASE_URL;
|
|
37
38
|
}
|
|
38
39
|
getAuthHeader() {
|
|
39
|
-
|
|
40
|
-
console.log("Generated auth header:", authHeader);
|
|
41
|
-
return authHeader;
|
|
40
|
+
return `Bearer ${this.apiKey}`;
|
|
42
41
|
}
|
|
43
42
|
async postRequest(url, body) {
|
|
44
|
-
console.log("Sending POST request to URL:", url);
|
|
45
|
-
console.log("Request body:", body);
|
|
46
43
|
try {
|
|
47
44
|
const response = await fetch(url, {
|
|
48
45
|
method: "POST",
|
|
@@ -54,22 +51,16 @@ class NotDiamond {
|
|
|
54
51
|
},
|
|
55
52
|
body: JSON.stringify(body)
|
|
56
53
|
});
|
|
57
|
-
console.log("Response status:", response.status);
|
|
58
54
|
if (!response.ok) {
|
|
59
55
|
const errorData = await response.json();
|
|
60
|
-
console.error("Error response data:", errorData);
|
|
61
56
|
return { detail: errorData.detail };
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
console.log("Response data:", responseData);
|
|
65
|
-
return responseData;
|
|
58
|
+
return await response.json();
|
|
66
59
|
} catch (error) {
|
|
67
|
-
console.error("An unexpected error occurred:", error);
|
|
68
60
|
return { detail: "An unexpected error occurred." };
|
|
69
61
|
}
|
|
70
62
|
}
|
|
71
63
|
async modelSelect(options) {
|
|
72
|
-
console.log("Calling modelSelect with options:", options);
|
|
73
64
|
const requestBody = {
|
|
74
65
|
messages: options.messages,
|
|
75
66
|
llm_providers: options.llmProviders.map((provider) => ({
|
|
@@ -100,16 +91,17 @@ class NotDiamond {
|
|
|
100
91
|
...options.timeout ? { timeout: options.timeout } : {
|
|
101
92
|
timeout: DEFAULT_TIMEOUT
|
|
102
93
|
},
|
|
103
|
-
...options.default && { default: options.default }
|
|
94
|
+
...options.default && { default: options.default },
|
|
95
|
+
...options.previousSession && {
|
|
96
|
+
previous_session: options.previousSession
|
|
97
|
+
}
|
|
104
98
|
};
|
|
105
|
-
console.log("Request body:", JSON.stringify(requestBody, null, 2));
|
|
106
99
|
return this.postRequest(
|
|
107
100
|
MODEL_SELECT_URL,
|
|
108
101
|
requestBody
|
|
109
102
|
);
|
|
110
103
|
}
|
|
111
104
|
async feedback(options) {
|
|
112
|
-
console.log("Calling feedback with options:", options);
|
|
113
105
|
return this.postRequest(FEEDBACK_URL, {
|
|
114
106
|
session_id: options.sessionId,
|
|
115
107
|
feedback: options.feedback,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
interface NotDiamondOptions {
|
|
2
2
|
apiKey?: string;
|
|
3
|
+
apiUrl?: string;
|
|
3
4
|
}
|
|
4
5
|
interface Provider {
|
|
5
6
|
provider: string;
|
|
@@ -35,6 +36,7 @@ interface ModelSelectOptions {
|
|
|
35
36
|
hashContent?: boolean;
|
|
36
37
|
timeout?: number;
|
|
37
38
|
default?: Provider | number | string;
|
|
39
|
+
previousSession?: string;
|
|
38
40
|
}
|
|
39
41
|
interface ModelSelectSuccessResponse {
|
|
40
42
|
providers: Provider[];
|
|
@@ -54,6 +56,7 @@ interface FeedbackSuccessResponse {
|
|
|
54
56
|
}
|
|
55
57
|
declare class NotDiamond {
|
|
56
58
|
private apiKey;
|
|
59
|
+
private apiUrl;
|
|
57
60
|
constructor(options?: NotDiamondOptions);
|
|
58
61
|
private getAuthHeader;
|
|
59
62
|
private postRequest;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
interface NotDiamondOptions {
|
|
2
2
|
apiKey?: string;
|
|
3
|
+
apiUrl?: string;
|
|
3
4
|
}
|
|
4
5
|
interface Provider {
|
|
5
6
|
provider: string;
|
|
@@ -35,6 +36,7 @@ interface ModelSelectOptions {
|
|
|
35
36
|
hashContent?: boolean;
|
|
36
37
|
timeout?: number;
|
|
37
38
|
default?: Provider | number | string;
|
|
39
|
+
previousSession?: string;
|
|
38
40
|
}
|
|
39
41
|
interface ModelSelectSuccessResponse {
|
|
40
42
|
providers: Provider[];
|
|
@@ -54,6 +56,7 @@ interface FeedbackSuccessResponse {
|
|
|
54
56
|
}
|
|
55
57
|
declare class NotDiamond {
|
|
56
58
|
private apiKey;
|
|
59
|
+
private apiUrl;
|
|
57
60
|
constructor(options?: NotDiamondOptions);
|
|
58
61
|
private getAuthHeader;
|
|
59
62
|
private postRequest;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
interface NotDiamondOptions {
|
|
2
2
|
apiKey?: string;
|
|
3
|
+
apiUrl?: string;
|
|
3
4
|
}
|
|
4
5
|
interface Provider {
|
|
5
6
|
provider: string;
|
|
@@ -35,6 +36,7 @@ interface ModelSelectOptions {
|
|
|
35
36
|
hashContent?: boolean;
|
|
36
37
|
timeout?: number;
|
|
37
38
|
default?: Provider | number | string;
|
|
39
|
+
previousSession?: string;
|
|
38
40
|
}
|
|
39
41
|
interface ModelSelectSuccessResponse {
|
|
40
42
|
providers: Provider[];
|
|
@@ -54,6 +56,7 @@ interface FeedbackSuccessResponse {
|
|
|
54
56
|
}
|
|
55
57
|
declare class NotDiamond {
|
|
56
58
|
private apiKey;
|
|
59
|
+
private apiUrl;
|
|
57
60
|
constructor(options?: NotDiamondOptions);
|
|
58
61
|
private getAuthHeader;
|
|
59
62
|
private postRequest;
|
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.4";
|
|
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;
|
|
@@ -9,24 +9,21 @@ var __publicField = (obj, key, value) => {
|
|
|
9
9
|
return value;
|
|
10
10
|
};
|
|
11
11
|
dotenv.config();
|
|
12
|
+
const DEFAULT_TIMEOUT = 5;
|
|
12
13
|
const BASE_URL = "https://not-diamond-server.onrender.com";
|
|
13
14
|
const MODEL_SELECT_URL = `${BASE_URL}/v2/modelRouter/modelSelect`;
|
|
14
15
|
const FEEDBACK_URL = `${BASE_URL}/v2/report/metrics/feedback`;
|
|
15
|
-
const DEFAULT_TIMEOUT = 5;
|
|
16
16
|
class NotDiamond {
|
|
17
17
|
constructor(options = {}) {
|
|
18
18
|
__publicField(this, "apiKey");
|
|
19
|
+
__publicField(this, "apiUrl");
|
|
19
20
|
this.apiKey = options.apiKey || process.env.NOTDIAMOND_API_KEY || "";
|
|
20
|
-
|
|
21
|
+
this.apiUrl = options.apiUrl || process.env.NOTDIAMOND_API_URL || BASE_URL;
|
|
21
22
|
}
|
|
22
23
|
getAuthHeader() {
|
|
23
|
-
|
|
24
|
-
console.log("Generated auth header:", authHeader);
|
|
25
|
-
return authHeader;
|
|
24
|
+
return `Bearer ${this.apiKey}`;
|
|
26
25
|
}
|
|
27
26
|
async postRequest(url, body) {
|
|
28
|
-
console.log("Sending POST request to URL:", url);
|
|
29
|
-
console.log("Request body:", body);
|
|
30
27
|
try {
|
|
31
28
|
const response = await fetch(url, {
|
|
32
29
|
method: "POST",
|
|
@@ -38,22 +35,16 @@ class NotDiamond {
|
|
|
38
35
|
},
|
|
39
36
|
body: JSON.stringify(body)
|
|
40
37
|
});
|
|
41
|
-
console.log("Response status:", response.status);
|
|
42
38
|
if (!response.ok) {
|
|
43
39
|
const errorData = await response.json();
|
|
44
|
-
console.error("Error response data:", errorData);
|
|
45
40
|
return { detail: errorData.detail };
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
console.log("Response data:", responseData);
|
|
49
|
-
return responseData;
|
|
42
|
+
return await response.json();
|
|
50
43
|
} catch (error) {
|
|
51
|
-
console.error("An unexpected error occurred:", error);
|
|
52
44
|
return { detail: "An unexpected error occurred." };
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
47
|
async modelSelect(options) {
|
|
56
|
-
console.log("Calling modelSelect with options:", options);
|
|
57
48
|
const requestBody = {
|
|
58
49
|
messages: options.messages,
|
|
59
50
|
llm_providers: options.llmProviders.map((provider) => ({
|
|
@@ -84,16 +75,17 @@ class NotDiamond {
|
|
|
84
75
|
...options.timeout ? { timeout: options.timeout } : {
|
|
85
76
|
timeout: DEFAULT_TIMEOUT
|
|
86
77
|
},
|
|
87
|
-
...options.default && { default: options.default }
|
|
78
|
+
...options.default && { default: options.default },
|
|
79
|
+
...options.previousSession && {
|
|
80
|
+
previous_session: options.previousSession
|
|
81
|
+
}
|
|
88
82
|
};
|
|
89
|
-
console.log("Request body:", JSON.stringify(requestBody, null, 2));
|
|
90
83
|
return this.postRequest(
|
|
91
84
|
MODEL_SELECT_URL,
|
|
92
85
|
requestBody
|
|
93
86
|
);
|
|
94
87
|
}
|
|
95
88
|
async feedback(options) {
|
|
96
|
-
console.log("Calling feedback with options:", options);
|
|
97
89
|
return this.postRequest(FEEDBACK_URL, {
|
|
98
90
|
session_id: options.sessionId,
|
|
99
91
|
feedback: options.feedback,
|