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

feat: ✨ add support for JSONL file parsing #1031

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const MDX_REGEX = /\.mdx$/i
export const MJS_REGEX = /\.mjs$/i
export const JS_REGEX = /\.js$/i
export const JSON5_REGEX = /\.json5?$/i
export const JSONL_REGEX = /\.jsonl$/i
export const PROMPTY_REGEX = /\.prompty$/i
export const TOOL_NAME = "GenAIScript"
export const SERVER_PORT = 8003
Expand Down
26 changes: 14 additions & 12 deletions packages/core/src/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { readFile } from "fs/promises"
import {
XLSX_REGEX,
CSV_REGEX,
Expand All @@ -9,19 +8,21 @@
XML_REGEX,
MD_REGEX,
MDX_REGEX,
JSONL_REGEX,
} from "./constants"
import { CSVParse, CSVTryParse } from "./csv"
import { CSVTryParse } from "./csv"
import { splitMarkdown } from "./frontmatter"
import { INIParse, INITryParse } from "./ini"
import { JSON5parse } from "./json5"
import { TOMLParse } from "./toml"
import { INITryParse } from "./ini"
import { JSON5TryParse } from "./json5"
import { TOMLTryParse } from "./toml"
import { XLSXParse } from "./xlsx"
import { XMLParse } from "./xml"
import { YAMLParse } from "./yaml"
import { XMLTryParse } from "./xml"
import { YAMLTryParse } from "./yaml"
import { resolveFileContent } from "./file"
import { TraceOptions } from "./trace"
import { host } from "./host"
import { fromBase64 } from "./base64"
import { JSONLTryParse } from "./jsonl"

Check failure on line 25 in packages/core/src/data.ts

View workflow job for this annotation

GitHub Actions / build

Missing import for JSONLTryParse. Did you forget to add it?
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

export async function dataTryParse(
file: WorkspaceFile,
Expand All @@ -40,13 +41,14 @@
else {
if (CSV_REGEX.test(filename)) data = CSVTryParse(content, options)
else if (INI_REGEX.test(filename)) data = INITryParse(content, options)
else if (TOML_REGEX.test(filename)) data = TOMLParse(content)
else if (TOML_REGEX.test(filename)) data = TOMLTryParse(content)
else if (JSON5_REGEX.test(filename))
data = JSON5parse(content, { repair: true })
else if (YAML_REGEX.test(filename)) data = YAMLParse(content)
else if (XML_REGEX.test(filename)) data = XMLParse(content, options)
data = JSON5TryParse(content, { repair: true })
else if (YAML_REGEX.test(filename)) data = YAMLTryParse(content)
else if (XML_REGEX.test(filename)) data = XMLTryParse(content, options)
else if (JSONL_REGEX.test(filename)) data = JSONLTryParse(content)
else if (MD_REGEX.test(filename) || MDX_REGEX.test(filename))
data = YAMLParse(splitMarkdown(content).frontmatter)
data = YAMLTryParse(splitMarkdown(content).frontmatter)
else {
return undefined // unknown
}
Expand Down
Loading