-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualBot.py
More file actions
79 lines (57 loc) · 2.07 KB
/
VirtualBot.py
File metadata and controls
79 lines (57 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
from dotenv import load_dotenv
load_dotenv()
AGENT_ID = os.getenv("ELEVENLABS_AGENT_ID")
API_KEY = os.getenv("ELEVENLABS_API_KEY")
from elevenlabs.client import ElevenLabs
from elevenlabs.conversational_ai.conversation import Conversation
from elevenlabs.conversational_ai.default_audio_interface import DefaultAudioInterface
from elevenlabs.types import ConversationConfig
# Patch in a default user_id property if missing
if not hasattr(ConversationConfig, "user_id"):
ConversationConfig.user_id = property(lambda self: "mahith-123")
user_name = "Mahith"
schedule = "Sales Meeting with Taipy at 10:00; Gym with Sophie at 17:00"
prompt = f"You are a helpful assistant. Your interlocutor has the following schedule: {schedule}."
first_message = f"Hello {user_name}, how can I help you today?"
conversation_override = {
"agent": {
"prompt": {
"prompt": prompt,
},
"first_message": first_message,
},
}
config = ConversationConfig(
conversation_config_override=conversation_override,
extra_body={"user_id": "mahith"},
dynamic_variables={},
)
client = ElevenLabs(api_key=API_KEY)
conversation = Conversation(
client,
AGENT_ID,
config=config,
requires_auth=True,
audio_interface=DefaultAudioInterface(),
)
def print_agent_response(response):
print(f"Agent: {response}")
def print_interrupted_response(original, corrected):
print(f"Agent interrupted, truncated response: {corrected}")
def print_user_transcript(transcript):
print(f"User: {transcript}")
conversation = Conversation(
client,
AGENT_ID,
config=config,
requires_auth=True,
audio_interface=DefaultAudioInterface(),
callback_agent_response=print_agent_response,
callback_agent_response_correction=print_interrupted_response,
callback_user_transcript=print_user_transcript,
)
conversation.start_session()
# Let it run for a while (or until user input)
input("Press Enter to stop the conversation...\n")
conversation.end_session()