Skip to content

Commit 55f626c

Browse files
authored
Merge pull request #71 from PackageFlipper/copilot/fix-llm-call-issue
Add LLM-based odd/even checker via OpenAI
2 parents 8f93b77 + 14de7ca commit 55f626c

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

‎index.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import not_odd from "not-odd";
22
import os from "os"
33
import { promisify } from 'util';
44
import { exec as execCallback } from 'child_process';
5+
import OpenAI from 'openai';
56

67
// Some Async Magic that allows STDOUT to be read after command execution
78
const exec = promisify(execCallback);
@@ -101,6 +102,22 @@ function doesNotNotOddNotOddlyOdd() {
101102
return defNotNotEven(fib(rand));
102103
}
103104
export const notNotOdd_perl = num => notNotOdd_pl(num);
105+
export const notNotOdd_llm = async function(num) {
106+
const client = new OpenAI();
107+
const message = await client.chat.completions.create({
108+
model: "gpt-4o-mini",
109+
messages: [
110+
{
111+
role: "user",
112+
content: `Is the number ${num} odd? Answer with only 'true' or 'false'.`
113+
}
114+
],
115+
max_tokens: 10
116+
});
117+
const response = message.choices[0].message.content.trim().toLowerCase();
118+
return response === 'true';
119+
};
120+
export const 𓀬 = notNotOdd_llm;
104121
export const notNotOdd = num => !not_odd(num);
105122
export const notNotNotOdd = num => !notNotOdd(num);
106123
export const notNotNotNotOdd = num => !notNotNotOdd(num);

‎package-lock.json‎

Lines changed: 32 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"type": "module",
33
"dependencies": {
44
"not-even": "^1.0.2",
5-
"not-odd": "^1.0.0"
5+
"not-odd": "^1.0.0",
6+
"openai": "^6.49.0"
67
}
78
}

0 commit comments

Comments
 (0)