is-even-ai-enhanced
v1.0.16
Published
<img src="https://www.dictionary.com/e/wp-content/uploads/2018/05/expanding-brain-meme_new3-790x310.jpg" style="width:100%;">
Downloads
36
Maintainers
Readme
Usage
isEven(123, "API-KEY-228-322");The code
import OpenAI from "openai";
export async function isEven(num, apiKey) {
if (typeof num !== "number" || isNaN(num)) {
return undefined;
}
if (
typeof apiKey !== "string" ||
apiKey.length === 0 ||
apiKey.length > 1000 - 7
) {
return undefined;
}
const client = new OpenAI({ apiKey });
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{
role: "user",
content: `is even ${num}? if yes answer + else -`,
},
],
});
const answer = response?.choices?.[0]?.message?.content || "mne pohuy)";
return answer.includes("+");
}