-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ShiboSoftwareDev/main
updated evalite, added format script
- Loading branch information
Showing
8 changed files
with
387 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,76 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import toml from 'toml'; | ||
import { anthropic } from '../lib/code-runner/anthropic'; | ||
import { safeEvaluateCode } from '../lib/code-runner/safe-evaluate-code'; | ||
import { askAboutOutput } from '../tests/fixtures/ask-about-output'; | ||
import { createCircuitBoard1Template } from '../prompt-templates/create-circuit-board1'; | ||
import { evalite } from "evalite"; | ||
import { Levenshtein } from "autoevals"; | ||
import fs from "fs" | ||
import path from "path" | ||
import toml from "toml" | ||
import { anthropic } from "../lib/code-runner/anthropic" | ||
import { safeEvaluateCode } from "../lib/code-runner/safe-evaluate-code" | ||
import { askAboutOutput } from "../tests/fixtures/ask-about-output" | ||
import { createPrompt } from "./prompt" | ||
import { evalite } from "evalite" | ||
import { ExactMatch } from "autoevals" | ||
|
||
interface Problem { | ||
prompt: string; | ||
questions: { text: string; answer: boolean }[]; | ||
prompt: string | ||
title: string | ||
questions: { text: string; answer: boolean }[] | ||
} | ||
|
||
const loadProblems = (filePath: string): Problem[] => { | ||
const tomlContent = fs.readFileSync(filePath, 'utf-8'); | ||
const parsedToml = toml.parse(tomlContent); | ||
const tomlContent = fs.readFileSync(filePath, "utf-8") | ||
const parsedToml = toml.parse(tomlContent) | ||
|
||
return parsedToml.problems.map((problem: any) => ({ | ||
prompt: problem.prompt, | ||
title: problem.title, | ||
questions: problem.questions.map((q: any) => ({ | ||
text: q.text, | ||
answer: q.answer | ||
})) | ||
})); | ||
}; | ||
answer: q.answer, | ||
})), | ||
})) | ||
} | ||
|
||
const runAI = async (prompt: string): Promise<string> => { | ||
const fullPrompt = createCircuitBoard1Template({ | ||
currentCode: "", | ||
availableImports: {} | ||
}) + "\n\n" + prompt; | ||
const initialPrompt = createPrompt({ requestedCircuit: prompt }) | ||
const completion = await anthropic.messages.create({ | ||
model: 'claude-3-5-haiku-20241022', | ||
model: "claude-3-5-haiku-20241022", | ||
max_tokens: 1024, | ||
system: "You are an expert in electronic circuit design and tscircuit.", | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: fullPrompt, | ||
role: "user", | ||
content: initialPrompt, | ||
}, | ||
], | ||
}); | ||
}) | ||
|
||
return (completion as any).content[0]?.text || ''; | ||
}; | ||
return (completion as any).content[0]?.text || "" | ||
} | ||
|
||
const problems = loadProblems(path.join(__dirname, './problems.toml')); | ||
let problemNumber = 0; | ||
const problems = loadProblems(path.join(__dirname, "./problems.toml")) | ||
let problemNumber = 0 | ||
for (const problem of problems) { | ||
problemNumber++ | ||
evalite(`problem: ${problemNumber}`, { | ||
evalite(problem.title, { | ||
data: async () => { | ||
const aiResponse = await runAI(problem.prompt); | ||
const codeMatch = aiResponse.match(/```tsx\s*([\s\S]*?)\s*```/); | ||
const code = codeMatch ? codeMatch[1].trim() : ''; | ||
const aiResponse = await runAI(problem.prompt) | ||
const codeMatch = aiResponse.match(/```tsx\s*([\s\S]*?)\s*```/) | ||
const code = codeMatch ? codeMatch[1].trim() : "" | ||
const evaluation = safeEvaluateCode(code, { | ||
outputType: 'board', | ||
outputType: "board", | ||
preSuppliedImports: {}, | ||
}); | ||
return problem.questions.map(question => ({ input: { code: evaluation.success ? code : null, question: question.text }, expected: question.answer.toString() })); | ||
}) | ||
return problem.questions.map((question) => ({ | ||
input: { | ||
code: evaluation.success ? code : null, | ||
question: question.text, | ||
}, | ||
expected: question.answer.toString(), | ||
})) | ||
}, | ||
task: async (input) => { | ||
if (!input.code) | ||
return "" | ||
const answer = await askAboutOutput(input.code, input.question); | ||
return answer.toString(); | ||
if (!input.code) return "" | ||
const answer = await askAboutOutput(input.code, input.question) | ||
return answer.toString() | ||
}, | ||
scorers: [Levenshtein], | ||
}); | ||
scorers: [ExactMatch], | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.