NeMo-Guardrails
NeMo-Guardrails copied to clipboard
Fix/multiline few shot colang 2
This PR fixes the issue of multiline bot say parameter, which could be a follow-up problem of the #748. Consider the following application:
import core
import llm
flow main
activate llm continuation
bot say "Hello! What movie preferences or needs do you have?"
user said wants to know about kid friendly movies
bot say "1. Toy Story (1995)\n2. Finding Nemo (2003)\n3. The Lion King (1994)\n4. Moana (2016)\n5. Frozen (2013)\n6. Zootopia (2016)\n7. Despicable Me (2010)\n8. The Incredibles (2004)\n9.
Shrek (2001)\n10. Paddington (2014)"
user said wants to know age suitability
flow user said wants to know about kid friendly movies
user said "i want to learn about kid friendly movies"
flow user said wants to know age suitability
user said "for what age are these movies suitable?"
After the kid-friendly movies are printed, if the user intent is undefined, the call to LLM's prompt would include this:
User
user action: user said "recommend some movies for kids"
Bot
user intent: user said wants to know about kid friendly movies
bot action: bot say "Here are some movies for kids:"
bot action: bot say "1. Toy Story (1995)
2. Finding Nemo (2003)
3. The Lion King (1994)
4. Moana (2016)
5. Frozen (2013)
6. Zootopia (2016)
7. Despicable Me (2010)
8. The Incredibles (2004)
9. Shrek (2001)
10. Paddington (2014)"
which is misleading for few-shot learning. This leads to a generation like:
LLM Completion
bot action: bot say "Sure! Here are some kid-friendly movies released after 2010:"
bot action: bot say "1. Moana (2016)
2. Zootopia (2016)
3. Finding Dory (2016)
4. The Lego Movie (2014)
5. Inside Out (2015)
6. Coco (2017)
7. Paddington 2 (2017)
8. Ralph Breaks the Internet (2018)
9. Toy Story 4 (2019)
10. Onward (2020)"
First of all, the first line which is considered a flow name is syntactically incorrect. This PR escapes non-word chars in generated flow names. Secondly, the correct generation should be like:
LLM Completion
bot intent: bot provide a list of kids' movies released after 2010
bot action: bot say "Sure! Here are some kid-friendly movies released after 2010:\n1. Frozen (2013)\n2. Moana (2016)\n3. Zootopia (2016)\n4. Finding Dory (2016)\n5. The Lego Movie (2014)\n6. Inside Out
(2015)\n7. Coco (2017)\n8. Ralph Breaks the Internet (2018)\n9. Toy Story 4 (2019)\n10. Onward (2020)"
This PR converts new lines in params to \n tokens to fix this problem.