Skip to content

Commit 83ee0c6

Browse files
testing model speak first in one fxn
1 parent 6b0e873 commit 83ee0c6

File tree

1 file changed

+17
-55
lines changed

1 file changed

+17
-55
lines changed

main.py

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,24 @@ async def connect(self) -> None:
8181
self.ws = await websockets.connect(url, extra_headers=headers)
8282
await self.initialize_session()
8383

84+
async def initialize_session(self):
85+
"""Control initial session with OpenAI."""
86+
session_update = {
87+
"type": "session.update",
88+
"session": {
89+
"turn_detection": {"type": "server_vad"},
90+
"input_audio_format": "g711_ulaw",
91+
"output_audio_format": "g711_ulaw",
92+
"voice": VOICE,
93+
"instructions": SYSTEM_MESSAGE,
94+
"modalities": ["text", "audio"],
95+
"temperature": 0.8,
96+
}
97+
}
98+
print('Sending session update:', json.dumps(session_update))
99+
await self.ws.send(json.dumps(session_update))
84100

85-
async def send_initial_conversation_item(self):
86-
"""Send initial conversation item if AI talks first."""
101+
# Send initial conversation item if AI talks first
87102
initial_conversation_item = {
88103
"type": "conversation.item.create",
89104
"item": {
@@ -99,59 +114,6 @@ async def send_initial_conversation_item(self):
99114
}
100115
await self.ws.send(json.dumps(initial_conversation_item))
101116

102-
async def initialize_session(self) -> None:
103-
"""Control initial session with OpenAI and register tools."""
104-
tools = [
105-
{
106-
"type": "function",
107-
"name": "handoff_to_agent",
108-
"description": "Request human intervention.",
109-
"parameters": {
110-
"type": "object",
111-
"properties": {
112-
"reason_for_handoff": {
113-
"type": "string",
114-
"description": "Reason for requesting an agent."
115-
}
116-
},
117-
"required": ["reason_for_handoff"]
118-
}
119-
},
120-
{
121-
"type": "function",
122-
"name": "get_weather",
123-
"description": "Retrieves weather info for a given lat/lng.",
124-
"parameters": {
125-
"type": "object",
126-
"properties": {
127-
"lat": {"type": "number", "description": "Latitude."},
128-
"lng": {"type": "number", "description": "Longitude."},
129-
"location": {"type": "string", "description": "Location name."}
130-
},
131-
"required": ["lat", "lng", "location"]
132-
}
133-
}
134-
]
135-
136-
session_update = {
137-
"type": "session.update",
138-
"session": {
139-
"turn_detection": {"type": self.turn_detection_mode.value},
140-
"input_audio_format": "g711_ulaw",
141-
"output_audio_format": "g711_ulaw",
142-
"voice": self.voice,
143-
"instructions": self.instructions,
144-
"modalities": ["text", "audio"],
145-
"temperature": self.temperature,
146-
"tools": tools,
147-
"tool_choice": "auto",
148-
}
149-
}
150-
print('Sending session update:', json.dumps(session_update))
151-
await self.ws.send(json.dumps(session_update))
152-
153-
await self.send_initial_conversation_item(self.ws)
154-
155117
async def send_text(self, text: str) -> None:
156118
"""Send text message to the API."""
157119
event = {

0 commit comments

Comments
 (0)