Llm

Connect a call to AI language model.

1session.llm(
2{
3 vendor: 'openai',
4 model: "gpt-4o-realtime-preview-2024-10-01",
5 auth: {
6 apiKey
7 },
8 actionHook: '/final',
9 eventHook: '/event',
10 toolHook: '/toolCall',
11 events: [
12 'conversation.item.*',
13 'response.audio_transcript.done',
14 'input_audio_buffer.committed'
15 ],
16 llmOptions: {
17 response_create: {
18 modalities: ['text', 'audio'],
19 instructions: 'Please assist the user with their request.',
20 voice: 'alloy',
21 output_audio_format: 'pcm16',
22 temperature: 0.8,
23 max_output_tokens: 4096,
24 },
25 session_update: {
26 tools: [
27 {
28 name: 'get_weather',
29 type: 'function',
30 description: 'Get the weather at a given location',
31 parameters: {
32 type: 'object',
33 properties: {
34 location: {
35 type: 'string',
36 description: 'Location to get the weather from',
37 },
38 scale: {
39 type: 'string',
40 enum: ['fahrenheit', 'celsius'],
41 },
42 },
43 required: ['location', 'scale'],
44 },
45 },
46 ],
47 tool_choice: 'auto',
48 input_audio_transcription: {
49 model: 'whisper-1',
50 },
51 turn_detection: {
52 type: 'server_vad',
53 threshold: 0.8,
54 prefix_padding_ms: 300,
55 silence_duration_ms: 500,
56 }
57 }
58 }
59})

Parameters

model
stringRequired

Name of the LLM model.

vendor
stringRequired

Name of the LLM vendor.

actionHook
string

Webhook that will be called when the LLM session ends.

auth
object

Object containing authentication credentials; format according to the model.

connectOptions
object

Object containing information such as the URI to connect to.

eventHook
string

Webhook that will be called when a requested LLM event happens (e.g., transcript).

events
array

Array of event names listing the events requested (wildcards allowed).

llmOptions
object

Object containing instructions for the LLM; format dependent on the LLM model.

toolHook
string

Webhook that will be called when the LLM wants to call a function.

The following LLMs are currently supported:

  • OpenAI Realtime API
  • Deepgram Voice Agent
  • Ultravox
  • ElevenLabs

Example Applications

Please checkout the following example applications: