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 CHANGED
@@ -1,8 +1,8 @@
1
- # Umbrage Evals JavaScript SDK
1
+ # Umbrage Evals JavaScript CLI
2
2
 
3
3
  ## Overview
4
4
 
5
- This is the Javascript SDK for Umbrage Evals. It also supports TypeScript.
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
- 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' }
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: