Skip to content

Commit da299e2

Browse files
committed
feat(core/reports): PROMPT_RESULT function
1 parent 671deff commit da299e2

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

projects/core/models/src/utils/expression-utils.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Renamed to IF.
1414
`IF(condition, then, otherwise)`
1515
If the condition is true, evaluates and returns then, otherwise otherwise.
1616

17+
`PROMPT_RESULT(report_data, promptName)`
18+
Reads from report_data the result of the AI prompt with the specified name.
19+
1720
## Forms manipulation functions
1821

1922
`BUILD_DATASET(forms, schema?)`

projects/core/models/src/utils/expression-utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export class AjfExpressionUtils {
151151
FROM_REPS: {fn: FROM_REPS},
152152
GET_AGE: {fn: GET_AGE},
153153
GET_LABELS: {fn: GET_LABELS},
154+
PROMPT_RESULT: {fn: PROMPT_RESULT},
154155
INCLUDES: {fn: INCLUDES},
155156
IS_AFTER: {fn: IS_AFTER},
156157
IS_BEFORE: {fn: IS_BEFORE},
@@ -2103,3 +2104,13 @@ export function GET_LABELS(schema: any, values: string[]): string[] {
21032104
const choiceLabels = extractLabelsFromChoices(schema);
21042105
return values.map(val => (choiceLabels[val] != null ? choiceLabels[val] : val));
21052106
}
2107+
2108+
/**
2109+
* Reads from report_data the result of the AI prompt with the specified name.
2110+
*/
2111+
export function PROMPT_RESULT(report_data: any, promptName: string): string | undefined {
2112+
if (report_data.data == null) {
2113+
return undefined;
2114+
}
2115+
return report_data.data[promptName];
2116+
}

projects/core/reports/src/xls-report/hindikit-parser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ const functionArgs: {[name: string]: string[]} = {
407407
FROM_REPS: ["arg", "func(form)"],
408408
GET_AGE: ["arg", "arg?"],
409409
GET_LABELS: ["arg", "arg"],
410+
PROMPT_RESULT: ["arg", "arg"],
410411
INCLUDES: ["arg", "arg"],
411412
IS_AFTER: ["arg", "arg"],
412413
IS_BEFORE: ["arg", "arg"],

0 commit comments

Comments
 (0)