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

split docs/produtct dependencies #621

Merged
merged 14 commits into from
Aug 16, 2024
5 changes: 2 additions & 3 deletions THIRD_PARTY_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28192,12 +28192,11 @@ SOFTWARE.

-----------

The following npm packages may be included in this product:
The following npm package may be included in this product:

- @slidev/[email protected]
- @slidev/[email protected]

These packages each contain the following license and notice below:
This package contains the following license and notice below:

MIT License

Expand Down
5 changes: 5 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.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"devDependencies": {
"zx": "^8.1.4"
}
}
}
10 changes: 5 additions & 5 deletions docs/src/content/docs/reference/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@
-rmo, --remove-out remove output folder if it exists
--cli <string> override path to the cli
-tp, --test-provider <string> test provider
-td, --test-delay <string> delay between tests in seconds

Check failure on line 87 in docs/src/content/docs/reference/cli/commands.md

View workflow job for this annotation

GitHub Actions / build

The option name `--promptfoo-version` seems incorrect. It should be `--prompt-version`.

Choose a reason for hiding this comment

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

The option name --promptfoo-version seems incorrect. It should likely be --prompt-version.

generated by pr-docs-review-commit option_name

--no-cache disable LLM result cache
-v, --verbose verbose output
-pv, --promptfoo-version [version] promptfoo version, default is ^0.75.2
-pv, --promptfoo-version [version] promptfoo version, default is 0.78.0
-os, --out-summary <file> append output summary in file
-h, --help display help for command
```
Expand Down Expand Up @@ -291,11 +291,11 @@
Options:
-h, --help display help for command

Commands:

Check failure on line 294 in docs/src/content/docs/reference/cli/commands.md

View workflow job for this annotation

GitHub Actions / build

The command usage for `fence` is missing the `<file>` argument.

Choose a reason for hiding this comment

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

The command usage for fence is missing the <file> argument.

generated by pr-docs-review-commit command_usage

fence <language> Extracts a code fenced regions of the given type
fence <language> <file> Extracts a code fenced regions of the given type
pdf <file> Parse a PDF into text
docx <file> Parse a DOCX into texts
html-to-text [file] Parse an HTML file into text
html-to-text <file> Parse an HTML file into text

Check failure on line 298 in docs/src/content/docs/reference/cli/commands.md

View workflow job for this annotation

GitHub Actions / build

The command usage for `html-to-text` is missing the `<file>` argument.

Choose a reason for hiding this comment

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

The command usage for html-to-text is missing the <file> argument.

generated by pr-docs-review-commit command_usage

code <file> [query] Parse code using tree sitter and executes a
query
tokens [options] <files...> Count tokens in a set of files
Expand All @@ -305,7 +305,7 @@
### `parse fence`

```
Usage: genaiscript parse fence [options] <language>
Usage: genaiscript parse fence [options] <language> <file>

Check failure on line 308 in docs/src/content/docs/reference/cli/commands.md

View workflow job for this annotation

GitHub Actions / build

The command usage for `parse fence` is missing the `<file>` argument.

Choose a reason for hiding this comment

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

The command usage for parse fence is missing the <file> argument.

generated by pr-docs-review-commit command_usage


Extracts a code fenced regions of the given type

Expand Down Expand Up @@ -338,7 +338,7 @@
### `parse html-to-text`

```
Usage: genaiscript parse html-to-text [options] [file]
Usage: genaiscript parse html-to-text [options] <file>

Check failure on line 341 in docs/src/content/docs/reference/cli/commands.md

View workflow job for this annotation

GitHub Actions / build

The command usage for `parse html-to-text` is missing the `<file>` argument.

Choose a reason for hiding this comment

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

The command usage for parse html-to-text is missing the <file> argument.

generated by pr-docs-review-commit command_usage


Parse an HTML file into text

Expand Down
8 changes: 8 additions & 0 deletions docs/src/content/docs/reference/scripts/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
const data = await workspace.readJSON("data.json")
```

### `readXML`

Reads the content of a file as XML.

```ts
const data = await workspace.readXML("data.xml")
```

Check notice on line 88 in docs/src/content/docs/reference/scripts/files.md

View workflow job for this annotation

GitHub Actions / build

A new `readXML` function has been documented. Ensure that the implementation matches the documentation.

