define user and define bot
Lesson 6 showed a configuration with no conversation rules: one model call, straight through, nothing checked. This lesson writes the first two Colang statements, which give the runtime something to recognise and something to say.
Colang is the language in .co files, and it has very little syntax. Two of its statements name things; a third joins them, and that is lesson 8. From here on the configuration lives in a folder, the way lesson 3 described.
The folder
models:
- type: main
engine: pretend
model: pretend-1
- type: embeddings
engine: pretend
model: pretend-embedThe main model answers users. The second one is new: the moment a configuration names a user intention, the runtime builds a searchable index over the example phrasings, and an index needs an embedding model. Lesson 9 writes that model and explains what it saves you.
define user ask refund policy
"How long does a refund take?"
"When do I get my money back?"
define bot give refund policy
"Refunds take five working days, once the parcel is back with us."define user ask refund policy gives a name to an intention, and the indented lines are examples of how somebody might express it. They are examples, not patterns: nothing is matched literally, and two are enough to start with.
define bot give refund policy does the same on the other side. The indented line is a sentence the assistant is allowed to say, word for word. That is the first real guarantee in this course: what the bot says here is what you wrote, not what a model produced.
Running it
import pretend_nemo
from nemoguardrails import LLMRails, RailsConfig
rails = LLMRails(RailsConfig.from_path("."))
print(rails.generate(messages=[{"role": "user", "content": "How long does a refund take?"}])["content"])Close, and not the sentence from rails.co, which ends with "once the parcel is back with us". The runtime recognised the intention and then answered from the model anyway, because nothing in the configuration says that this user intent leads to that bot message. Naming is not joining.
What did happen
import pretend_nemo
from nemoguardrails import LLMRails, RailsConfig
rails = LLMRails(RailsConfig.from_path("."))
rails.generate(messages=[{"role": "user", "content": "When do I get my money back?"}])
print(rails.explain().colang_history)
print([call.task for call in rails.explain().llm_calls])The history has a second line under the user's message: ask refund policy. That is the canonical form, and working it out is what the generate_user_intent call was for. Two more calls followed, because after naming the intent the runtime still had to decide what to do and then find words for it.
define usernames an intention and lists example phrasings.define botnames a reply and gives its exact words.- Neither one connects to the other. That is lesson 8.
- Add a third example utterance and then ask a fourth way of saying the same thing.
- Rename the intent to
ask about refundsin both places and check nothing changes.
You understood something today that you didn't yesterday.