Skip to content

Commit d8287d1

Browse files
committed
feat(model/omni):support item.create api
1 parent 27ffefa commit d8287d1

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

dashscope/audio/http_tts/__init__.py

Whitespace-only changes.

dashscope/audio/qwen_omni/omni_realtime.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ def connect(self) -> None:
182182
self.ws = websocket.WebSocketApp(
183183
self.url,
184184
header=self._get_websocket_header(),
185-
on_message=self.on_message,
186-
on_error=self.on_error,
187-
on_close=self.on_close,
185+
on_message=self._on_message,
186+
on_error=self._on_error,
187+
on_close=self._on_close,
188188
)
189189
self.thread = threading.Thread(target=self.ws.run_forever)
190190
self.thread.daemon = True
@@ -199,7 +199,8 @@ def connect(self) -> None:
199199
if not (self.ws.sock and self.ws.sock.connected):
200200
raise TimeoutError(
201201
"websocket connection could not established within 5s. "
202-
"Please check your network connection, firewall settings, or server status.", # noqa: E501 # pylint: disable=line-too-long
202+
"Please check your network connection, firewall settings,"
203+
"or server status.",
203204
)
204205
self.callback.on_open()
205206

@@ -208,6 +209,21 @@ def __send_str(self, data: str, enable_log: bool = True):
208209
logger.debug("[omni realtime] send string: %s", data)
209210
self.ws.send(data)
210211

212+
def create_item(self, item: dict):
213+
"""
214+
send item.create request
215+
"""
216+
self.__send_str(
217+
json.dumps(
218+
{
219+
"event_id": self._generate_event_id(),
220+
"type": "conversation.item.create",
221+
"item": item,
222+
},
223+
),
224+
enable_log=True,
225+
)
226+
211227
def update_session(
212228
self,
213229
output_modalities: List[MultiModality],
@@ -496,7 +512,7 @@ def close(self) -> None:
496512
self.ws.close()
497513

498514
# 监听消息的回调函数
499-
def on_message( # pylint: disable=unused-argument,too-many-branches
515+
def _on_message( # pylint: disable=unused-argument,too-many-branches
500516
self,
501517
ws,
502518
message,
@@ -567,7 +583,7 @@ def on_message( # pylint: disable=unused-argument,too-many-branches
567583
len(message),
568584
)
569585

570-
def on_close( # pylint: disable=unused-argument
586+
def _on_close( # pylint: disable=unused-argument
571587
self,
572588
ws,
573589
close_status_code,
@@ -576,7 +592,7 @@ def on_close( # pylint: disable=unused-argument
576592
self.callback.on_close(close_status_code, close_msg)
577593

578594
# WebSocket发生错误的回调函数
579-
def on_error(self, ws, error): # pylint: disable=unused-argument
595+
def _on_error(self, ws, error): # pylint: disable=unused-argument
580596
print(f"websocket closed due to {error}")
581597
# pylint: disable=broad-exception-raised
582598
raise Exception(f"websocket closed due to {error}")

0 commit comments

Comments
 (0)