Install it, and what a config is
Lesson 2 ended with three things a hand-written guard cannot do. NeMo Guardrails provides all three, and the first thing to understand about it is that the unit of work is not a class you construct: it is a folder you write.
Install
pip install nemoguardrailsThat pulls in a runtime, a parser for the configuration language, and an embedding index. It does not pull in any model client. Which model you talk to is a line of configuration, not an install option.
A config is a folder
myconfig/
config.yml what models to use, which rails are on, which prompts to use
rails.co the conversation rules, written in Colang
config.py optional Python, run once when the config loadsAny number of .co files are allowed and they are all read. The names do not matter; the extension does. config.yml and config.py are the two fixed names.
The smallest config.yml
models:
- type: main
engine: openai
model: gpt-4o-minitype says what the model is for, and main is the one that answers users. engine names a provider the runtime knows how to build, and model is that provider's own name for the model.
Reading it without running it
from nemoguardrails import RailsConfig
config = RailsConfig.from_content(yaml_content="""
models:
- type: main
engine: openai
model: gpt-4o-mini
""")
main = config.models[0]
print(main.type, main.engine, main.model)
print("colang version:", config.colang_version)RailsConfig.from_content takes the same YAML as a string, which is what most lessons here use so that a whole configuration fits on the page. RailsConfig.from_path reads a folder, and lesson 26 switches to it.
colang_version came out as 1.0 and nothing in the YAML asked for it. That is the default, and it is the version this course teaches. Colang 2.0 exists, is still labelled beta in its own changelog, and is named in lesson 30.
What it will not do yet
Nothing above talked to a model, because engine: openai needs a key. The next lesson replaces that line with an engine you write yourself.
- Add a second entry under
modelswithtype: embeddingsand printlen(config.models). - Set
colang_version: "2.0"in the YAML and print it again.
Slow is fine. Stopping is the only problem.