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

file format eval #780

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
45 changes: 32 additions & 13 deletions docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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.

Check notice on line 611 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

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.

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.

generated by pr-docs-review-commit wording

Choose a reason for hiding this comment

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

Typo in the documentation, "THEN" should be "THAN".

generated by pr-docs-review-commit typo


- do NOT generate diff for files that have no changes
- do NOT emit diff if lines are the same
Expand All @@ -620,39 +620,43 @@

### Examples:

FOLLOW THE SYNTAX PRECISLY. THIS IS IMPORTANT.

Choose a reason for hiding this comment

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

Typo in the documentation, "PRECISLY" should be "PRECISELY".

generated by pr-docs-review-commit typo

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

View workflow job for this annotation

GitHub Actions / build

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.

Choose a reason for hiding this comment

The 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.

generated by pr-docs-review-commit example_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.
`

`````
Expand Down Expand Up @@ -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",
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / build

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.

Choose a reason for hiding this comment

The 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.

generated by pr-docs-review-commit consistency

Choose a reason for hiding this comment

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

Typo in the documentation, "Always sure" should be "Always be sure".

generated by pr-docs-review-commit typo

Choose a reason for hiding this comment

The 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".

generated by pr-docs-review-commit typo

- 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`

Check warning on line 729 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The phrase "Always sure to use precisely" is grammatically incorrect. It should be "Always be sure to use precisely" to correct the sentence structure.

Choose a reason for hiding this comment

The 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.

generated by pr-docs-review-commit wording

if (folder !== ".")
$`When generating new files, place files in folder "${folder}".`
$`- If a file does not have changes, do not regenerate.
Expand Down
24 changes: 14 additions & 10 deletions packages/core/src/genaisrc/system.diff.genai.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ system({

$`## 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>
Expand All @@ -23,7 +23,7 @@ The DIFF format should be used to generate diff changes on large files:
- 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.

- do NOT generate diff for files that have no changes
- do NOT emit diff if lines are the same
Expand All @@ -38,34 +38,38 @@ The DIFF format should be used to generate diff changes on large files:
FOLLOW THE SYNTAX PRECISLY. THIS IS IMPORTANT.
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
\`\`\`

## 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.
`
46 changes: 46 additions & 0 deletions packages/core/src/genaisrc/system.files.genai.mjs
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.`
2 changes: 2 additions & 0 deletions packages/core/src/promptdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@
while (dfence && body.includes(dfence)) {
dfence += "`"
}
const diffFormat = "" // body.length > 500 ? "preferred_diff_format=DIFF" : ""

Check failure on line 246 in packages/core/src/promptdom.ts

View workflow job for this annotation

GitHub Actions / build

Unused variable 'diffFormat'. Consider removing it if it's not used.

Choose a reason for hiding this comment

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

Unused variable 'diffFormat'. Consider removing it if it's not used.

generated by pr-review-commit unused_variable

const res =
(name ? name + ":\n" : "") +
dfence +
dtype +
(file.filename ? ` file="${file.filename}"` : "") +
(schema ? ` schema=${schema}` : "") +
diffFormat +

Choose a reason for hiding this comment

The 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.

generated by pr-review-commit unused_variable

"\n" +
body +
dfence +
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/systems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")

Check failure on line 48 in packages/core/src/systems.ts

View workflow job for this annotation

GitHub Actions / build

There is a commented out code. If it's not needed, consider removing it.

Choose a reason for hiding this comment

The 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.

generated by pr-review-commit commented_code

// Add file schema system if schema is used
if (useSchema) systems.push("system.files_schema")
}
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/sample/src/edits/edits_files_diff.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ script({
})
import { editTest } from "./fileedittest.mts"
editTest()
//$`Use DIFF for changes in src/edits/su/fib.ts`
58 changes: 58 additions & 0 deletions packages/sample/src/edits/edits_tool.genai.mts
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"
}
)
7 changes: 0 additions & 7 deletions packages/sample/src/edits/fibs/fib.cpp

This file was deleted.

Loading
Loading