NeMo-Guardrails
NeMo-Guardrails copied to clipboard
Add bot message instruction
What is this PR:
- [ ] Bug fix
- [x] Feature
- [ ] Chore
Description: In this PR, it is possible to insert instruction at the stage where the Bot generates messages. The usage of this feature intend to scenarios such as forcing a language of the Bot's message.
For example:
import logging
from nemoguardrails import LLMRails, RailsConfig
logging.basicConfig(level=logging.DEBUG)
COLANG_CONFIG = """
define user express greeting
"hello"
define flow greeting
user express greeting
bot express greeting
bot ask how are you
"""
YAML_CONFIG = """
instructions:
- type: bot_message
content: |
BOT MUST RESPOND ONLY IN JAPANESE AND JAPANESE CHARACTERS.
models:
- type: main
engine: openai
model: gpt-3.5-turbo
"""
def demo():
config = RailsConfig.from_content(COLANG_CONFIG, YAML_CONFIG)
app = LLMRails(config=config, verbose=True)
history = []
while True:
user_message = input("> ")
history.append({"role": "user", "content": user_message})
bot_message = app.generate(messages=history)
history.append(bot_message)
print(history)
print(f"\033[92m{bot_message['content']}\033[0m")
if __name__ == "__main__":
demo()
Example reuslt:
user> hello
bot> こんにちは!今日は何かお手伝いできますか? お元気ですか?