Skip to content

Commit

Permalink
feat: ✨ add jq support to parsers for data filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 22, 2024
1 parent f97cd3f commit a19aba5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { jinjaRender } from "./jinja"
import { createDiff, llmifyDiff } from "./diff"
import { tidyData } from "./tidy"
import { hash } from "./crypto"
import { jq } from "./jq"

export async function createParsers(options: {
trace: MarkdownTrace
Expand Down Expand Up @@ -122,5 +123,6 @@ export async function createParsers(options: {
tidyData: (rows, options) => tidyData(rows, options),
hash: async (text, options) => await hash(text, options),
unfence: unfence,
jq: jq,
})
}
8 changes: 8 additions & 0 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,7 @@ interface Parsers {
* @param data data to render
*/
mustache(text: string | WorkspaceFile, data: Record<string, any>): string

/**
* Renders a jinja template
*/
Expand All @@ -1589,6 +1590,13 @@ interface Parsers {
*/
tidyData(rows: object[], options?: DataFilter): object[]

/**
* Applies a jq query to the data
* @param data data object to filter
* @param query jq query
*/
jq(data: any, query: string): any

/**
* Computes a sha1 that can be used for hashing purpose, not cryptographic.
* @param content content to hash
Expand Down

0 comments on commit a19aba5

Please sign in to comment.