Skip to content

Commit

Permalink
Add overrides parameter for assistant start (#27)
Browse files Browse the repository at this point in the history
- Bump version to 1.1.1
- Add assistantOverrides parameter and OverrideAssistantDTO to web SDK
- Update docs for using assistant overrides
  • Loading branch information
edwinzhng authored May 2, 2024
1 parent 2cc10cf commit d2684c1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,40 @@ vapi.start({
...
});
```

```javascript
vapi.start('your-assistant-id');
```

The `start` method will initiate a new call.
The `start` method will initiate a new call.

You can also send text messages to the assistant aside from the audio input using the `send` method and passing appropriate `role` and `content`.
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`:

```javascript
const assistantOverrides = {
recordingEnabled: false,
variableValues: {
name: 'John',
},
};

vapi.start({
assistantId: 'your-assistant-id',
assistantOverrides: assistantOverrides,
});
```

You can send text messages to the assistant aside from the audio input using the `send` method and passing appropriate `role` and `content`.

```javascript
vapi.send({
type: "add-message",
type: 'add-message',
message: {
role: "system",
content: "The user has pressed the button, say peanuts",
role: 'system',
content: 'The user has pressed the button, say peanuts',
},
});

```

Possible values for the role are `system`, `user`, `assistant`, `tool` or `function`.
Expand Down Expand Up @@ -113,13 +130,12 @@ vapi.on('message', (message) => {
});

vapi.on('error', (e) => {
console.error(e)
console.error(e);
});
```

These events allow you to react to changes in the state of the call or speech.


## License

```
Expand Down
11 changes: 11 additions & 0 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,13 @@ export interface CreateAssistantDTO {
serverUrlSecret?: string;
}

export interface OverrideAssistantDTO extends CreateAssistantDTO {
/**
* These are template variables that will be replaced in the assistant messages and prompts.
*/
variableValues?: Record<string, string>;
}

export interface Assistant {
/** These are the options for the assistant's transcriber. */
transcriber?: DeepgramTranscriber | TalkscriberTranscriber;
Expand Down Expand Up @@ -1394,6 +1401,8 @@ export interface CreateOutboundCallDTO {
assistantId?: string;
/** This is the assistant that will be used for the call. To use an existing assistant, use `assistantId` instead. */
assistant?: CreateAssistantDTO;
/** These are assistant overrides for the call. */
assistantOverrides?: OverrideAssistantDTO;
/**
* This is the customer that will be called. To call a transient customer , use `customer` instead.
*
Expand Down Expand Up @@ -1427,6 +1436,8 @@ export interface CreateWebCallDTO {
assistantId?: string;
/** This is the assistant that will be used for the call. To use an existing assistant, use `assistantId` instead. */
assistant?: CreateAssistantDTO;
/** These are assistant overrides for the call. */
assistantOverrides?: OverrideAssistantDTO;
/** This will expose SIP URI you can use to connect to the call. Disabled by default. */
sipEnabled?: boolean;
/** This is the metadata associated with the call. */
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vapi-ai/web",
"version": "1.1.0",
"version": "1.1.1",
"description": "",
"main": "dist/vapi.js",
"types": "dist/vapi.d.ts",
Expand Down
8 changes: 6 additions & 2 deletions vapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Call, CreateAssistantDTO } from './api';
import { Call, CreateAssistantDTO, OverrideAssistantDTO } from './api';
import DailyIframe, {
DailyCall,
DailyEventObjectAppMessage,
Expand Down Expand Up @@ -112,7 +112,10 @@ export default class Vapi extends VapiEventEmitter {
this.speakingTimeout = null;
}

async start(assistant: CreateAssistantDTO | string): Promise<Call | null> {
async start(
assistant: CreateAssistantDTO | string,
assistantOverrides?: OverrideAssistantDTO,
): Promise<Call | null> {
if (this.started) {
return null;
}
Expand All @@ -124,6 +127,7 @@ export default class Vapi extends VapiEventEmitter {
await client.call.callControllerCreateWebCall({
assistant: typeof assistant === 'string' ? undefined : assistant,
assistantId: typeof assistant === 'string' ? assistant : undefined,
assistantOverrides,
})
).data;

Expand Down

0 comments on commit d2684c1

Please sign in to comment.