- how to ask the model for a list;
- how to add a second model call to a ticket’s steps;
- how to script two model calls in a test.
1. A signature for the details
Finding details is a task of its own, so it gets its own signature rather than more outputs onTriageTicket. That keeps each signature one small task you can try alone in the console. The cost is a second model call for each ticket.
Create app/signatures/extract_details.rb:
app/signatures/extract_details.rb
DSPyRb::Types::List[String] asks the model for an array of strings, which may be empty.
Customers often put the order number only in the subject, as in “Refund for order #1234”. So the instructions and the order_numbers description tell the model to look in both the subject and the body.
2. Try it in the console
Try it on chapter 2’s sample ticket:3. Columns for the lists
Give tickets a JSON column for each list, with the same name as its output:4. A second step for the details
Add the details after triage. Replaceapp/models/ticket.rb with:
app/models/ticket.rb
5. Show the lists
List the order numbers and products on the ticket’s page, when it has any. Replaceapp/views/tickets/_ticket.html.erb with:
app/views/tickets/_ticket.html.erb
6. See it in the browser
Start the server, and create a ticket at http://localhost:3000/tickets/new with the subject “Return for order 7788” and the body “I would like to return the espresso cups, and the milk jug from order 7790.” The ticket’s page shows “Order numbers: 7788 and 7790”, one from the subject and one from the body, and “Products: espresso cups and milk jug”.7. Two answers in the tests
Each new ticket now makes two model calls, triage first, soDummyLM needs two answers, in that order. Replace test/fixtures/files/ticket_answers.yml with:
test/fixtures/files/ticket_answers.yml
test/models/ticket_test.rb with:
test/models/ticket_test.rb
test/integration/ticket_submission_test.rb with:
test/integration/ticket_submission_test.rb
8. Check your work
If something goes wrong
Comparing with the tag
Thechapter-3 tag holds the app at the end of this chapter. To compare yours with it:
Next
Reasoning
Have the model reason before it triages, and show why on each ticket’s page.