ai-experiments 0.1.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.
Files changed (2) hide show
  1. package/README.md +146 -0
  2. package/package.json +50 -0
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # ai-experiments
2
+
3
+ A minimalistic experiment runner for AI tasks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install ai-experiments
9
+ # or
10
+ yarn add ai-experiments
11
+ # or
12
+ pnpm add ai-experiments
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Basic Example
18
+
19
+ ```typescript
20
+ import { Experiment } from 'ai-experiments';
21
+
22
+ const result = await Experiment('simple-test', {
23
+ models: ['gpt-4o'],
24
+ temperature: 0.7,
25
+ prompt: 'What is the capital of France?',
26
+ });
27
+
28
+ console.log(result);
29
+ ```
30
+
31
+ ### Using Parameter Combinations
32
+
33
+ ```typescript
34
+ import { Experiment } from 'ai-experiments';
35
+
36
+ const result = await Experiment('temperature-comparison', {
37
+ models: ['gpt-4o', 'gpt-4o-mini'],
38
+ temperature: [0, 0.3, 0.7, 1.0],
39
+ prompt: 'Generate a creative story about a robot.',
40
+ });
41
+
42
+ // This will run 8 combinations (2 models × 4 temperatures)
43
+ console.log(result);
44
+ ```
45
+
46
+ ### Using the Cartesian Function Directly
47
+
48
+ ```typescript
49
+ import { cartesian } from 'ai-experiments';
50
+
51
+ const combinations = cartesian({
52
+ model: ['gpt-4o', 'gpt-4o-mini'],
53
+ temperature: [0, 0.7],
54
+ maxTokens: [100, 500]
55
+ });
56
+
57
+ // Returns:
58
+ // [
59
+ // { model: 'gpt-4o', temperature: 0, maxTokens: 100 },
60
+ // { model: 'gpt-4o', temperature: 0, maxTokens: 500 },
61
+ // { model: 'gpt-4o', temperature: 0.7, maxTokens: 100 },
62
+ // { model: 'gpt-4o', temperature: 0.7, maxTokens: 500 },
63
+ // { model: 'gpt-4o-mini', temperature: 0, maxTokens: 100 },
64
+ // { model: 'gpt-4o-mini', temperature: 0, maxTokens: 500 },
65
+ // { model: 'gpt-4o-mini', temperature: 0.7, maxTokens: 100 },
66
+ // { model: 'gpt-4o-mini', temperature: 0.7, maxTokens: 500 }
67
+ // ]
68
+ ```
69
+
70
+ ### Using the Runner
71
+
72
+ ```typescript
73
+ // vitest.config.ts
74
+ import { defineConfig } from 'vitest/config';
75
+ import { createRunner } from 'ai-experiments';
76
+
77
+ export default createRunner({
78
+ outputDir: '.ai/experiments',
79
+ testMatch: ['**/*experiment*.(js|ts|mjs|cjs)'],
80
+ watch: false,
81
+ });
82
+ ```
83
+
84
+ ## API Reference
85
+
86
+ ### Experiment
87
+
88
+ ```typescript
89
+ function Experiment<T = any, E = any>(
90
+ name: string,
91
+ config: ExperimentConfig<T, E>
92
+ ): Promise<ExperimentResult>
93
+ ```
94
+
95
+ #### Parameters
96
+
97
+ - `name`: Name of the experiment
98
+ - `config`: Configuration object with the following properties:
99
+ - `models`: Array of model names to use
100
+ - `temperature`: Number or array of temperature values
101
+ - `seed` (optional): Number or array of seed values
102
+ - `prompt` (optional): String or function that generates prompts
103
+ - `inputs` (optional): Array or function that returns input values
104
+ - `expected` (optional): Expected output for validation
105
+ - `schema` (optional): Schema for structured output
106
+
107
+ #### Returns
108
+
109
+ Promise that resolves to an `ExperimentResult` object with:
110
+ - `name`: Name of the experiment
111
+ - `results`: Array of results for each parameter combination
112
+ - `totalTime`: Total time taken for the experiment
113
+ - `timestamp`: ISO string of when the experiment was run
114
+
115
+ ### cartesian
116
+
117
+ ```typescript
118
+ function cartesian<T extends Record<string, readonly any[]>>(
119
+ spec: T
120
+ ): Array<{ [K in keyof T]: T[K][number] }>
121
+ ```
122
+
123
+ #### Parameters
124
+
125
+ - `spec`: Object with keys mapping to arrays of values
126
+
127
+ #### Returns
128
+
129
+ Array of objects representing all possible combinations of the input values.
130
+
131
+ ### createRunner
132
+
133
+ ```typescript
134
+ function createRunner(config?: RunnerConfig): VitestConfig
135
+ ```
136
+
137
+ #### Parameters
138
+
139
+ - `config` (optional): Configuration object with the following properties:
140
+ - `outputDir` (optional): Directory where experiment results will be saved
141
+ - `testMatch` (optional): Custom test matcher pattern
142
+ - `watch` (optional): Whether to watch for file changes
143
+
144
+ #### Returns
145
+
146
+ A Vitest configuration function that can be used in `vitest.config.ts`.
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "ai-experiments",
3
+ "version": "0.1.0",
4
+ "description": "A minimalistic experiment runner for AI tasks",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/index.js",
11
+ "import": "./dist/index.mjs",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "ai",
20
+ "experiments",
21
+ "testing",
22
+ "vitest"
23
+ ],
24
+ "dependencies": {
25
+ "vitest": "^1.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "tsup": "^8.0.1",
29
+ "typescript": "^5.2.2",
30
+ "prettier": "^3.4.2",
31
+ "@types/node": "^20.17.0"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/drivly/primitives.org.ai.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/drivly/primitives.org.ai/issues"
39
+ },
40
+ "homepage": "https://primitives.org.ai",
41
+ "license": "MIT",
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "test": "vitest run",
46
+ "test:watch": "vitest",
47
+ "typecheck": "tsc --noEmit",
48
+ "format": "prettier --write 'src/**/*.{ts,tsx,js,jsx}'"
49
+ }
50
+ }