Consider that you want to extract someone's call name(s) during a dialogue in real time:
S: Hi, how should I call you?
U: My friends call me Jin, but you can call me Jinho. Some students call me Dr. Choi as well.
Design a prompt that extracts all call names provided by the user.
How does the speaker want to be called? Respond in the one-line JSON format such as {"call_names": ["Mike", "Michael"]}: My friends call me Pete, my students call me Dr. Parker, and my parents call me Peter.
In "My friends call me Pete, my students call me Dr. Parker, and my parents call me Peter.", how does the speaker want to be called? Respond in the following JSON format: {"call_names": ["Mike", "Michael"]}
Let us write a function that takes the user input and returns the GPT output in the JSON format:
#3: is a function that takes a variable table and returns a string output.
Finally, we use the macros in a dialogue flow:
transitions ={'state':'start','`Hi, how should I call you?`':{'#SET_CALL_NAMES':{'`Nice to meet you,` #GET_CALL_NAME `. Can you tell me where your office is and when your general office hours are?`':{'#SET_OFFICE_LOCATION_HOURS':{'`Can you confirm if the following office infos are correct?` #GET_OFFICE_LOCATION_HOURS':{}}}},'error':{'`Sorry, I didn\'t understand you.`':'end'}}}macros ={'GET_CALL_NAME':MacroNLG(get_call_name),'GET_OFFICE_LOCATION_HOURS':MacroNLG(get_office_location_hours),'SET_CALL_NAMES':MacroGPTJSON('How does the speaker want to be called?', {V.call_names.name: ["Mike", "Michael"]}),'SET_OFFICE_LOCATION_HOURS':MacroGPTJSON('Where is the speaker\'s office and when are the office hours?', {V.office_location.name: "White Hall E305", V.office_hours.name: [{"day": "Monday", "begin": "14:00", "end": "15:00"}, {"day": "Friday", "begin": "11:00", "end": "12:30"}]}, {V.office_location.name: "N/A", V.office_hours.name: []}, set_office_location_hours ),}
The helper methods can be as follow:
defget_call_name(vars: Dict[str, Any]): ls =vars[V.call_names.name]return ls[random.randrange(len(ls))]defget_office_location_hours(vars: Dict[str, Any]):return'\n- Location: {}\n- Hours: {}'.format(vars[V.office_location.name], vars[V.office_hours.name])defset_office_location_hours(vars: Dict[str, Any],user: Dict[str, Any]):vars[V.office_location.name]= user[V.office_location.name]vars[V.office_hours.name]={d['day']: [d['begin'], d['end']] for d in user[V.office_hours.name]}