Choose a reason for hiding this comment

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

The readXML function is added without a description of its behavior or use cases.

generated by pr-docs-review-commit missing_example_description

Choose a reason for hiding this comment

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

The readXML function is added but there is no explanation or details provided about its usage or behavior.

generated by pr-docs-review-commit missing_documentation

Choose a reason for hiding this comment

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

A new readXML function has been documented. Ensure that the implementation matches the documentation.

generated by pr-docs-review-commit new_feature


### `writeText`

Writes text to a file, relative to the workspace root.
Expand Down
13 changes: 12 additions & 1 deletion docs/src/content/docs/reference/scripts/parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,21 @@

## XML

The `parsers.XML` function parses for the [XML format](https://en.wikipedia.org/wiki/XML).

```js
const res = parsers.XML("<xml></xml>")
const res = parsers.XML('<xml attr="1"><child /></xml>')
```

Attribute names are prepended with "@_".

```json
{
"xml": {
"@_attr": "1",
"child": {}
}
}

Check notice on line 117 in docs/src/content/docs/reference/scripts/parsers.md

View workflow job for this annotation

GitHub Actions / build

The `parsers.XML` function documentation has been updated with new information about attribute naming conventions. Ensure that the implementation matches the documentation.

Choose a reason for hiding this comment

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

The code fence around the JSON example should be js or javascript, not ```json, since the content is not valid JSON due to the unquoted keys.

generated by pr-docs-review-commit incorrect_code_fence

Choose a reason for hiding this comment

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

The example provided for parsers.XML function is in JSON format, which is inconsistent with the context that should show an XML parsing example.

generated by pr-docs-review-commit incorrect_example

Choose a reason for hiding this comment

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

The parsers.XML function documentation has been updated with more details on how attributes are parsed. Ensure that the implementation matches the documentation.

generated by pr-docs-review-commit xml_parsing_details

Choose a reason for hiding this comment

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

The parsers.XML function documentation has been updated with new information about attribute naming conventions. Ensure that the implementation matches the documentation.

generated by pr-docs-review-commit new_feature

```

## front matter
Expand Down
5 changes: 5 additions & 0 deletions genaisrc/genaiscript.d.ts

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

13 changes: 7 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"mathjs": "^13.0.3",
"pdfjs-dist": "4.5.136",
"tree-sitter-wasms": "^0.1.11",
"tsx": "^4.16.5",
"tsx": "^4.17.0",
"typescript": "5.5.4",
"vectra": "^0.7.6",
"web-tree-sitter": "^0.22.2",
Expand All @@ -42,6 +42,9 @@
"engines": {
"node": ">=20.0.0"
},
"peerDependencies": {
"promptfoo": "0.78.0"
},
"devDependencies": {
"@types/dockerode": "^3.3.31",
"@types/fs-extra": "^11.0.4",
Expand All @@ -54,18 +57,16 @@
"commander": "^12.1.0",
"dotenv": "^16.4.5",
"esbuild": "^0.23.0",
"execa": "^9.3.0",
"execa": "^9.3.1",
"fs-extra": "^11.2.0",
"get-stdin": "^9.0.0",
"glob": "^11.0.0",
"memorystream": "^0.3.1",
"node-sarif-builder": "^3.1.0",
"openai": "^4.55.0",
"openai": "^4.55.7",
"ora": "^8.0.1",
"pretty-bytes": "^6.1.1",
"promptfoo": "^0.75.2",
"prompts": "^2.4.2",
"replace-ext": "^2.0.0",
"ws": "^8.18.0",
"zx": "^8.1.4"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
.alias("parsers")
.description("Parse various outputs")
parser
.command("fence <language>")
.command("fence <language> <file>")

Check failure on line 252 in packages/cli/src/cli.ts

View workflow job for this annotation

GitHub Actions / build

The function `parseFence` now requires two arguments, but only one is provided here. Please add the second argument.

Choose a reason for hiding this comment

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

The parseFence function now requires two arguments, but only one is being passed here. Please pass the required file argument. 📝

generated by pr-review-commit missing_argument

.description("Extracts a code fenced regions of the given type")
.action(parseFence)

Expand All @@ -264,7 +264,7 @@
.action(parseDOCX)

parser
.command("html-to-text [file]")
.command("html-to-text <file>")

Choose a reason for hiding this comment

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

The function parseHTMLToText is now expecting one argument, but none is being provided. Please provide the required argument.

generated by pr-review-commit missing_argument

.description("Parse an HTML file into text")
.action(parseHTMLToText)

Expand Down
11 changes: 4 additions & 7 deletions packages/cli/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createProgressSpinner } from "./spinner"
import replaceExt from "replace-ext"
import getStdin from "get-stdin"
import { readFile } from "node:fs/promises"
import { DOCXTryParse } from "../../core/src/docx"
import { extractFenced } from "../../core/src/fence"
Expand All @@ -12,9 +11,9 @@
import { YAMLStringify } from "../../core/src/yaml"
import { resolveTokenEncoder } from "../../core/src/encoders"

export async function parseFence(language: string) {
const stdin = await getStdin()
const fences = extractFenced(stdin || "").filter(
export async function parseFence(language: string, file: string) {
const res = await parsePdf(file)
const fences = extractFenced(res.content || "").filter(

Check failure on line 16 in packages/cli/src/parse.ts

View workflow job for this annotation

GitHub Actions / build

The function `parsePdf` is called here, but it is not defined or imported in this file. Please check the function name or import it.

Choose a reason for hiding this comment

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

The function parsePdf is not defined in this file or imported from another module. Please ensure that this function is defined before it is called. 🧐

generated by pr-review-commit undefined_function

Choose a reason for hiding this comment

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

The function parsePdf is called here, but it is not defined or imported in this file. Please check the function name or import it.

generated by pr-review-commit wrong_function_call

(f) => f.language === language
)
console.log(fences.map((f) => f.content).join("\n\n"))
Expand All @@ -32,9 +31,7 @@
}

export async function parseHTMLToText(file: string) {
const html = file
? await readFile(file, { encoding: "utf-8" })
: await getStdin()
const html = await readFile(file, { encoding: "utf-8" })
const text = HTMLToText(html)
console.log(text)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import packageJson from "../package.json"

export const NODE_MIN_VERSION = packageJson.engines.node
export const PROMPTFOO_VERSION = packageJson.devDependencies.promptfoo
export const PROMPTFOO_VERSION = packageJson.peerDependencies.promptfoo
export const TYPESCRIPT_VERSION = packageJson.dependencies.typescript
export const DOCKERODE_VERSION = packageJson.dependencies.dockerode
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"gpt-tokenizer": "^2.2.1",
"html-escaper": "^3.0.3",
"html-to-text": "^9.0.5",
"ignore": "^5.3.1",
"ignore": "^5.3.2",
"inflection": "^3.0.0",
"ini": "^4.1.3",
"json5": "^2.2.3",
Expand All @@ -50,7 +50,7 @@
"mime-types": "^2.1.35",
"minimatch": "^10.0.1",
"minisearch": "^7.1.0",
"openai": "^4.55.0",
"openai": "^4.55.7",
"parse-diff": "^0.11.1",
"prettier": "^3.3.3",
"pretty-bytes": "^6.1.1",
Expand All @@ -59,7 +59,7 @@
"toml": "^3.0.0",
"tree-sitter-wasms": "^0.1.11",
"ts-dedent": "^2.2.0",
"tsx": "^4.16.5",
"tsx": "^4.17.0",
"typescript": "5.5.4",
"vectra": "^0.7.6",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { readText, writeText } from "./fs"
import { host } from "./host"
import { JSON5parse } from "./json5"
import { logVerbose } from "./util"
import { XMLParse, XMLTryParse } from "./xml"

export function createFileSystem(): Omit<WorkspaceFileSystem, "grep"> {
const fs: Omit<WorkspaceFileSystem, "grep"> = {
Expand Down Expand Up @@ -61,6 +62,11 @@ export function createFileSystem(): Omit<WorkspaceFileSystem, "grep"> {
const res = JSON5parse(file.content)
return res
},
readXML: async (f: string | WorkspaceFile) => {
const file = await fs.readText(f)
const res = XMLParse(file.content)
return res
},

Choose a reason for hiding this comment

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

There is no error handling for the XML parsing. If the XML is malformed, this could cause an unhandled exception.

generated by pr-review-commit missing_error_handling

}
;(fs as any).readFile = readText
return Object.freeze(fs)
Expand Down
5 changes: 5 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/promptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export async function createPromptContext(
const workspace: WorkspaceFileSystem = {
readText: (f) => runtimeHost.workspace.readText(f),
readJSON: (f) => runtimeHost.workspace.readJSON(f),
readXML: (f) => runtimeHost.workspace.readXML(f),

Choose a reason for hiding this comment

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

There is no error handling for the XML reading. If the XML is malformed or the file does not exist, this could cause an unhandled exception.

generated by pr-review-commit missing_error_handling

Choose a reason for hiding this comment

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

The readXML function is not defined in the runtimeHost.workspace object. Please ensure that this function is defined before it is called. 🕵️‍♀️

generated by pr-review-commit missing_function

writeText: (f, c) => runtimeHost.workspace.writeText(f, c),
findFiles: async (pattern, options) => {
const res = await runtimeHost.workspace.findFiles(pattern, options)
Expand Down
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 @@ -506,6 +506,11 @@ interface WorkspaceFileSystem {
*/
readJSON(path: string | WorkspaceFile): Promise<any>

/**
* Reads the content of a file and parses to XML, using the XML parser.
*/
readXML(path: string | WorkspaceFile): Promise<any>

/**
* Writes a file as text to the file system
* @param path
Expand Down
19 changes: 12 additions & 7 deletions packages/core/src/xml.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { XMLParse } from './xml'
import { describe, test } from 'node:test'
import assert from 'node:assert/strict'
import { XMLParse } from "./xml"
import { describe, test } from "node:test"
import assert from "node:assert/strict"

describe('xml', () => {
test('parse', () => {
const x = XMLParse('<root><a>1</a><b>2</b></root>')
describe("xml", () => {
test("parse elements", () => {
const x = XMLParse("<root><a>1</a><b>2</b></root>")
assert.deepStrictEqual(x, { root: { a: 1, b: 2 } })
})
})

test("parse attribute", () => {
const x = XMLParse('<root a="1"><b>2</b></root>')
assert.deepStrictEqual(x, { root: { b: 2, "@_a": 1 } })

Choose a reason for hiding this comment

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

The test case for XML parsing only checks for a single attribute. It would be more robust to include multiple attributes in the test case to ensure the parser can handle them correctly. 🧪

generated by pr-review-commit incomplete_test

})
})
9 changes: 8 additions & 1 deletion packages/core/src/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
}

export function XMLParse(text: string, options?: XMLParseOptions) {
const parser = new XMLParser(options)
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: "@_",
allowBooleanAttributes: true,
ignoreDeclaration: true,
parseAttributeValue: true,
...(options || {}),

Check failure on line 24 in packages/core/src/xml.ts

View workflow job for this annotation

GitHub Actions / build

The options object is being overwritten here, which could lead to unexpected behavior if options are passed to the `XMLParse` function. Consider merging the default options with the passed options instead of overwriting them.

Choose a reason for hiding this comment

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

The options object is being overwritten here, which could lead to unexpected behavior if options are passed to the XMLParse function. Consider merging the default options with the passed options instead of overwriting them.

generated by pr-review-commit unnecessary_code

Choose a reason for hiding this comment

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

The XML parser is now configured to parse attributes, which might lead to unexpected behavior if the rest of the codebase is not prepared to handle attributes.

generated by pr-review-commit unexpected_behavior

Choose a reason for hiding this comment

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

The XML parser options have been changed. This could potentially break existing functionality if the parser is used elsewhere in the codebase.

generated by pr-review-commit unexpected_change

})

Choose a reason for hiding this comment

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

There is no error handling for the XML parsing. If the XML is malformed, this could cause an unhandled exception.

generated by pr-review-commit missing_error_handling

Choose a reason for hiding this comment

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

The attribute name prefix is hardcoded to "@_". This could lead to confusion or unexpected behavior if other parts of the codebase expect a different prefix. Consider making this a configurable option. 🔄

generated by pr-review-commit hardcoded_values

return parser.parse(text)
}
5 changes: 5 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.

5 changes: 5 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.

5 changes: 5 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.

5 changes: 5 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.

5 changes: 5 additions & 0 deletions packages/sample/src/aici/genaiscript.d.ts

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

Loading
Loading