File size: 1,466 Bytes
3696fe2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import os
import sys
from tools.dialog_handler import handle_message
from tools import nlu_tool

def prompt_loop():
    print("Interactive CLI for collection assistant. Type 'exit' to quit.")
    context = {}
    while True:
        msg = input('You: ').strip()
        if msg.lower() in ('exit','quit'):
            print('Goodbye')
            break

        # run NLU first to see what is missing
        nlu = nlu_tool.extract_intent_and_slots(msg)
        intent = nlu.get('intent')
        print(f"(NLU -> intent={intent}, slots={nlu.get('slots')})")

        # call handler - it will return either a prompt for missing slot or a confirmation
        out = handle_message(msg, context=context)
        print('Assistant:', out['response'])

        # If handler requested a missing slot (no request created), accept next input as value and append to message
        if out.get('request') is None and 'Please provide' in out['response'] or out['response'].endswith('?'):
            # ask user to provide the requested info and re-run
            follow = input('You (reply): ').strip()
            # naive: append to previous message for NLU re-processing
            combined = follow
            out2 = handle_message(combined, context=context)
            print('Assistant:', out2['response'])
            if out2.get('request'):
                print('Created request:', out2['request'])

if __name__ == '__main__':
    prompt_loop()