From a19aba515b0c17e9fa1b5dbeb22cef5581774b1e Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Sun, 22 Dec 2024 09:12:18 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20jq=20support=20to=20p?= =?UTF-8?q?arsers=20for=20data=20filtering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/parsers.ts | 2 ++ packages/core/src/types/prompt_template.d.ts | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/packages/core/src/parsers.ts b/packages/core/src/parsers.ts index a9e71784c..12d950b92 100644 --- a/packages/core/src/parsers.ts +++ b/packages/core/src/parsers.ts @@ -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 @@ -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, }) } diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index e6c80c37b..3ca5a7ba2 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -1568,6 +1568,7 @@ interface Parsers { * @param data data to render */ mustache(text: string | WorkspaceFile, data: Record): string + /** * Renders a jinja template */ @@ -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