Skip to content

Commit cbaf2f9

Browse files
committed
update readme
1 parent 81ff8c1 commit cbaf2f9

3 files changed

Lines changed: 63 additions & 11 deletions

File tree

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,61 @@ for speech in continuously_listen(silence_len=0.5):
224224
# do something to actually turn off the lamp
225225
print("Turning off the lamp")
226226
```
227+
228+
### Dialog Builder
229+
230+
You can create a high-level outline of a conversation using the Dialog Builder, available in the Aurora Dashboard. Once you have create the dialog, its ID will be available to you in the "Conversation Details" sidebar (under "Conversation ID"). You can use this ID to create and run the entire conversation in just a few lines of code:
231+
232+
```python
233+
# Import the package
234+
import auroraapi as aurora
235+
from auroraapi.dialog import Dialog
236+
237+
# Set your application settings
238+
aurora.config.app_id = "YOUR_APP_ID" # put your app ID here
239+
aurora.config.app_token = "YOUR_APP_TOKEN" # put your app token here
240+
241+
# Create the Dialog with the ID from the Dialog Builder
242+
dialog = Dialog("DIALOG_ID")
243+
244+
# Run the dialog
245+
dialog.run()
246+
```
247+
248+
If you've used a UDF (User-Defined Function) in the Dialog Builder, you can write the corresponding function and register it to the dialog using the `set_function` function. The UDF must take one argument, which is the dialog context. You can use it to retrieve data from other steps in the dialog and set custom data for future use (both in UDFs and in the builder).
249+
250+
If the UDF in the dialog builder has branching enabled, then you can return `True` or `False` to control which branch is taken.
251+
252+
```python
253+
from auroraapi.dialog import Dialog
254+
255+
def udf(context):
256+
# get data for a particular step
257+
data = context.get_step_data("step_id")
258+
# set some custom data
259+
context.set_user_data("id", "some data value")
260+
# return True to take the upward branch in the dialog builder
261+
return True
262+
263+
dialog = Dialog("DIALOG_ID")
264+
dialog.set_function("udf_id", udf)
265+
dialog.run()
266+
```
267+
268+
Here, `step_id` is the ID of a step in the dialog builder and `udf_id` is the ID of the UDF you want to register a function for. `id` is an arbitrary string you can use to identify the data you are setting.
269+
270+
You can also set a function when creating the `Dialog` that lets you handle whenever the current step changes or context is changed.
271+
272+
```python
273+
from auroraapi.dialog import Dialog
274+
275+
def handle_update(context):
276+
# this function is called whenever the current step is changed or
277+
# whenever the data in the context is updated
278+
# you can get the current dialog step like this
279+
step = context.get_current_step()
280+
print(step, context)
281+
282+
dialog = Dialog("DIALOG_ID", on_context_update=handle_update)
283+
dialog.run()
284+
```

auroraapi/dialog/context.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_step_data(self, key, default=None):
1717

1818
def set_user_data(self, key, value):
1919
self.user[key] = value
20+
self.on_update(self)
2021

2122
def get_user_data(self, key, default=None):
2223
if not key in self.user:
@@ -25,4 +26,7 @@ def get_user_data(self, key, default=None):
2526

2627
def set_current_step(self, step):
2728
self.current_step = step
28-
self.on_update(self)
29+
self.on_update(self)
30+
31+
def get_current_step(self):
32+
return self.current_step

dialog_demo.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)