swarmauri_live_model_qwen 0.1.0.dev3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Jacob Stewart
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_live_model_qwen
3
+ Version: 0.1.0.dev3
4
+ Summary: Qwen Omni Realtime multimodal model adapter for Swarmauri.
5
+ License: Copyright 2024 Jacob Stewart
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+ License-File: LICENSE
19
+ Keywords: swarmauri,qwen omni,realtime,multimodal,websocket
20
+ Author: Jacob Stewart
21
+ Author-email: jacob@swarmauri.com
22
+ Requires-Python: >=3.10,<3.13
23
+ Classifier: Development Status :: 1 - Planning
24
+ Classifier: License :: OSI Approved :: Apache Software License
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Requires-Dist: swarmauri_base (>=0.11.0.dev5)
29
+ Requires-Dist: swarmauri_core (>=0.11.0.dev5)
30
+ Requires-Dist: swarmauri_provider_qwen (>=0.1.0.dev3)
31
+ Requires-Dist: swarmauri_transport_websocket (>=0.1.0.dev4)
32
+ Description-Content-Type: text/markdown
33
+
34
+ ![Swarmauri](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
35
+
36
+ [![PyPI](https://img.shields.io/pypi/v/swarmauri_live_model_qwen.svg)](https://pypi.org/project/swarmauri_live_model_qwen/) [![Python](https://img.shields.io/pypi/pyversions/swarmauri_live_model_qwen.svg)](https://pypi.org/project/swarmauri_live_model_qwen/) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Downloads](https://static.pepy.tech/badge/swarmauri_live_model_qwen)](https://pepy.tech/project/swarmauri_live_model_qwen) [![Hits](https://hits.sh/github.com/swarmauri/swarmauri-sdk.svg)](https://hits.sh/github.com/swarmauri/swarmauri-sdk/)
37
+
38
+ # swarmauri_live_model_qwen
39
+
40
+ ## Features
41
+
42
+ - Qwen Omni realtime text, audio, image, transcript, and tool events.
43
+ - Provider-neutral Swarmauri live-session contract.
44
+
45
+ ## Installation
46
+
47
+ `uv add swarmauri_live_model_qwen` or `pip install swarmauri_live_model_qwen`.
48
+
49
+ ## Usage
50
+
51
+ Inject `QwenProvider` into `QwenOmniRealtimeModel` and consume typed events.
52
+
@@ -0,0 +1,18 @@
1
+ ![Swarmauri](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/swarmauri_live_model_qwen.svg)](https://pypi.org/project/swarmauri_live_model_qwen/) [![Python](https://img.shields.io/pypi/pyversions/swarmauri_live_model_qwen.svg)](https://pypi.org/project/swarmauri_live_model_qwen/) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Downloads](https://static.pepy.tech/badge/swarmauri_live_model_qwen)](https://pepy.tech/project/swarmauri_live_model_qwen) [![Hits](https://hits.sh/github.com/swarmauri/swarmauri-sdk.svg)](https://hits.sh/github.com/swarmauri/swarmauri-sdk/)
4
+
5
+ # swarmauri_live_model_qwen
6
+
7
+ ## Features
8
+
9
+ - Qwen Omni realtime text, audio, image, transcript, and tool events.
10
+ - Provider-neutral Swarmauri live-session contract.
11
+
12
+ ## Installation
13
+
14
+ `uv add swarmauri_live_model_qwen` or `pip install swarmauri_live_model_qwen`.
15
+
16
+ ## Usage
17
+
18
+ Inject `QwenProvider` into `QwenOmniRealtimeModel` and consume typed events.
@@ -0,0 +1,29 @@
1
+ [project]
2
+ name = "swarmauri_live_model_qwen"
3
+ version = "0.1.0.dev3"
4
+ description = "Qwen Omni Realtime multimodal model adapter for Swarmauri."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10,<3.13"
7
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
8
+ license = { file = "LICENSE" }
9
+ dependencies = ["swarmauri_core>=0.11.0.dev5", "swarmauri_base>=0.11.0.dev5", "swarmauri_provider_qwen>=0.1.0.dev3", "swarmauri_transport_websocket>=0.1.0.dev4"]
10
+ classifiers = ["Development Status :: 1 - Planning", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12"]
11
+ keywords = ["swarmauri", "qwen omni", "realtime", "multimodal", "websocket"]
12
+ [tool.uv.sources]
13
+ swarmauri_core = { workspace = true }
14
+ swarmauri_base = { workspace = true }
15
+ swarmauri_provider_qwen = { workspace = true }
16
+ swarmauri_transport_websocket = { workspace = true }
17
+ [project.entry-points."swarmauri.live_models"]
18
+ QwenOmniRealtimeModel = "swarmauri_live_model_qwen:QwenOmniRealtimeModel"
19
+ [build-system]
20
+ requires = ["poetry-core>=1.8.0"]
21
+ build-backend = "poetry.core.masonry.api"
22
+ [dependency-groups]
23
+ dev = ["pytest>=8.0", "pytest-asyncio>=0.24", "ruff>=0.9.9", "swarmauri_tests_component"]
24
+
25
+ [tool.ruff]
26
+ extend = "../../pyproject.toml"
27
+
28
+ [tool.ruff.lint]
29
+ ignore = ["BLE001", "N999"]
@@ -0,0 +1,99 @@
1
+ import base64
2
+ import json
3
+
4
+ from swarmauri_base.live_models.events.AudioDeltaEvent import AudioDeltaEvent
5
+ from swarmauri_base.live_models.events.OutputTranscriptDeltaEvent import (
6
+ OutputTranscriptDeltaEvent,
7
+ )
8
+ from swarmauri_base.live_models.events.SessionErrorEvent import (
9
+ SessionErrorEvent,
10
+ )
11
+ from swarmauri_base.live_models.events.TextDeltaEvent import TextDeltaEvent
12
+ from swarmauri_base.live_models.events.ToolCallEvent import ToolCallEvent
13
+ from swarmauri_base.live_models.events.TurnCompleteEvent import (
14
+ TurnCompleteEvent,
15
+ )
16
+
17
+
18
+ class QwenOmniRealtimeCodec:
19
+ def encode(self, input_data):
20
+ if input_data.kind == "text":
21
+ return json.dumps(
22
+ {
23
+ "type": "conversation.item.create",
24
+ "item": {
25
+ "role": "user",
26
+ "content": [
27
+ {"type": "input_text", "text": input_data.payload}
28
+ ],
29
+ },
30
+ }
31
+ )
32
+ if input_data.kind == "audio":
33
+ return json.dumps(
34
+ {
35
+ "type": "input_audio_buffer.append",
36
+ "audio": base64.b64encode(input_data.payload).decode(),
37
+ }
38
+ )
39
+ if input_data.kind == "tool_result":
40
+ return json.dumps(
41
+ {
42
+ "type": "conversation.item.create",
43
+ "item": {
44
+ "type": "function_call_output",
45
+ "call_id": input_data.call_id,
46
+ "output": json.dumps(input_data.payload),
47
+ },
48
+ }
49
+ )
50
+ return json.dumps({"type": "response.create"})
51
+
52
+ def decode(self, message):
53
+ data = json.loads(message)
54
+ kind = data.get("type", "")
55
+ correlation = {
56
+ "provider_event_id": data.get("event_id"),
57
+ "call_id": data.get("call_id"),
58
+ }
59
+ if kind.endswith("text.delta"):
60
+ return [
61
+ TextDeltaEvent(
62
+ payload=data.get("delta", ""), correlation=correlation
63
+ )
64
+ ]
65
+ if kind.endswith("audio.delta"):
66
+ return [
67
+ AudioDeltaEvent(
68
+ payload=base64.b64decode(data.get("delta", "")),
69
+ correlation=correlation,
70
+ )
71
+ ]
72
+ if "transcript.delta" in kind:
73
+ return [
74
+ OutputTranscriptDeltaEvent(
75
+ payload=data.get("delta", ""), correlation=correlation
76
+ )
77
+ ]
78
+ if kind.endswith("function_call_arguments.done"):
79
+ args = data.get("arguments", {})
80
+ return [
81
+ ToolCallEvent(
82
+ call_id=data.get("call_id", ""),
83
+ tool_name=data.get("name", ""),
84
+ arguments=json.loads(args)
85
+ if isinstance(args, str)
86
+ else args,
87
+ correlation=correlation,
88
+ )
89
+ ]
90
+ if kind == "response.done":
91
+ return [TurnCompleteEvent(correlation=correlation)]
92
+ if kind == "error":
93
+ return [
94
+ SessionErrorEvent(
95
+ message=str(data.get("error", data)),
96
+ correlation=correlation,
97
+ )
98
+ ]
99
+ return []
@@ -0,0 +1,13 @@
1
+ from swarmauri_base.live_models.LiveConfigBase import LiveConfigBase
2
+
3
+
4
+ class QwenOmniRealtimeConfigMapper:
5
+ def map(self, config: LiveConfigBase) -> dict:
6
+ return {
7
+ "event_id": "swarmauri-setup",
8
+ "type": "session.update",
9
+ "session": {
10
+ "modalities": config.requested_modalities,
11
+ **config.provider_options.get("session", {}),
12
+ },
13
+ }
@@ -0,0 +1,43 @@
1
+ from typing import Any, Literal
2
+
3
+ from pydantic import ConfigDict, Field
4
+ from swarmauri_base.ComponentBase import ComponentBase
5
+ from swarmauri_base.live_models.LiveCapabilitiesBase import (
6
+ LiveCapabilitiesBase,
7
+ )
8
+ from swarmauri_base.live_models.LiveConfigBase import LiveConfigBase
9
+ from swarmauri_base.live_models.LiveModelBase import LiveModelBase
10
+ from swarmauri_provider_qwen import QwenProvider
11
+ from swarmauri_transport_websocket import WebSocketClient
12
+
13
+ from .QwenOmniRealtimeConfigMapper import QwenOmniRealtimeConfigMapper
14
+ from .QwenOmniRealtimeSession import QwenOmniRealtimeSession
15
+
16
+
17
+ @ComponentBase.register_type(LiveModelBase, "QwenOmniRealtimeModel")
18
+ class QwenOmniRealtimeModel(LiveModelBase):
19
+ name: str = "qwen-omni-turbo-realtime"
20
+ provider: QwenProvider = Field(default_factory=QwenProvider)
21
+ transport: Any = Field(default_factory=WebSocketClient, exclude=True)
22
+ capabilities: LiveCapabilitiesBase = Field(
23
+ default_factory=lambda: LiveCapabilitiesBase(
24
+ input_modalities=frozenset({"text", "audio", "image"}),
25
+ output_modalities=frozenset({"text", "audio"}),
26
+ features=frozenset({"tools", "transcription"}),
27
+ session_features=frozenset({"realtime"}),
28
+ )
29
+ )
30
+ type: Literal["QwenOmniRealtimeModel"] = "QwenOmniRealtimeModel"
31
+ model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
32
+
33
+ async def aconnect(self, config: LiveConfigBase):
34
+ connection_config = self.provider.prepare_connection(
35
+ "realtime.connect", model=self.name
36
+ )
37
+ connection = await self.transport.aconnect(
38
+ connection_config.resolved_url(),
39
+ headers=connection_config.headers,
40
+ )
41
+ return await QwenOmniRealtimeSession.create(
42
+ connection, QwenOmniRealtimeConfigMapper().map(config)
43
+ )
@@ -0,0 +1,53 @@
1
+ import asyncio
2
+ import json
3
+ from contextlib import suppress
4
+ from typing import Literal
5
+
6
+ from pydantic import PrivateAttr
7
+ from swarmauri_base.live_models.events.SessionErrorEvent import (
8
+ SessionErrorEvent,
9
+ )
10
+ from swarmauri_base.live_models.LiveSessionBase import LiveSessionBase
11
+ from swarmauri_base.ComponentBase import ComponentBase
12
+
13
+ from .QwenOmniRealtimeCodec import QwenOmniRealtimeCodec
14
+
15
+
16
+ @ComponentBase.register_type(LiveSessionBase, "QwenOmniRealtimeSession")
17
+ class QwenOmniRealtimeSession(LiveSessionBase):
18
+ type: Literal["QwenOmniRealtimeSession"] = "QwenOmniRealtimeSession"
19
+ _connection = PrivateAttr()
20
+ _codec = PrivateAttr(default_factory=QwenOmniRealtimeCodec)
21
+ _receiver = PrivateAttr(default=None)
22
+
23
+ @classmethod
24
+ async def create(cls, connection, setup):
25
+ session = cls()
26
+ session._connection = connection
27
+ await connection.asend(json.dumps(setup))
28
+ session.mark_open()
29
+ session._receiver = asyncio.create_task(session._receive_loop())
30
+ return session
31
+
32
+ async def _receive_loop(self) -> None:
33
+ try:
34
+ async for message in self._connection.aiter_messages():
35
+ for event in self._codec.decode(message):
36
+ await self.emit(event)
37
+ except asyncio.CancelledError:
38
+ raise
39
+ except Exception as exc:
40
+ await self.emit(SessionErrorEvent(message=str(exc)))
41
+ await self.fail(exc)
42
+ else:
43
+ await self.finish()
44
+
45
+ async def _asend_impl(self, input_data):
46
+ await self._connection.asend(self._codec.encode(input_data))
47
+
48
+ async def _aclose_impl(self):
49
+ if self._receiver and self._receiver is not asyncio.current_task():
50
+ self._receiver.cancel()
51
+ with suppress(asyncio.CancelledError):
52
+ await self._receiver
53
+ await self._connection.aclose()
@@ -0,0 +1,6 @@
1
+ from swarmauri_base.live_models.inputs.ToolResultInput import ToolResultInput
2
+
3
+
4
+ class QwenOmniRealtimeToolAdapter:
5
+ def result(self, call_id, value):
6
+ return ToolResultInput(call_id=call_id, payload=value)
@@ -0,0 +1,13 @@
1
+ from .QwenOmniRealtimeCodec import QwenOmniRealtimeCodec
2
+ from .QwenOmniRealtimeConfigMapper import QwenOmniRealtimeConfigMapper
3
+ from .QwenOmniRealtimeModel import QwenOmniRealtimeModel
4
+ from .QwenOmniRealtimeSession import QwenOmniRealtimeSession
5
+ from .QwenOmniRealtimeToolAdapter import QwenOmniRealtimeToolAdapter
6
+
7
+ __all__ = [
8
+ "QwenOmniRealtimeCodec",
9
+ "QwenOmniRealtimeConfigMapper",
10
+ "QwenOmniRealtimeModel",
11
+ "QwenOmniRealtimeSession",
12
+ "QwenOmniRealtimeToolAdapter",
13
+ ]