Skip to content

Commit ed5d3b7

Browse files
authored
Conversation.py update for elevenlabs_extra_body (elevenlabs#403)
* Conversation.py update for elevenlabs_extra_body * updates * naming * addressing * change * lint * addressed compile error * ksdjfghksdjhdf
1 parent 243f851 commit ed5d3b7

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/elevenlabs/conversational_ai/conversation.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ def interrupt(self):
5252
"""
5353
pass
5454

55-
55+
class ConversationConfig:
56+
"""Configuration options for the Conversation."""
57+
def __init__(
58+
self,
59+
extra_body: Optional[dict] = None,
60+
conversation_config_override: Optional[dict] = None,
61+
):
62+
self.extra_body = extra_body or {}
63+
self.conversation_config_override = conversation_config_override or {}
64+
5665
class Conversation:
5766
client: BaseElevenLabs
5867
agent_id: str
5968
requires_auth: bool
60-
69+
config: ConversationConfig
6170
audio_interface: AudioInterface
6271
callback_agent_response: Optional[Callable[[str], None]]
6372
callback_agent_response_correction: Optional[Callable[[str, str], None]]
@@ -76,6 +85,8 @@ def __init__(
7685
*,
7786
requires_auth: bool,
7887
audio_interface: AudioInterface,
88+
config: Optional[ConversationConfig] = None,
89+
7990
callback_agent_response: Optional[Callable[[str], None]] = None,
8091
callback_agent_response_correction: Optional[Callable[[str, str], None]] = None,
8192
callback_user_transcript: Optional[Callable[[str], None]] = None,
@@ -104,6 +115,7 @@ def __init__(
104115

105116
self.audio_interface = audio_interface
106117
self.callback_agent_response = callback_agent_response
118+
self.config = config or ConversationConfig()
107119
self.callback_agent_response_correction = callback_agent_response_correction
108120
self.callback_user_transcript = callback_user_transcript
109121
self.callback_latency_measurement = callback_latency_measurement
@@ -136,6 +148,15 @@ def wait_for_session_end(self) -> Optional[str]:
136148

137149
def _run(self, ws_url: str):
138150
with connect(ws_url) as ws:
151+
ws.send(
152+
json.dumps(
153+
{
154+
"type": "conversation_initiation_client_data",
155+
"custom_llm_extra_body": self.config.extra_body,
156+
"conversation_config_override": self.config.conversation_config_override,
157+
}
158+
)
159+
)
139160

140161
def input_callback(audio):
141162
ws.send(
@@ -161,6 +182,7 @@ def _handle_message(self, message, ws):
161182
event = message["conversation_initiation_metadata_event"]
162183
assert self._conversation_id is None
163184
self._conversation_id = event["conversation_id"]
185+
164186
elif message["type"] == "audio":
165187
event = message["audio_event"]
166188
if int(event["event_id"]) <= self._last_interrupt_id:
@@ -212,4 +234,4 @@ def _get_signed_url(self):
212234
f"v1/convai/conversation/get_signed_url?agent_id={self.agent_id}",
213235
method="GET",
214236
)
215-
return response.json()["signed_url"]
237+
return response.json()["signed_url"]

0 commit comments

Comments
 (0)