Skip to main content
After reading this guide, you will know:
  • 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.
Once a ticket is triaged, the team needs its details: which orders and which products it’s about. In this chapter, the model finds every order number and product a new ticket mentions, and the ticket’s page lists them.

1. A signature for the details

Finding details is a task of its own, so it gets its own signature rather than more outputs on TriageTicket. 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
A ticket can mention any number of orders and products, so each output is a list. 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. Replace app/models/ticket.rb with:
app/models/ticket.rb
Creating a ticket now waits for two model calls, one after the other.

5. Show the lists

List the order numbers and products on the ticket’s page, when it has any. Replace app/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, so DummyLM needs two answers, in that order. Replace test/fixtures/files/ticket_answers.yml with:
test/fixtures/files/ticket_answers.yml
Each test file gains a test for the details. Replace test/models/ticket_test.rb with:
test/models/ticket_test.rb
And replace test/integration/ticket_submission_test.rb with:
test/integration/ticket_submission_test.rb

8. Check your work

Both should pass, with no offenses and 4 tests.

If something goes wrong

If a test fails with DSPyRb::AdapterParseError, a call got an answer that doesn’t fit its signature: ticket_answers.yml is missing an answer, or has them in the wrong order. Triage’s answer comes first.

Comparing with the tag

The chapter-3 tag holds the app at the end of this chapter. To compare yours with it:
Expect the same files to differ as in chapter 1.

Next

Reasoning

Have the model reason before it triages, and show why on each ticket’s page.