Skip to content

Commit

Permalink
Add fs_diff_files tool for computing file diffs and update related do…
Browse files Browse the repository at this point in the history
…cumentation and parsers
  • Loading branch information
pelikhan committed Oct 2, 2024
1 parent 6de65d5 commit 3b2288b
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/genaisrc/genaiscript.d.ts

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

1 change: 1 addition & 0 deletions docs/src/components/BuiltinTools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LinkCard } from '@astrojs/starlight/components';
<LinkCard title="agent_github" description="Agent that can query GitHub to accomplish tasks" href="/genaiscript/reference/scripts/system#systemagent_github" />
<LinkCard title="agent_interpreter" description="Run code interpreters for Python, Math. Use this agent to ground computation questions." href="/genaiscript/reference/scripts/system#systemagent_interpreter" />
<LinkCard title="agent_user_input" description="Ask user for input to confirm, select or answer a question." href="/genaiscript/reference/scripts/system#systemagent_user_input" />
<LinkCard title="fs_diff_files" description="Computes a diff between two files." href="/genaiscript/reference/scripts/system#systemfs_diff_files" />
<LinkCard title="fs_find_files" description="Finds file matching a glob pattern. Use pattern to specify a regular expression to search for in the file content." href="/genaiscript/reference/scripts/system#systemfs_find_files" />
<LinkCard title="fs_read_file" description="Reads a file as text from the file system. Returns undefined if the file does not exist." href="/genaiscript/reference/scripts/system#systemfs_read_file" />
<LinkCard title="git_branch_current" description="Gets the current branch." href="/genaiscript/reference/scripts/system#systemgit" />
Expand Down
46 changes: 46 additions & 0 deletions docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ defTool(
"system.explanations",
"system.fs_find_files",
"system.fs_read_file",
"system.fs_diff_files",
"system.retrieval_fuzz_search",
"system.md_frontmatter",
],
Expand Down Expand Up @@ -652,6 +653,51 @@ def(`File ${folder}/data.json`, `...`, {
`````


### `system.fs_diff_files`

File Diff Files

Tool to compute a diff betweeen two files.

- tool `fs_diff_files`: Computes a diff between two files.

`````js wrap title="system.fs_diff_files"
system({
title: "File Diff Files",
description: "Tool to compute a diff betweeen two files.",
})

defTool(
"fs_diff_files",
"Computes a diff between two files.",
{
type: "object",
properties: {
filename: {
type: "string",
description:
"Path of the file to compare, relative to the workspace.",
},
otherfilename: {
type: "string",
description:
"Path of the other file to compare, relative to the workspace.",
},
},
required: ["filename"],
},
async (args) => {
const { context, filename, otherfilename } = args
context.log(`diff: ${filename} ${filename}`)
const f = await workspace.readText(filename)
const of = await workspace.readText(otherfilename)
return parsers.diff(f, of)
}
)

`````


### `system.fs_find_files`

File find files
Expand Down
7 changes: 7 additions & 0 deletions genaisrc/genaiscript.d.ts

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

7 changes: 7 additions & 0 deletions packages/auto/genaiscript.d.ts

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

7 changes: 7 additions & 0 deletions packages/core/src/genaisrc/genaiscript.d.ts

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

1 change: 1 addition & 0 deletions packages/core/src/genaisrc/system.agent_fs.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defTool(
"system.explanations",
"system.fs_find_files",
"system.fs_read_file",
"system.fs_diff_files",
"system.retrieval_fuzz_search",
"system.md_frontmatter",
],
Expand Down
32 changes: 32 additions & 0 deletions packages/core/src/genaisrc/system.fs_diff_files.genai.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
system({
title: "File Diff Files",
description: "Tool to compute a diff betweeen two files.",
})

defTool(
"fs_diff_files",
"Computes a diff between two files.",
{
type: "object",
properties: {
filename: {
type: "string",
description:
"Path of the file to compare, relative to the workspace.",
},
otherfilename: {
type: "string",
description:
"Path of the other file to compare, relative to the workspace.",
},
},
required: ["filename"],
},
async (args) => {
const { context, filename, otherfilename } = args
context.log(`diff: ${filename} ${filename}`)
const f = await workspace.readText(filename)
const of = await workspace.readText(otherfilename)
return parsers.diff(f, of)
}
)
2 changes: 2 additions & 0 deletions packages/core/src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { resolveFileContent } from "./file"
import { resolveTokenEncoder } from "./encoders"
import { mustacheRender } from "./mustache"
import { jinjaRender } from "./jinja"
import { createDiff, llmifyDiff } from "./diff"

export async function createParsers(options: {
trace: MarkdownTrace
Expand Down Expand Up @@ -115,5 +116,6 @@ export async function createParsers(options: {
const f = filenameOrFileToContent(file)
return jinjaRender(f, data)
},
diff: (f1, f2) => llmifyDiff(createDiff(f1, f2)),
})
}
5 changes: 5 additions & 0 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,11 @@ interface Parsers {
* Renders a jinja template
*/
jinja(text: string | WorkspaceFile, data: Record<string, any>): string

/**
* Computes a diff between two files
*/
diff(left: WorkspaceFile, right: WorkspaceFile, options?: DefDiffOptions): string
}

interface AICIGenOptions {
Expand Down
7 changes: 7 additions & 0 deletions packages/sample/genaisrc/blog/genaiscript.d.ts

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

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
script({
model: "gpt-3.5-turbo",
system: ["system", "system.files"],
tests: {}
tests: {},
})

$`Generate a poem and save it in a file "poem.txt".`
$`Generate a poem and save it in a file "poem.txt".`
7 changes: 7 additions & 0 deletions packages/sample/genaisrc/genaiscript.d.ts

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

7 changes: 7 additions & 0 deletions packages/sample/genaisrc/node/genaiscript.d.ts

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

7 changes: 7 additions & 0 deletions packages/sample/genaisrc/python/genaiscript.d.ts

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

7 changes: 7 additions & 0 deletions packages/sample/genaisrc/style/genaiscript.d.ts

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

Loading

0 comments on commit 3b2288b

Please sign in to comment.