evals 1.0.0 → 1.0.1
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 +126 -42
- package/dist/index.js +15633 -54
- package/package.json +12 -7
- package/dist/evals.d.ts +0 -13
- package/dist/index.d.ts +0 -2
- package/dist/types.d.ts +0 -18
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Umbrage Evals JavaScript
|
|
1
|
+
# Umbrage Evals JavaScript CLI
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
This is the Javascript
|
|
5
|
+
This is the Javascript CLI for Umbrage Evals. It also supports TypeScript.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -16,53 +16,137 @@ npm install evals
|
|
|
16
16
|
|
|
17
17
|
- Node.js (or another JavaScript runtime environment like Bun)
|
|
18
18
|
|
|
19
|
+
## Environment
|
|
20
|
+
|
|
21
|
+
You will need to set the following environment variables:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
UMBRAGE_EVALS_API_KEY=<your api key for the umbrage evals project>
|
|
25
|
+
OPENAI_API_KEY=<your openai api key>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
These can be set in your `~/.bashrc` or `~/.zshrc` file on Mac or Linux, or in your `~/.bash_profile` file on Windows.
|
|
29
|
+
|
|
30
|
+
It would look like:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export UMBRAGE_EVALS_API_KEY=<your api key for the umbrage evals project>
|
|
34
|
+
export OPENAI_API_KEY=<your openai api key>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
To save the file, press `Ctrl + X`, then `Y`, then `Enter`. Then, run `source ~/.bashrc` or `source ~/.zshrc` on Mac or Linux, or `source ~/.bash_profile` on Windows.
|
|
38
|
+
|
|
19
39
|
## Example usage
|
|
20
40
|
|
|
41
|
+
```bash
|
|
42
|
+
umbrage-cli fetch-evals
|
|
43
|
+
|
|
44
|
+
umbrage-cli run-evals
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Example BaseModel
|
|
48
|
+
|
|
21
49
|
```typescript
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
export interface ModelSettings {
|
|
51
|
+
temperature: number;
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Prompt {
|
|
56
|
+
prompt_type: string;
|
|
57
|
+
prompt_text: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface Config {
|
|
61
|
+
promptName: string;
|
|
62
|
+
modelName: string;
|
|
63
|
+
modelSettings: ModelSettings;
|
|
64
|
+
environment: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class BaseModel {
|
|
68
|
+
promptName: string;
|
|
69
|
+
modelName: string;
|
|
70
|
+
modelSettings: ModelSettings;
|
|
71
|
+
environment: string;
|
|
72
|
+
|
|
73
|
+
constructor(config: Config) {
|
|
74
|
+
this.promptName = config.promptName;
|
|
75
|
+
this.modelName = config.modelName;
|
|
76
|
+
this.modelSettings = config.modelSettings;
|
|
77
|
+
this.environment = config.environment || 'development';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* This method should be overridden in subclasses.
|
|
82
|
+
* It should return an object containing the response and the prompts array.
|
|
83
|
+
* @param userMessage The user message to be processed by the model, optional.
|
|
84
|
+
* @returns Promise<{ response: string, prompts: Prompt[] }>
|
|
85
|
+
*/
|
|
86
|
+
async callModel(userMessage: string = ''): Promise<{ response: string; prompts: Prompt[] }> {
|
|
87
|
+
throw new Error('callModel method needs to be implemented in subclasses');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default BaseModel;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Example Prompt (OpenAI API)
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import BaseModel from './BaseModel';
|
|
98
|
+
import OpenAI from 'openai';
|
|
99
|
+
|
|
100
|
+
class ChevySalesCopilotPrompt extends BaseModel {
|
|
101
|
+
constructor() {
|
|
102
|
+
const config = {
|
|
103
|
+
promptName: 'Chevy Sales Copilot',
|
|
104
|
+
modelName: 'gpt-4',
|
|
105
|
+
modelSettings: { temperature: 0.2 },
|
|
106
|
+
environment: 'development'
|
|
107
|
+
};
|
|
108
|
+
super(config);
|
|
109
|
+
|
|
110
|
+
this.openai = new OpenAI(); // Assumes OPENAI_API_KEY is set in environment
|
|
111
|
+
this.messages = [
|
|
112
|
+
{ role: 'system', content: 'You are a Chevy Sales Copilot assistant. You can only help with topics related to sales at Chevrolet. If asked your name your name is "Sales Copilot".' }
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async callModel(userMessage) {
|
|
117
|
+
try {
|
|
118
|
+
// Update messages with user input
|
|
119
|
+
const updatedMessages = [...this.messages, { role: 'user', content: userMessage }];
|
|
120
|
+
|
|
121
|
+
const modelResponse = await this.openai.chat.completions.create({
|
|
122
|
+
model: this.modelName,
|
|
123
|
+
messages: updatedMessages,
|
|
124
|
+
temperature: this.modelSettings.temperature,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const response = modelResponse.choices[0].message.content;
|
|
128
|
+
|
|
129
|
+
const prompts = updatedMessages.map(message => ({
|
|
130
|
+
prompt_type: message.role,
|
|
131
|
+
prompt_text: message.content,
|
|
132
|
+
}));
|
|
133
|
+
|
|
134
|
+
return { response, prompts };
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error('Error:', error);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const prompt = new ChevySalesCopilotPrompt();
|
|
143
|
+
|
|
144
|
+
export default prompt;
|
|
62
145
|
|
|
63
146
|
```
|
|
64
147
|
|
|
65
148
|
## LICENSE
|
|
149
|
+
|
|
66
150
|
Copyright (c) 2023 Umbrage Studios, LLC
|
|
67
151
|
|
|
68
152
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|