AI Frontend · Exercise 5 of 5 Previous
Advanced
A Tool That Runs in the Browser
The route declares showOrder with no execute, so the call comes to the browser. When it arrives, put the order id in #panel as Orders panel: ORD-1042, give the model the result, and make the chat continue.
Use onToolCall and addToolOutput (do not await it there), and sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls. If the id does not look like ORD- and four digits, answer with an output-error and the text Not a valid order id. instead. The model's final sentence appears in #answer.
What Check tests
- Before anything,
#panelsaysOrders panel: nothing - After
#good, the panel shows the order and the model answers - After
#bad, the panel does not change and the model says the id was not valid - The code does not
awaitaddToolOutput
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.