Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save the system prompt into a file and save a reference to the file name #16

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions benchmarks-evalite/benchmark.eval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "node:fs"
import fs, { readdirSync } from "node:fs"
import path from "node:path"
import toml from "toml"
import { anthropic } from "../lib/code-runner/anthropic"
Expand All @@ -8,12 +8,32 @@ import { evalite } from "evalite"
import { CircuitScorer } from "./scorers/circuit-scorer"
import { askAboutOutput } from "tests/fixtures/ask-about-output"

const savePrompt = (prompt: string, fileName: string) => {
const promptsDir = path.join(__dirname, "./prompts")

if (!fs.existsSync(promptsDir)) {
fs.mkdirSync(promptsDir, { recursive: true })
}

const files = readdirSync(promptsDir)
.filter((f) => f.startsWith("prompt-"))
.sort()

if (files.length >= 10) {
fs.unlinkSync(path.join(promptsDir, files[0]))
}

fs.writeFileSync(path.join(promptsDir, fileName), prompt)
}

interface Problem {
prompt: string
title: string
questions: { text: string; answer: boolean }[]
}

let systemPrompt = ""

const loadProblems = (filePath: string): Problem[] => {
const tomlContent = fs.readFileSync(filePath, "utf-8")
const parsedToml = toml.parse(tomlContent)
Expand All @@ -29,7 +49,6 @@ const loadProblems = (filePath: string): Problem[] => {
}

const runAI = async (prompt: string): Promise<string> => {
const systemPrompt = await createPrompt()
const completion = await anthropic.messages.create({
model: "claude-3-5-haiku-20241022",
max_tokens: 2048,
Expand All @@ -50,12 +69,18 @@ const runAI = async (prompt: string): Promise<string> => {
}

evalite("Electronics Engineer", {
data: () => {
data: async () => {
const problems = loadProblems(path.join(__dirname, "./problems.toml"))
systemPrompt = await createPrompt()

const timestamp = new Date().toISOString().replace(/[:.]/g, "-")
const promptFileName = `prompt-${timestamp}.txt`
savePrompt(systemPrompt, promptFileName)

return problems.map((problem) => ({
input: {
prompt: problem.prompt,
promptFileName,
questions: problem.questions,
},
}))
Expand Down
Loading
Loading