evals 0.0.5 → 1.0.0
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 +47 -1
- package/dist/evals.d.ts +6 -2
- package/dist/index.js +45 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
This is the Javascript SDK for Umbrage Evals. It
|
|
5
|
+
This is the Javascript SDK for Umbrage Evals. It also supports TypeScript.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -16,6 +16,52 @@ npm install evals
|
|
|
16
16
|
|
|
17
17
|
- Node.js (or another JavaScript runtime environment like Bun)
|
|
18
18
|
|
|
19
|
+
## Example usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import Evals from 'evals';
|
|
23
|
+
|
|
24
|
+
const evals = new Evals('your-umbrage-evals-api-key-goes-here'); // Get your API key from the Umbrage Evals Dashboard
|
|
25
|
+
|
|
26
|
+
// Get the timestamp for the request so we can log the response time from the model
|
|
27
|
+
const request_timestamp = new Date();
|
|
28
|
+
|
|
29
|
+
// Setting model in a variable since it's going to be passed in two places, one for the model and one for Umbrage Evals
|
|
30
|
+
const model = 'gpt-3.5-turbo';
|
|
31
|
+
|
|
32
|
+
// Call the model
|
|
33
|
+
const chatResponse = await openai.createChatCompletion({
|
|
34
|
+
model,
|
|
35
|
+
messages,
|
|
36
|
+
max_tokens: reservedTokensForResponse,
|
|
37
|
+
temperature: 0.2,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Get the timestamp for the response so we can log the response time from the model
|
|
41
|
+
const response_timestamp = new Date();
|
|
42
|
+
|
|
43
|
+
// Log the prompt and response data to Umbrage Evals
|
|
44
|
+
const logResponse = await evals.logPrompt({
|
|
45
|
+
prompt_name: 'unique_prompt_name', // A unique name specific to this prompt. This is what will show up in the Dashboard under your Project.
|
|
46
|
+
environment: 'development', // Which environment you're using, e.g. development, test, staging, production
|
|
47
|
+
model,
|
|
48
|
+
model_settings: { // Optional, but recommended if you want to track model settings
|
|
49
|
+
temperature: 0.2,
|
|
50
|
+
max_tokens: 512,
|
|
51
|
+
},
|
|
52
|
+
prompts: messages.map((message) => ({
|
|
53
|
+
prompt_type: message.role, // Make sure you have an array with prompt_type and prompt_text
|
|
54
|
+
prompt_text: message.content,
|
|
55
|
+
})),
|
|
56
|
+
response: chatResponse.data.choices[0].message.content, // Map the final text response from the model to the response field
|
|
57
|
+
request_timestamp,
|
|
58
|
+
response_timestamp, // Pass the JavaScript Date objects for the request and response timestamps
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
console.log(logResponse) // { status: 200, body: 'Prompt and response logged successfully' }
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
19
65
|
## LICENSE
|
|
20
66
|
Copyright (c) 2023 Umbrage Studios, LLC
|
|
21
67
|
|
package/dist/evals.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
/// <reference types="bun-types" />
|
|
2
1
|
import { RequestData } from './types';
|
|
3
2
|
declare class Evals {
|
|
4
3
|
private apiKey;
|
|
5
4
|
private endpoint;
|
|
6
5
|
constructor(apiKey: string, endpoint?: string);
|
|
7
|
-
logPrompt(requestData: RequestData): Promise<
|
|
6
|
+
logPrompt(requestData: RequestData): Promise<{
|
|
7
|
+
status: number;
|
|
8
|
+
body: string;
|
|
9
|
+
}>;
|
|
10
|
+
formatTimestamp(timestamp: Date): string;
|
|
11
|
+
validateRequestData(requestData: RequestData): void;
|
|
8
12
|
}
|
|
9
13
|
export default Evals;
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ class Evals {
|
|
|
7
7
|
this.endpoint = endpoint;
|
|
8
8
|
}
|
|
9
9
|
async logPrompt(requestData) {
|
|
10
|
+
this.validateRequestData(requestData);
|
|
10
11
|
const response = await fetch(this.endpoint, {
|
|
11
12
|
method: "POST",
|
|
12
13
|
headers: {
|
|
@@ -14,10 +15,52 @@ class Evals {
|
|
|
14
15
|
},
|
|
15
16
|
body: JSON.stringify({
|
|
16
17
|
api_key: this.apiKey,
|
|
17
|
-
...requestData
|
|
18
|
+
...requestData,
|
|
19
|
+
request_timestamp: this.formatTimestamp(new Date(requestData.request_timestamp)),
|
|
20
|
+
response_timestamp: this.formatTimestamp(new Date(requestData.response_timestamp))
|
|
18
21
|
})
|
|
19
22
|
});
|
|
20
|
-
|
|
23
|
+
const body = await response.text();
|
|
24
|
+
return { status: response.status, body };
|
|
25
|
+
}
|
|
26
|
+
formatTimestamp(timestamp) {
|
|
27
|
+
const pad = (num, size) => num.toString().padStart(size, "0");
|
|
28
|
+
const year = timestamp.getFullYear();
|
|
29
|
+
const month = pad(timestamp.getMonth() + 1, 2);
|
|
30
|
+
const day = pad(timestamp.getDate(), 2);
|
|
31
|
+
const hours = pad(timestamp.getHours(), 2);
|
|
32
|
+
const minutes = pad(timestamp.getMinutes(), 2);
|
|
33
|
+
const seconds = pad(timestamp.getSeconds(), 2);
|
|
34
|
+
const milliseconds = pad(timestamp.getMilliseconds(), 3);
|
|
35
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
36
|
+
}
|
|
37
|
+
validateRequestData(requestData) {
|
|
38
|
+
if (!requestData.request_timestamp || !requestData.response_timestamp || isNaN(Date.parse(requestData.request_timestamp)) || isNaN(Date.parse(requestData.response_timestamp))) {
|
|
39
|
+
throw new Error("request_timestamp and response_timestamp are required and must be valid MySQL DATETIME strings");
|
|
40
|
+
}
|
|
41
|
+
if (!requestData.prompts || !Array.isArray(requestData.prompts) || requestData.prompts.length === 0) {
|
|
42
|
+
throw new Error("prompts is required and must be an array with at least one item");
|
|
43
|
+
}
|
|
44
|
+
requestData.prompts.forEach((prompt) => {
|
|
45
|
+
if (typeof prompt.prompt_type !== "string" || typeof prompt.prompt_text !== "string") {
|
|
46
|
+
throw new Error("Each prompt must have a string prompt_type and prompt_text");
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (!requestData.model_settings && typeof requestData.model_settings !== "object") {
|
|
50
|
+
throw new Error("model_settings is required and must be an object");
|
|
51
|
+
}
|
|
52
|
+
if (!requestData.model || typeof requestData.model !== "string") {
|
|
53
|
+
throw new Error("model is required and must be a string");
|
|
54
|
+
}
|
|
55
|
+
if (!requestData.prompt_name || typeof requestData.prompt_name !== "string") {
|
|
56
|
+
throw new Error("prompt_name is required and must be a string");
|
|
57
|
+
}
|
|
58
|
+
if (!requestData.environment || typeof requestData.environment !== "string") {
|
|
59
|
+
throw new Error("environment is required and must be a string");
|
|
60
|
+
}
|
|
61
|
+
if (!requestData.response || typeof requestData.response !== "string") {
|
|
62
|
+
throw new Error("response is required and must be a string");
|
|
63
|
+
}
|
|
21
64
|
}
|
|
22
65
|
}
|
|
23
66
|
var evals_default = Evals;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.0
|
|
7
|
+
"version": "1.0.0",
|
|
8
8
|
"description": "Umbrage Evals SDK",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "bun build --target=node ./src/index.ts --outfile=dist/index.js && bun run build:declaration",
|