Skip to content
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
22 changes: 14 additions & 8 deletions pdl-live-react/src/view/masonry/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {

import type Tile from "./Tile"
import { hasStabilityMetrics, type StabilityMetric } from "./stability"
import { match, P } from "ts-pattern"
import { block_code_cleanup } from "../../pdl_code_cleanup"

/** The final result of the block */
/* function result(block: import("../../pdl_ast").PdlBlock) {
Expand Down Expand Up @@ -60,14 +62,18 @@ export default function computeModel(block: import("../../pdl_ast").PdlBlock) {
const { resultForDisplay, meta, lang } = isLLMBlock(block)
? extractStructuredModelResponse(block)
: {
resultForDisplay:
typeof block.pdl__result === "object"
? stringify(block.pdl__result)
: typeof block.pdl__result === "string" ||
typeof block.pdl__result === "number" ||
typeof block.pdl__result === "boolean"
? block.pdl__result
: String(block.pdl__result),
resultForDisplay: match(block.pdl__result)
.with(
{ kind: "function", function: P._, return: P._ },
// @ts-expect-error: unable to check that it is a function block
(closure) => stringify(block_code_cleanup(closure)),
)
.with({}, (result) => stringify(result))
.with(
P.union(P.string, P.number, P.boolean),
(result) => result,
)
.otherwise((result) => String(result)),
meta: undefined,
lang:
typeof block.pdl__result === "object"
Expand Down
12 changes: 5 additions & 7 deletions src/pdl/pdl_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,7 @@ def block_to_dict( # noqa: C901
]:
d["contribute"] = contribute_to_list(block.contribute)
if block.pdl__result is not None:
if isinstance(block.pdl__result, FunctionBlock):
d["pdl__result"] = ""
elif json_compatible:
d["pdl__result"] = as_json(block.pdl__result.result())
else:
d["pdl__result"] = block.pdl__result.result()
d["pdl__result"] = data_to_dict(block.pdl__result.result(), json_compatible)
if block.parser is not None:
d["parser"] = parser_to_dict(block.parser)
# if block.pdl__location is not None:
Expand All @@ -302,7 +297,10 @@ def block_to_dict( # noqa: C901


def data_to_dict(data: Any, json_compatible: bool):
if json_compatible:
d: Any
if isinstance(data, FunctionBlock):
d = block_to_dict(data, json_compatible)
elif json_compatible:
d = as_json(data)
else:
d = data
Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def __execute_file(self, pdl_file_name: str) -> None:

exec_result.result = str(output["result"])
exec_result.error_code = ExecutionErrorCode.NO_ERROR

pdl.write_trace("/dev/null", output["trace"])
except PDLParseError:
exec_result.error_code = ExecutionErrorCode.PARSE_ERROR
except Exception:
Expand Down
Loading