Skip to content

Commit c14fd00

Browse files
committed
fix lint and mypy errors
1 parent cf43f5a commit c14fd00

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

examples/realtime/twilio_sip/server.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from fastapi import FastAPI, HTTPException, Request, Response
1111
from openai import APIStatusError, AsyncOpenAI, InvalidWebhookSignatureError
1212

13+
from agents.realtime.config import RealtimeSessionModelSettings
1314
from agents.realtime.items import (
1415
AssistantAudio,
1516
AssistantMessageItem,
@@ -89,9 +90,7 @@ async def accept_call(call_id: str) -> None:
8990
except Exception: # noqa: BLE001
9091
detail = str(exc.response)
9192

92-
logger.error(
93-
"Failed to accept call %s: %s %s", call_id, exc.status_code, detail
94-
)
93+
logger.error("Failed to accept call %s: %s %s", call_id, exc.status_code, detail)
9594
raise HTTPException(status_code=500, detail="Failed to accept call") from exc
9695

9796
logger.info("Accepted call %s", call_id)
@@ -103,17 +102,16 @@ async def observe_call(call_id: str) -> None:
103102
runner = RealtimeRunner(assistant_agent, model=OpenAIRealtimeSIPModel())
104103

105104
try:
106-
initial_settings = {
105+
initial_model_settings: RealtimeSessionModelSettings = {
107106
"turn_detection": {
108107
"type": "semantic_vad",
109108
"interrupt_response": True,
110109
}
111110
}
112-
113111
async with await runner.run(
114112
model_config={
115113
"call_id": call_id,
116-
"initial_model_settings": initial_settings,
114+
"initial_model_settings": initial_model_settings,
117115
}
118116
) as session:
119117
# Trigger an initial greeting so callers hear the agent right away.
@@ -124,12 +122,14 @@ async def observe_call(call_id: str) -> None:
124122
RealtimeModelSendRawMessage(
125123
message={
126124
"type": "response.create",
127-
"response": {
128-
"instructions": (
129-
"Say exactly '"
130-
f"{WELCOME_MESSAGE}"
131-
"' now before continuing the conversation."
132-
)
125+
"other_data": {
126+
"response": {
127+
"instructions": (
128+
"Say exactly '"
129+
f"{WELCOME_MESSAGE}"
130+
"' now before continuing the conversation."
131+
)
132+
}
133133
},
134134
}
135135
)
@@ -139,15 +139,21 @@ async def observe_call(call_id: str) -> None:
139139
if event.type == "history_added":
140140
item = event.item
141141
if isinstance(item, UserMessageItem):
142-
for content in item.content:
143-
if isinstance(content, InputText) and content.text:
144-
logger.info("Caller: %s", content.text)
142+
for user_content in item.content:
143+
if isinstance(user_content, InputText) and user_content.text:
144+
logger.info("Caller: %s", user_content.text)
145145
elif isinstance(item, AssistantMessageItem):
146-
for content in item.content:
147-
if isinstance(content, AssistantText) and content.text:
148-
logger.info("Assistant (text): %s", content.text)
149-
elif isinstance(content, AssistantAudio) and content.transcript:
150-
logger.info("Assistant (audio transcript): %s", content.transcript)
146+
for assistant_content in item.content:
147+
if isinstance(assistant_content, AssistantText) and assistant_content.text:
148+
logger.info("Assistant (text): %s", assistant_content.text)
149+
elif (
150+
isinstance(assistant_content, AssistantAudio)
151+
and assistant_content.transcript
152+
):
153+
logger.info(
154+
"Assistant (audio transcript): %s",
155+
assistant_content.transcript,
156+
)
151157
elif event.type == "error":
152158
logger.error("Realtime session error: %s", event.error)
153159

src/agents/realtime/openai_realtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def _tools_to_session_tools(
936936
class OpenAIRealtimeSIPModel(OpenAIRealtimeWebSocketModel):
937937
"""Realtime model that attaches to SIP-originated calls using a call ID."""
938938

939-
async def connect(self, options: RealtimeModelConfig) -> None: # type: ignore[override]
939+
async def connect(self, options: RealtimeModelConfig) -> None:
940940
call_id = options.get("call_id")
941941
if not call_id:
942942
raise UserError("OpenAIRealtimeSIPModel requires `call_id` in the model configuration.")

tests/realtime/test_openai_realtime_sip_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def test_sip_model_uses_call_id_in_url(monkeypatch: pytest.MonkeyPatch) ->
3131
dummy_ws = _DummyWebSocket()
3232
captured: dict[str, object] = {}
3333

34-
async def fake_connect(url: str, **kwargs): # type: ignore[override]
34+
async def fake_connect(url: str, **kwargs):
3535
captured["url"] = url
3636
captured["kwargs"] = kwargs
3737
return dummy_ws

0 commit comments

Comments
 (0)