mirror of
https://github.com/TejasQ/basically-ai-harness.git
synced 2026-06-13 19:20:06 +00:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
// ─────────────────────────────────────────────
|
|
// PART 2: The model
|
|
//
|
|
// One function. Takes a prompt, returns a string.
|
|
// The harness doesn't care what's inside —
|
|
// swap the model string to test a different one.
|
|
// ─────────────────────────────────────────────
|
|
|
|
import OpenAI from "openai";
|
|
import "dotenv/config";
|
|
|
|
const client = new OpenAI({
|
|
baseURL: "https://openrouter.ai/api/v1",
|
|
apiKey: process.env.OPENROUTER_API_KEY,
|
|
});
|
|
|
|
export async function callModel(
|
|
model: string,
|
|
prompt: string
|
|
): Promise<string> {
|
|
const response = await client.chat.completions.create({
|
|
model,
|
|
max_tokens: 64,
|
|
messages: [
|
|
{
|
|
role: "system",
|
|
content:
|
|
"Answer as briefly as possible. One word or number if you can. No punctuation.",
|
|
},
|
|
{ role: "user", content: prompt },
|
|
],
|
|
});
|
|
|
|
return response.choices[0].message.content?.trim() ?? "";
|
|
}
|