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

Refactor file edit handling for improved modularity and functionality #759

Merged
merged 11 commits into from
Oct 8, 2024
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
15 changes: 12 additions & 3 deletions docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{
system: ["system.explanations", "system.github_info"],
tools: [
"md_find_files",

Check failure on line 139 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

There seems to be a typo here. Correct function name is "md_read_frontmatter".
"md_read_frontmatterm",
"fs_find_files",
"fs_read_file",
Expand Down Expand Up @@ -206,7 +206,10 @@
- The current repository is the same as github repository.
- Prefer using diff to compare files rather than listing files. Listing files is only useful when you need to read the content of the files.
`,
{ model, system: ["system.git_info", "system.github_info"], tools: ["git"] }
{
model,
system: ["system.git_info", "system.github_info", "system.git"],

Check failure on line 211 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The system array should not include "system.git" as it is not a valid system function according to the provided context.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The system array should not include "system.git" as it is not a valid system function according to the provided context.

generated by pr-docs-review-commit incorrect_info

}
)

`````
Expand Down
100 changes: 0 additions & 100 deletions eval/extrism/genaisrc/extrism-tool.genai.mts

This file was deleted.

129 changes: 129 additions & 0 deletions eval/extrism/genaisrc/extrism.genai.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
script({
model: "openai:gpt-4o",
title: "Runs a extrism sample",
})

const results = `eval/extrism/results/${new Date().toISOString().replace(/:/g, "-")}`
const practiceDir = "python/exercises/practice"

// create container
const container = await host.container({
image: "python:3.11.1",
networkEnabled: true,
})
//console.log(`container path: ${await container.containerPath}`)
console.log(`host path: ${await container.hostPath}`)

await container.exec("git clone https://github.com/exercism/python")
await container.exec("pip install --upgrade pip")
await container.exec("pip install -r requirements.txt --user", {
cwd: "python",
})
await container.exec("pip install pytest --user", { cwd: "python" })
await container.disconnect()

const q = host.promiseQueue(5)
const samples = (await container.exec("ls -1", { cwd: practiceDir })).stdout
.trim()
.split(/\n/g)
await q.mapAll(samples, async (sample) => {
const cwd = path.join(practiceDir, sample)
console.log(cwd)
const { files: samplefiles } = JSON.parse(
await container.readText(path.join(cwd, ".meta/config.json"))
)
const { solution, test } = samplefiles
const filename = path.join(cwd, solution[0])
let instructions = ""
for (const introname of [
"introduction",
"instructions",
"instructions.app",
]) {
const intro = await container.readText(
path.join(cwd, `.docs/${introname}.md`)
)
if (intro) instructions += intro + "\n\n"
}

let generatedCode = ""
let testPassed = false
const res = await runPrompt(
(ctx) => {
ctx.$`

## Task 1:

Analyze INSTRUCTIONS and generate Python code that the requirements.

- use Python 3.11
- Use the TEMPLATE code as a starting point and update it to solve the problem.
You mush NOT change the function signature. Implement the functions.
- do NOT generate unit tests.
- you can only use built-in python libraries. pip packages are not allowed.

## Task 2:

Evaluate the generated code by running the unit tests.

- Use the test_code tool to run the unit tests against the generated code.

## Task 3:

If the tests fail, update the generated code in Task 1 and re-run the tests in Task 1.
If the tests passed, stop.
`

ctx.def("INSTRUCTIONS", instructions, { language: "markdown" })
ctx.def("TEMPLATE", { filename }, { language: "python" })

ctx.defTool(
"test_code",
"Run unit tests against generated solution",
{
code: {
type: "string",
description:
"Generated Python code to solve the problem",
},
},
async ({ code }) => {
generatedCode = code
console.log(code)
await container.writeText(filename, code)
const res = await container.exec(
`python3.11 -m pytest -o markers=task ${test[0]}`,
{ cwd }
)
if (res.exitCode) {
console.log(res.stdout || "")
console.log(res.stderr || "")
} else testPassed = true
return res
},
{ maxTokens: 20000 }
)
},
{
label: sample,
applyEdits: true,
cache: "extrism",
system: [
"system",
"system.explanations",
"system.python",
"system.files",
],
}
)

await workspace.writeText(
`${results}/res/${sample}.yaml`,
YAML.stringify(res)
)
if (generatedCode)
await workspace.writeText(
`${results}/${testPassed ? "success" : "failed"}/${solution[0]}`,
generatedCode
)
})
15 changes: 12 additions & 3 deletions eval/extrism/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading