-
Notifications
You must be signed in to change notification settings - Fork 126
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
file format eval #780
file format eval #780
Changes from 4 commits
311422e
18c5fc3
4d79d25
710a315
a9ad311
dc12309
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -590,7 +590,7 @@ | |
|
||
$`## DIFF file format | ||
|
||
The DIFF format should be used to generate diff changes on large files: | ||
The DIFF format should be used to generate diff changes on large files with small number of changes: | ||
|
||
- existing lines must start with their original line number: [<line number>] <line> | ||
- deleted lines MUST start with - followed by the line number: - [<line number>] <deleted line> | ||
|
@@ -608,7 +608,7 @@ | |
- only emit a couple unmodified lines before and after the changes | ||
- keep the diffs AS SMALL AS POSSIBLE | ||
- when reading files, ask for line numbers | ||
- minimize the number of unmodified lines | ||
- minimize the number of unmodified lines. DO NOT EMIT MORE THEN 2 UNMODIFIED LINES BEFORE AND AFTER THE CHANGES. Otherwise use the FILE file format. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in the documentation, "THEN" should be "THAN".
|
||
|
||
- do NOT generate diff for files that have no changes | ||
- do NOT emit diff if lines are the same | ||
|
@@ -620,39 +620,43 @@ | |
|
||
### Examples: | ||
|
||
FOLLOW THE SYNTAX PRECISLY. THIS IS IMPORTANT. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in the documentation, "PRECISLY" should be "PRECISELY".
|
||
DIFF ./file.ts: | ||
\`\`\`diff | ||
[original line number] <2 lines before changes (not the whole file)> | ||
[original line number] line before changes | ||
- [original line number] <deleted line> | ||
+ <added line> | ||
[original line number] <2 lines after changes (not the whole file)> | ||
[original line number] line after changes | ||
\`\`\` | ||
|
||
DIFF ./file2.ts: | ||
\`\`\`diff | ||
[original line number] <2 lines before changes (not the whole file)> | ||
[original line number] line before changes | ||
- [original line number] <deleted line> | ||
- [original line number] <delete line 2> | ||
+ <added line> | ||
+ <added line 2> | ||
[original line number] <2 lines after changes (not the whole file)> | ||
[original line number] line after changes | ||
\`\`\` | ||
|
||
DIFF ./file3.ts: | ||
\`\`\`diff | ||
[original line number] <2 lines before changes (not the whole file)> | ||
[original line number] line before changes | ||
+ <added line> | ||
[original line number] <2 lines after changes (not the whole file)> | ||
[original line number] line after changes | ||
\`\`\` | ||
|
||
DIFF ./file4.ts: | ||
\`\`\`diff | ||
[original line number] <2 lines before changes (not the whole file)> | ||
[original line number] line before changes | ||
- [original line number] <deleted line> | ||
[original line number] <2 lines after changes (not the whole file)> | ||
[original line number] line after changes | ||
\`\`\` | ||
Check failure on line 654 in docs/src/content/docs/reference/scripts/system.mdx GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The examples provided for the DIFF format are incorrect. They should include the actual line numbers and not placeholders like "[original line number]". The examples should be updated to reflect the actual usage of the DIFF format.
|
||
|
||
## Choosing what file format to use | ||
|
||
- If the file content is large (> 50 lines) and the changes are small, use the DIFF format. | ||
- In all other cases, use the FILE file format. | ||
` | ||
|
||
````` | ||
|
@@ -688,9 +692,9 @@ | |
}) | ||
|
||
const folder = env.vars["outputFolder"] || "." | ||
$`## Files | ||
$`## FILE file format | ||
|
||
When generating or updating files you will use the following syntax:` | ||
When generating or updating files you should use the FILE file syntax preferrably:` | ||
|
||
def(`File ${folder}/file1.ts`, `What goes in\n${folder}/file1.ts.`, { | ||
language: "typescript", | ||
|
@@ -705,9 +709,24 @@ | |
language: "markdown", | ||
}) | ||
|
||
$`You MUST specify a start_line and end_line to only update a specific part of a file: | ||
|
||
FILE ${folder}/file1.py: | ||
\`\`\`python start_line=15 end_line=20 | ||
Replace line range 15-20 in \n${folder}/file1.py | ||
\`\`\` | ||
|
||
FILE ${folder}/file1.py: | ||
\`\`\`python start_line=30 end_line=35 | ||
Replace line range 30-35 in \n${folder}/file1.py | ||
\`\`\` | ||
|
||
` | ||
|
||
$`- Make sure to use precisely \`\`\` to guard file code sections. | ||
- Always sure to use precisely \`\`\`\`\` to guard file markdown sections. | ||
Check warning on line 727 in docs/src/content/docs/reference/scripts/system.mdx GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The instructions for guarding file code sections are inconsistent. The first bullet point says to use precisely "```" while the second says to use precisely "````". This should be clarified for consistency.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in the documentation, "Always sure" should be "Always be sure".
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in the documentation, "guard file markdown sections" should be "guard markdown file sections".
|
||
- Use full path of filename in code section header.` | ||
- Use full path of filename in code section header. | ||
- Use start_line, end_line for large files with small updates` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The phrase "Always sure to use precisely" is grammatically incorrect. It should be "Always be sure to use precisely" to correct the sentence structure.
|
||
if (folder !== ".") | ||
$`When generating new files, place files in folder "${folder}".` | ||
$`- If a file does not have changes, do not regenerate. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
system({ | ||
title: "File generation", | ||
description: "Teaches the file format supported by GenAIScripts", | ||
}) | ||
|
||
const folder = env.vars["outputFolder"] || "." | ||
$`## FILE file format | ||
|
||
When generating or updating files you should use the FILE file syntax preferrably:` | ||
|
||
def(`File ${folder}/file1.ts`, `What goes in\n${folder}/file1.ts.`, { | ||
language: "typescript", | ||
}) | ||
def(`File ${folder}/file1.js`, `What goes in\n${folder}/file1.js.`, { | ||
language: "javascript", | ||
}) | ||
def(`File ${folder}/file1.py`, `What goes in\n${folder}/file1.py.`, { | ||
language: "python", | ||
}) | ||
def(`File /path_to_file/file2.md`, `What goes in\n/path_to_file/file2.md.`, { | ||
language: "markdown", | ||
}) | ||
|
||
$`You MUST specify a start_line and end_line to only update a specific part of a file: | ||
|
||
FILE ${folder}/file1.py: | ||
\`\`\`python start_line=15 end_line=20 | ||
Replace line range 15-20 in \n${folder}/file1.py | ||
\`\`\` | ||
|
||
FILE ${folder}/file1.py: | ||
\`\`\`python start_line=30 end_line=35 | ||
Replace line range 30-35 in \n${folder}/file1.py | ||
\`\`\` | ||
|
||
` | ||
|
||
$`- Make sure to use precisely \`\`\` to guard file code sections. | ||
- Always sure to use precisely \`\`\`\`\` to guard file markdown sections. | ||
- Use full path of filename in code section header. | ||
- Use start_line, end_line for large files with small updates` | ||
if (folder !== ".") | ||
$`When generating new files, place files in folder "${folder}".` | ||
$`- If a file does not have changes, do not regenerate. | ||
- Do NOT emit line numbers in file. | ||
- CSV files are inlined as markdown tables.` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,12 +243,14 @@ | |
while (dfence && body.includes(dfence)) { | ||
dfence += "`" | ||
} | ||
const diffFormat = "" // body.length > 500 ? "preferred_diff_format=DIFF" : "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused variable 'diffFormat'. Consider removing it if it's not used.
|
||
const res = | ||
(name ? name + ":\n" : "") + | ||
dfence + | ||
dtype + | ||
(file.filename ? ` file="${file.filename}"` : "") + | ||
(schema ? ` schema=${schema}` : "") + | ||
diffFormat + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable 'diffFormat' is declared but its value is never read. Consider removing it if it's not needed.
|
||
"\n" + | ||
body + | ||
dfence + | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
/** | ||
* Function to resolve and return a list of systems based on the provided script and project. | ||
* This function analyzes the script options and JavaScript source code to determine applicable systems. | ||
* | ||
* | ||
* @param prj - The project object containing templates and other project-related data. | ||
* @param script - An object containing options for the prompt system, model options, and optionally JavaScript source code. | ||
* @returns An array of unique system IDs that are applicable based on the analysis. | ||
|
@@ -45,6 +45,7 @@ | |
if (/\Wchangelog\W/i.test(jsSource)) systems.push("system.changelog") | ||
else if (/\Wfile\W/i.test(jsSource)) { | ||
systems.push("system.files") | ||
// systems.push("system.diff") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a commented out code. If it's not needed, consider removing it.
|
||
// Add file schema system if schema is used | ||
if (useSchema) systems.push("system.files_schema") | ||
} | ||
|
@@ -82,7 +83,7 @@ | |
/** | ||
* Helper function to resolve tools in the project and return their system IDs. | ||
* Finds systems in the project associated with a specific tool. | ||
* | ||
* | ||
* @param prj - The project object containing templates and other project-related data. | ||
* @param tool - The tool ID to resolve systems for. | ||
* @returns An array of system IDs associated with the specified tool. | ||
|
@@ -99,7 +100,7 @@ | |
/** | ||
* Function to resolve tools in the project based on provided systems and tools. | ||
* This function returns a list of tool objects with their IDs and descriptions. | ||
* | ||
* | ||
* @param prj - The project object containing templates and other project-related data. | ||
* @param systems - An array of system IDs to resolve tools for. | ||
* @param tools - An array of tool IDs to resolve tools for. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
script({ | ||
model: "large", | ||
files: "src/edits/fibs/fib.*", | ||
system: ["system"], | ||
lineNumbers: true, | ||
tests: [ | ||
{ | ||
files: "src/edits/fibs/fib.*", | ||
}, | ||
{ | ||
files: "src/edits/bigfibs/fib.*", | ||
}, | ||
], | ||
}) | ||
import { editTest } from "./fileedittest.mts" | ||
|
||
$`## File edits | ||
|
||
Use the 'file_edit' tool to update a file with new content. THIS IS IMPORTANT | ||
|
||
` | ||
|
||
editTest() | ||
|
||
defTool( | ||
"file_edit", | ||
"Updates a file with new content. If the file is large, use lineStart and lineEnd in multiple tool calls to split the update into multiple parts THIS IS VERY IMPORTANT.", | ||
{ | ||
type: "object", | ||
properties: { | ||
filename: { | ||
type: "string", | ||
description: | ||
"The path of the file to update relative to the workspace root", | ||
}, | ||
content: { | ||
type: "string", | ||
description: | ||
"The new content to write to the file. Preserve white space.", | ||
}, | ||
lineStart: { | ||
type: "number", | ||
description: "The line number to start the edit", | ||
}, | ||
lineEnd: { | ||
type: "number", | ||
description: "The line number to end the edit", | ||
}, | ||
}, | ||
required: ["filename", "content"], | ||
}, | ||
async (args) => { | ||
const { context, filename, content, lineStart, lineEnd } = args | ||
context.log(`${filename}#L${lineStart || ""}:${lineEnd || ""}`) | ||
context.log(content) | ||
return "ok" | ||
} | ||
) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrase "DO NOT EMIT MORE THEN 2 UNMODIFIED LINES" should be "DO NOT EMIT MORE THAN 2 UNMODIFIED LINES" to correct the grammatical error.