Output Builder - answerrocket/answerrocket-python-client GitHub Wiki

Output Builder

Overview

You can use the output builder module to construct and send payloads to the Max frontend to be viewed by the end-users of your skill. A skill output is constructed as a JSON object with keys that represent various properties that the frontend may use when rendering your skill. This XML object can be sequentially built and sent to the client as it is updated (as many times as needed) to give the end-user new rendered content as it becomes available (similar to how ChatGPT streams content to the client).

While you can construct output JSON objects manually, it is recommended that you use the methods provided below to assist with constructing blocks, sending updates to the client, and managing your final skill output.

It is also important to note that when testing these methods locally, no updates to the AnswerRocket UI on the instance you are connected to will occur; Frontend updates will only be operational when your skill code is uploaded to and running on an AnswerRocket instance.

Methods

add_block(title, loading_status, xml)

update_block(block_id, title, loading_info, xml)

end_block(block_id)

merge_output(changes)

Examples

Add a Simple Block With HTML Content

# Init AnswerRocket Client
arc = AnswerRocketClient(url='https://your-answerrocket-instance.com', token='<your_api_token>')

# Start a new block (With only a title for now)
arc.output.add_block(title='My HTML Block')

# Use your favorite XML library to construct an HTML payload
variables =  E.Variables()
html_content = "<b>TEST CONTENT!</b><small>Small content</small>"
html_body = E.Box(E.HTMLIFrame(FS(html_content), height="auto"))
data = E.data()
app = E.App(
    variables,
    data,
    E.Body(
        E.HorizontalSpacer(height="10px"),
        html_body,
    ),
    key="chart_and_insights",
)

# XML payload must be converted to a string
app = ET.tostring(app, encoding="unicode")

# Update the current block with the new content and send the update to the client
arc.output.update_block(xml=app)

# Close the current block
arc.output.end_block()

# Return the entire constructed payload
return arc.output.current_output
⚠️ **GitHub.com Fallback** ⚠️