Skip to content

Commit

Permalink
render objects in $ instead of [object]
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jun 10, 2024
1 parent 9e7001d commit 9f87637
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/core/src/promptdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "./chat"
import { errorMessage } from "./error"
import { tidyData } from "./tidy"
import { inspect } from "./logging"

export interface PromptNode extends ContextExpansionOptions {
type?:
Expand Down Expand Up @@ -391,7 +392,15 @@ async function resolvePromptNode(
try {
const resolvedArgs: any[] = []
for (const arg of args) {
const resolvedArg = await arg
let resolvedArg = await arg
// render objects
if (
typeof resolvedArg === "object" ||
Array.isArray(resolvedArg)
)
resolvedArg = inspect(resolvedArg, {
maxDepth: 3,
})
resolvedArgs.push(resolvedArg ?? "")
}
const value = dedent(strings, ...resolvedArgs)
Expand Down
9 changes: 7 additions & 2 deletions packages/sample/genaisrc/defdata.genai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "defData demo",
model: "gpt-3.5-turbo",
model: "openai:gpt-3.5-turbo",
tests: {},
system: ["system"]
})
Expand All @@ -17,5 +17,10 @@ defData(
{ format: "csv" }
)

$`Identify the data formats of A,B,C,D and return the format results as CSV with key value pairs variable,format.
$`
E:
${[{ a: 7, b: 8 },
{ a: 9, b: 10 },]}
Identify the data formats of A,B,C,D,E and return the format results as CSV with key value pairs variable,format.
`

0 comments on commit 9f87637

Please sign in to comment.