evals 0.0.5 → 0.0.6

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/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<Response>;
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
- return response;
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.5",
7
+ "version": "0.0.6",
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",