@aci-metrics/score 0.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/test-model.js ADDED
@@ -0,0 +1,232 @@
1
+ /**
2
+ * ACI Local Scorer - Model Test Script
3
+ *
4
+ * This script verifies that the inference abstraction layer works correctly:
5
+ * 1. Loads configuration from config/default.json
6
+ * 2. Creates the appropriate provider based on settings
7
+ * 3. Initializes the model
8
+ * 4. Tests JSON schema enforcement with a sample prompt
9
+ *
10
+ * Run with: npm test
11
+ *
12
+ * To test different configurations:
13
+ * - Edit config/default.json to change model or provider
14
+ * - Or use command line: node test-model.js --model=llama-3.2-3b --provider=ollama
15
+ */
16
+
17
+ var path = require('path');
18
+ var createProvider = require('./lib/provider-factory');
19
+
20
+ /**
21
+ * Parse command line arguments
22
+ *
23
+ * Supports --model=<id> and --provider=<name> flags
24
+ *
25
+ * @returns {Object} Parsed options
26
+ */
27
+ function parseArgs() {
28
+ var options = {};
29
+ var args = process.argv.slice(2);
30
+
31
+ for (var i = 0; i < args.length; i++) {
32
+ var arg = args[i];
33
+
34
+ // Handle --model=value format
35
+ if (arg.startsWith('--model=')) {
36
+ options.modelId = arg.substring('--model='.length);
37
+ }
38
+
39
+ // Handle --provider=value format
40
+ if (arg.startsWith('--provider=')) {
41
+ options.provider = arg.substring('--provider='.length);
42
+ }
43
+
44
+ // Handle --help flag
45
+ if (arg === '--help' || arg === '-h') {
46
+ options.help = true;
47
+ }
48
+ }
49
+
50
+ return options;
51
+ }
52
+
53
+ /**
54
+ * Show help message
55
+ */
56
+ function showHelp() {
57
+ console.log('');
58
+ console.log('ACI Local Scorer - Model Test');
59
+ console.log('');
60
+ console.log('Usage: node test-model.js [options]');
61
+ console.log('');
62
+ console.log('Options:');
63
+ console.log(' --model=<id> Override model from config');
64
+ console.log(' Available: qwen2.5-1.5b, phi-3.5-mini, llama-3.2-3b, gemma-2-2b');
65
+ console.log('');
66
+ console.log(' --provider=<name> Override inference provider');
67
+ console.log(' Available: node-llama-cpp, ollama');
68
+ console.log('');
69
+ console.log(' --help, -h Show this help message');
70
+ console.log('');
71
+ console.log('Examples:');
72
+ console.log(' node test-model.js # Use config defaults');
73
+ console.log(' node test-model.js --model=llama-3.2-3b # Test with Llama');
74
+ console.log(' node test-model.js --provider=ollama # Use Ollama backend');
75
+ console.log('');
76
+ }
77
+
78
+ /**
79
+ * Run the model test
80
+ *
81
+ * @param {Object} options - Command line options
82
+ */
83
+ async function runTest(options) {
84
+ console.log('='.repeat(60));
85
+ console.log('ACI Local Scorer - Model Test');
86
+ console.log('='.repeat(60));
87
+ console.log('');
88
+
89
+ // Create the provider
90
+ console.log('Creating provider...');
91
+ var provider;
92
+ try {
93
+ provider = createProvider({
94
+ modelId: options.modelId,
95
+ provider: options.provider,
96
+ basePath: __dirname
97
+ });
98
+ } catch (error) {
99
+ console.error('');
100
+ console.error('Failed to create provider:');
101
+ console.error(' ' + error.message);
102
+ console.error('');
103
+ process.exit(1);
104
+ }
105
+
106
+ // Show provider info
107
+ var info = provider.getInfo();
108
+ console.log('');
109
+ console.log('Provider: ' + info.provider);
110
+ console.log('Model: ' + info.model);
111
+ console.log('');
112
+
113
+ // Initialize the provider
114
+ console.log('Initializing provider...');
115
+ console.log('');
116
+ try {
117
+ await provider.initialize();
118
+ } catch (error) {
119
+ console.error('');
120
+ console.error('Initialization failed:');
121
+ console.error('');
122
+ console.error(error.message);
123
+ console.error('');
124
+ process.exit(1);
125
+ }
126
+
127
+ // Define test schema
128
+ var testSchema = {
129
+ type: 'object',
130
+ properties: {
131
+ task_type: {
132
+ type: 'string',
133
+ enum: ['feature', 'bugfix', 'refactor', 'docs', 'test', 'config', 'other']
134
+ },
135
+ complexity: {
136
+ type: 'number',
137
+ minimum: 1,
138
+ maximum: 10
139
+ },
140
+ description: {
141
+ type: 'string'
142
+ }
143
+ },
144
+ required: ['task_type', 'complexity', 'description']
145
+ };
146
+
147
+ // Test prompt
148
+ var testPrompt = 'Classify this coding task: "Add error handling to the API endpoint and write unit tests". Respond with JSON containing task_type, complexity (1-10), and description.';
149
+
150
+ console.log('');
151
+ console.log('Testing JSON generation with schema enforcement...');
152
+ console.log('');
153
+ console.log('Prompt:');
154
+ console.log(' ' + testPrompt);
155
+ console.log('');
156
+
157
+ // Generate response
158
+ try {
159
+ console.log('Generating...');
160
+ console.log('');
161
+ var result = await provider.generate(testPrompt, testSchema);
162
+
163
+ console.log('Response:');
164
+ console.log(' task_type: ' + result.task_type);
165
+ console.log(' complexity: ' + result.complexity);
166
+ console.log(' description: ' + result.description);
167
+ console.log('');
168
+ console.log('JSON validation: PASSED');
169
+ console.log('');
170
+
171
+ } catch (error) {
172
+ console.error('');
173
+ console.error('Generation failed:');
174
+ console.error(' ' + error.message);
175
+ console.error('');
176
+ await provider.destroy();
177
+ process.exit(1);
178
+ }
179
+
180
+ // Clean up
181
+ console.log('Cleaning up...');
182
+ await provider.destroy();
183
+
184
+ // Success
185
+ console.log('');
186
+ console.log('='.repeat(60));
187
+ console.log('TEST RESULT: PASSED');
188
+ console.log('');
189
+ console.log('The local scorer is configured correctly!');
190
+ console.log('');
191
+ console.log('Current configuration:');
192
+ console.log(' Model: ' + info.model);
193
+ console.log(' Provider: ' + info.provider);
194
+ console.log('');
195
+ console.log('To change models, edit config/default.json');
196
+ console.log('='.repeat(60));
197
+ }
198
+
199
+ /**
200
+ * Main entry point
201
+ */
202
+ async function main() {
203
+ var options = parseArgs();
204
+
205
+ // Show help if requested
206
+ if (options.help) {
207
+ showHelp();
208
+ process.exit(0);
209
+ }
210
+
211
+ // Run the test
212
+ try {
213
+ await runTest(options);
214
+ process.exit(0);
215
+ } catch (error) {
216
+ console.error('');
217
+ console.error('='.repeat(60));
218
+ console.error('TEST RESULT: FAILED');
219
+ console.error('');
220
+ console.error('Error: ' + error.message);
221
+ if (error.stack) {
222
+ console.error('');
223
+ console.error('Stack trace:');
224
+ console.error(error.stack);
225
+ }
226
+ console.error('='.repeat(60));
227
+ process.exit(1);
228
+ }
229
+ }
230
+
231
+ // Run main
232
+ main();