eval(), but powered by AI.
Non-deterministic. Cloud-billed. Proudly terrible.
// traditional eval — boring, fast, correct eval('2 + 2') // → 4 // eval++ — exciting, slow, probably correct import evil from '@zachflower/eval-plus-plus' await evil('2 + 2') // → "4" (this time)
* By reading this page you acknowledge this is a terrible idea and you're doing it anyway.
Traditional eval() is predictable, fast, and free. We fixed all of that.
Code is analyzed by AI, not executed locally. It's also not executed correctly, but hey — safety first.
Ask questions about code and receive confident, occasionally accurate answers from a large language model.
Get helpful narrative explanations instead of cryptic stack traces. Trade one kind of confusion for another.
Understand what code would do without running it. Results may vary. Void where prohibited by common sense.
Three easy steps to replace reliable code execution with vibes-based evaluation.
Point npm at GitHub Packages for the @zachflower scope.
@zachflower:registry=https://npm.pkg.github.com
Add it to your project. You'll regret this later, but not yet.
npm install @zachflower/eval-plus-plus
A GitHub Copilot subscription is required. A free tier is available and the irony of needing Copilot to run eval() is not lost on us.
npm install -g @github/copilot-cli
copilot auth login
It's just like eval(). Except it isn't.
import evil from '@zachflower/eval-plus-plus';
// Evaluate a math expression
const result = await evil('2 + 2');
console.log(result); // "4"
// Something more interesting
const analysis = await evil(`
function fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
fibonacci(10)
`);
console.log(analysis); // "55"
import { createEvil } from '@zachflower/eval-plus-plus';
const myEvil = createEvil({
model: 'gpt-4o',
systemPrompt: 'You are a code evaluation assistant...',
clientOptions: {
cliPath: '/usr/local/bin/copilot',
},
});
const result = await myEvil('Math.sqrt(144)');
console.log(result); // "12" — almost certainly
import evil from '@zachflower/eval-plus-plus';
// Malformed JSON? No problem. AI will tell you all about it.
const explanation = await evil('JSON.parse("{invalid}")');
console.log(explanation);
// "This would throw a SyntaxError because the JSON is malformed..."
// Unclear variables? Sure, whatever.
const result = await evil('undeclaredVar + 1');
// "ReferenceError: undeclaredVar is not defined"
Two functions. That's it. We kept it simple because nothing else about this is.
evil(code)
default export
The default evaluation function. Requires the Copilot CLI to be installed and authenticated. Returns a Promise<string>.
function evil(code: string): Promise<string>
createEvil(options?)
named export
Factory function. Returns a configured evil() instance with the options baked in. Useful when you want to imagine you're being professional about this.
function createEvil(options?: EvilOptions): (code: string) => Promise<string>
| Option | Type | Default | Description |
|---|---|---|---|
model |
string |
Copilot default | The model to use for evaluation. As if it matters. |
systemPrompt |
string |
see source | Custom system prompt. For when you want to be extra specific about how wrong the answers should be. |
clientOptions |
CopilotClientOptions |
{} |
Options passed directly to the Copilot SDK client. Consult your therapist before modifying. |
Questions we anticipated. Answers we stand behind, mostly.
No.
eval()?Absolutely not. Regular eval() runs in microseconds. eval++ runs in "latency measured in 'please hold'". You're sending HTTP requests to GitHub's infrastructure to evaluate 2 + 2.
eval()?Also no. Regular eval() is deterministic. eval++ uses an LLM, so results may vary. 2 + 2 is 4, probably, most of the time, in most configurations.
eval()?It's different. You've traded "arbitrary local code execution" for "paying money to get potentially wrong answers from the cloud." You also now have an AI reading all your code snippets. Pick your poison.
The author asked themselves "what if eval, but worse?" and then couldn't stop. This is what happens when you have both a sense of humor and push access to npm.
Technically, yes. Morally, we're going to need you to have a longer conversation with your team first. Maybe also your deployment pipeline. Definitely your billing department.
++ mean?It's an increment operator. We incremented eval by adding latency, cost, non-determinism, and a cloud dependency. Classic ++.