From 75dde1e9d71aff993172ccb54638560ef4dfed99 Mon Sep 17 00:00:00 2001 From: Edwin Zhang Date: Wed, 1 May 2024 16:54:59 -0400 Subject: [PATCH 1/3] Update Python SDK to support assistant overrides --- README.md | 18 ++++++++++++++++++ README.rst | 20 +++++++++++++++++++- setup.py | 2 +- vapi_python/vapi_python.py | 6 +++--- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 84bd081..64e5eba 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,24 @@ vapi.start(assistant=assistant) The `start` method will initiate a new call. +You can also override existing assistant parameters or set variables with the `assistant_overrides` parameter: + +```python +# Assume the below has already been set for the assistant with ID 'your-assistant-id' +assistant = { + 'firstMessage': 'Hey, {{name}} how are you?', +} + +assistant_overrides = { + "recordingEnabled": False, + "variableValues": { + "name": "John" + } +} + +vapi.start(assistant_id='your-assistant-id', assistant_overrides=assistant_overrides) +``` + You can stop the session by calling the `stop` method: ```python diff --git a/README.rst b/README.rst index f27df0f..c0126ca 100644 --- a/README.rst +++ b/README.rst @@ -75,7 +75,25 @@ or vapi.start(assistant=assistant) -The `start` method will initiate a new call. +The `start` method will initiate a new call. + +You can also override existing assistant parameters or set variables with the `assistant_overrides` parameter: + +.. code-block:: python + + # Assume the below has already been set for the assistant with ID 'your-assistant-id' + assistant = { + 'firstMessage': 'Hey, {{name}} how are you?', + } + + assistant_overrides = { + "recordingEnabled": False, + "variableValues": { + "name": "John" + } + } + + vapi.start(assistant_id='your-assistant-id', assistant_overrides=assistant_overrides) You can stop the session by calling the `stop` method: diff --git a/setup.py b/setup.py index ed5e1e5..1ed5194 100644 --- a/setup.py +++ b/setup.py @@ -49,6 +49,6 @@ def read_requirements(file): test_suite='tests', tests_require=test_requirements, url='https://github.com/jordan.cde/vapi_python', - version='0.1.8', + version='0.1.9', zip_safe=False, ) diff --git a/vapi_python/vapi_python.py b/vapi_python/vapi_python.py index 44fe220..e6f5ac8 100644 --- a/vapi_python/vapi_python.py +++ b/vapi_python/vapi_python.py @@ -27,12 +27,12 @@ def __init__(self, *, api_key, api_url="https://api.vapi.ai"): self.api_key = api_key self.api_url = api_url - def start(self, *, assistant_id=None, assistant=None): + def start(self, *, assistant_id=None, assistant=None, assistant_overrides=None): # Start a new call if assistant_id: - assistant = {'assistantId': assistant_id} + assistant = {'assistantId': assistant_id, 'assistantOverrides': assistant_overrides} elif assistant: - assistant = {'assistant': assistant} + assistant = {'assistant': assistant, 'assistantOverrides': assistant_overrides} call_id, web_call_url = create_web_call( self.api_url, self.api_key, assistant) From 54e21012f698a7f23167bcd7f79c82b0fd86c378 Mon Sep 17 00:00:00 2001 From: Edwin Zhang Date: Wed, 1 May 2024 17:21:42 -0400 Subject: [PATCH 2/3] Docs copy --- README.md | 16 ++++++---------- README.rst | 8 ++------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 64e5eba..f873299 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ You can install the package via pip: pip install vapi_python ``` -On Mac, you might need to install `brew install portaudio` to satisfy `pyaudio`'s dependency requirement. +On Mac, you might need to install `brew install portaudio` to satisfy `pyaudio`'s dependency requirement. ## Usage @@ -31,7 +31,9 @@ You can start a new call by calling the `start` method and passing an `assistant ```python vapi.start(assistant_id='your-assistant-id') ``` + or + ```python assistant = { 'firstMessage': 'Hey, how are you?', @@ -45,16 +47,12 @@ assistant = { vapi.start(assistant=assistant) ``` -The `start` method will initiate a new call. +The `start` method will initiate a new call. -You can also override existing assistant parameters or set variables with the `assistant_overrides` parameter: +You can override existing assistant parameters or set variables with the `assistant_overrides` parameter. +Assume the first message is `Hey, {{name}} how are you?` and you want to set the value of `name` to `John`: ```python -# Assume the below has already been set for the assistant with ID 'your-assistant-id' -assistant = { - 'firstMessage': 'Hey, {{name}} how are you?', -} - assistant_overrides = { "recordingEnabled": False, "variableValues": { @@ -98,5 +96,3 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` - - diff --git a/README.rst b/README.rst index c0126ca..fe0672c 100644 --- a/README.rst +++ b/README.rst @@ -77,15 +77,11 @@ or The `start` method will initiate a new call. -You can also override existing assistant parameters or set variables with the `assistant_overrides` parameter: +You can override existing assistant parameters or set variables with the `assistant_overrides` parameter. +Assume the first message is `Hey, {{name}} how are you?` and you want to set the value of `name` to `John`: .. code-block:: python - # Assume the below has already been set for the assistant with ID 'your-assistant-id' - assistant = { - 'firstMessage': 'Hey, {{name}} how are you?', - } - assistant_overrides = { "recordingEnabled": False, "variableValues": { From ce9be940db5a067b50f4141ed37af10593ae13fa Mon Sep 17 00:00:00 2001 From: Edwin Zhang Date: Fri, 24 May 2024 17:57:16 -0400 Subject: [PATCH 3/3] Support multiple assistants in start --- vapi_python/vapi_python.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/vapi_python/vapi_python.py b/vapi_python/vapi_python.py index e6f5ac8..e081934 100644 --- a/vapi_python/vapi_python.py +++ b/vapi_python/vapi_python.py @@ -27,12 +27,24 @@ def __init__(self, *, api_key, api_url="https://api.vapi.ai"): self.api_key = api_key self.api_url = api_url - def start(self, *, assistant_id=None, assistant=None, assistant_overrides=None): + def start( + self, + *, + assistant_id=None, + assistant=None, + assistants=None, + assistant_override=None, + assistant_overrides=None, + ): # Start a new call if assistant_id: - assistant = {'assistantId': assistant_id, 'assistantOverrides': assistant_overrides} + assistant = {'assistantId': assistant_id, 'assistantOverride': assistant_override} elif assistant: - assistant = {'assistant': assistant, 'assistantOverrides': assistant_overrides} + assistant = {'assistant': assistant, 'assistantOverride': assistant_override} + elif assistants: + assistant = {'assistants': assistants, 'assistantOverride': assistant_overrides, 'assistantOverrides': assistant_overrides} + else: + raise Exception("Error: No assistant specified.") call_id, web_call_url = create_web_call( self.api_url, self.api_key, assistant)