-
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
split docs/produtct dependencies #621
Changes from 9 commits
2139bcd
5b8345e
fd7731e
b3fd339
ee36074
7c8d065
96f0f74
29ac4dc
e6f60b9
90dde36
f9f99af
48ebef7
d6abf83
ba9327e
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 |
---|---|---|
|
@@ -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 | ||
|
||
|
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 |
---|---|---|
|
@@ -26,4 +26,4 @@ | |
"devDependencies": { | ||
"zx": "^8.1.4" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
--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 | ||
``` | ||
|
@@ -291,11 +291,11 @@ | |
Options: | ||
-h, --help display help for command | ||
|
||
Commands: | ||
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 command usage for
|
||
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 | ||
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 command usage for
|
||
code <file> [query] Parse code using tree sitter and executes a | ||
query | ||
tokens [options] <files...> Count tokens in a set of files | ||
|
@@ -305,7 +305,7 @@ | |
### `parse fence` | ||
|
||
``` | ||
Usage: genaiscript parse fence [options] <language> | ||
Usage: genaiscript parse fence [options] <language> <file> | ||
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 command usage for
|
||
|
||
Extracts a code fenced regions of the given type | ||
|
||
|
@@ -338,7 +338,7 @@ | |
### `parse html-to-text` | ||
|
||
``` | ||
Usage: genaiscript parse html-to-text [options] [file] | ||
Usage: genaiscript parse html-to-text [options] <file> | ||
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 command usage for
|
||
|
||
Parse an HTML file into text | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
``` | ||
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
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
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. A new
|
||
|
||
### `writeText` | ||
|
||
Writes text to a file, relative to the workspace root. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 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 code fence around the JSON example should be
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 example provided for
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
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
|
||
``` | ||
|
||
## front matter | ||
|
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 |
---|---|---|
|
@@ -249,7 +249,7 @@ | |
.alias("parsers") | ||
.description("Parse various outputs") | ||
parser | ||
.command("fence <language>") | ||
.command("fence <language> <file>") | ||
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
|
||
.description("Extracts a code fenced regions of the given type") | ||
.action(parseFence) | ||
|
||
|
@@ -264,7 +264,7 @@ | |
.action(parseDOCX) | ||
|
||
parser | ||
.command("html-to-text [file]") | ||
.command("html-to-text <file>") | ||
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 function
|
||
.description("Parse an HTML file into text") | ||
.action(parseHTMLToText) | ||
|
||
|
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" | ||
|
@@ -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( | ||
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 function
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 function
|
||
(f) => f.language === language | ||
) | ||
console.log(fences.map((f) => f.content).join("\n\n")) | ||
|
@@ -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) | ||
} | ||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"> = { | ||
|
@@ -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 | ||
}, | ||
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 no error handling for the XML parsing. If the XML is malformed, this could cause an unhandled exception.
|
||
} | ||
;(fs as any).readFile = readText | ||
return Object.freeze(fs) | ||
|
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 |
---|---|---|
|
@@ -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), | ||
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 no error handling for the XML reading. If the XML is malformed or the file does not exist, this could cause an unhandled exception.
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
|
||
writeText: (f, c) => runtimeHost.workspace.writeText(f, c), | ||
findFiles: async (pattern, options) => { | ||
const res = await runtimeHost.workspace.findFiles(pattern, options) | ||
|
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 } }) | ||
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 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. 🧪
|
||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 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 options object is being overwritten here, which could lead to unexpected behavior if options are passed to the
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 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.
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 XML parser options have been changed. This could potentially break existing functionality if the parser is used elsewhere in the codebase.
|
||
}) | ||
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 no error handling for the XML parsing. If the XML is malformed, this could cause an unhandled exception.
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 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. 🔄
|
||
return parser.parse(text) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 option name
--promptfoo-version
seems incorrect. It should likely be--prompt-version
.