Render format
Developers can choose how the Gentrace UI renders an output key, making it easier to compare results from different code versions.
Types
render
The value type of the render
key is an object with type
and key
keys. We only support one key type at this time (html
).
We will add more upon request.
If your generative AI pipeline returned the following JSON output:
json
{"htmlOutput": "<h1>Hello world!</h1>"}
You would describe the render
value in the context in the following way:
json
{"type": "html","key": "htmlOutput"}
We only support top-level JSON keys. The following would not work.
json
{"content": {"htmlOutput": {"html": "<h1>Hello world!</h1>"}}}
json
{"type": "html","key": "content.htmlOutput.html"}
Example
Specify the render
key in the gentrace
context object when using the advanced SDK.
- TypeScript
- Python
typescript
import {init ,Pipeline } from "@gentrace/core";import {createUserHtml } from "./ai";init ({apiKey :process .env .GENTRACE_API_KEY });constpipeline = newPipeline ({slug : "create-html",});construnner =pipeline .start ();constuserId = "user-id-123";awaitrunner .measure ((userId ) => {// Omitted: code for AI-generated HTML contentconsthtmlOutput =createUserHtml (userId );return {htmlOutput , // ⬅️ The 'key' in the context below references this 'htmlOutput'};},[userId ],{context : {render : {type : "html",key : "htmlOutput", /* ⬅️ JSON path to the 'htmlOutput' returned above */},},},);constpipelineRunId = awaitrunner .submit ();
python
import gentracefrom app.ai import create_user_htmlPIPELINE_SLUG = "create-html"pipeline = gentrace.Pipeline(PIPELINE_SLUG,)runner = pipeline.start()user_id = "user-id-123"runner.measure(# Create AI-generated HTML for a particular userlambda user_id: {"htmlOutput": create_user_html(user_id), # ⬅️ The 'key' in the context below references this 'htmlOutput'},[user_id],{"step_info": {"context": {"render": {"type": "html","key": "htmlOutput", # ⬅️ JSON path to the 'htmlOutput' returned above},},}},)runner.submit()
The above example uses the measure()
function from our core tracer. .
Limitations
The render
key is only supported when using the core tracer components like measure()
and checkpoint()
. Learn more
about these tracing primitives here.
We intend to expand support for our provider-specific wrappers like OpenAI and Pinecone.