pipecat-boson 0.1.0__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.
Potentially problematic release.
This version of pipecat-boson might be problematic. Click here for more details.
- pipecat_boson-0.1.0/CHANGELOG.md +15 -0
- pipecat_boson-0.1.0/LICENSE +24 -0
- pipecat_boson-0.1.0/MANIFEST.in +2 -0
- pipecat_boson-0.1.0/PKG-INFO +274 -0
- pipecat_boson-0.1.0/README.md +246 -0
- pipecat_boson-0.1.0/examples/pipecat_boson_realtime_agent.py +334 -0
- pipecat_boson-0.1.0/pipecat_boson/__init__.py +8 -0
- pipecat_boson-0.1.0/pipecat_boson/realtime/__init__.py +22 -0
- pipecat_boson-0.1.0/pipecat_boson/realtime/config.py +190 -0
- pipecat_boson-0.1.0/pipecat_boson/realtime/llm.py +1047 -0
- pipecat_boson-0.1.0/pipecat_boson.egg-info/PKG-INFO +274 -0
- pipecat_boson-0.1.0/pipecat_boson.egg-info/SOURCES.txt +18 -0
- pipecat_boson-0.1.0/pipecat_boson.egg-info/dependency_links.txt +1 -0
- pipecat_boson-0.1.0/pipecat_boson.egg-info/requires.txt +18 -0
- pipecat_boson-0.1.0/pipecat_boson.egg-info/top_level.txt +1 -0
- pipecat_boson-0.1.0/pyproject.toml +77 -0
- pipecat_boson-0.1.0/setup.cfg +4 -0
- pipecat_boson-0.1.0/tests/test_packaging.py +23 -0
- pipecat_boson-0.1.0/tests/test_realtime_config.py +143 -0
- pipecat_boson-0.1.0/tests/test_realtime_llm.py +1113 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-07-08
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Added `BosonRealtimeLLMService` for using the Boson Realtime API from Pipecat pipelines.
|
|
13
|
+
- Added support for audio and text output modalities, server VAD, user transcripts, function calling, and text-only responses.
|
|
14
|
+
- Added a WebRTC RTVI example with user transcripts and function calling.
|
|
15
|
+
- Added unit tests for session configuration, realtime event handling, function-call follow-up responses, terminal session events, and package metadata.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Boson AI
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
21
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
22
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
23
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
24
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pipecat-boson
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pipecat realtime LLM service for the Boson Realtime API
|
|
5
|
+
License-Expression: BSD-2-Clause
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: loguru<1,>=0.7.3
|
|
13
|
+
Requires-Dist: pipecat-ai<2,>=1.4.0
|
|
14
|
+
Requires-Dist: websockets>=13.1
|
|
15
|
+
Provides-Extra: webrtc
|
|
16
|
+
Requires-Dist: pipecat-ai[runner,webrtc]<2,>=1.4.0; extra == "webrtc"
|
|
17
|
+
Requires-Dist: python-dotenv<2,>=1.0.0; extra == "webrtc"
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest==8.4.2; extra == "test"
|
|
20
|
+
Requires-Dist: pytest-asyncio==1.2.0; extra == "test"
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pipecat-ai[runner,webrtc]<2,>=1.4.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest==8.4.2; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-asyncio==1.2.0; extra == "dev"
|
|
25
|
+
Requires-Dist: python-dotenv<2,>=1.0.0; extra == "dev"
|
|
26
|
+
Requires-Dist: ruff==0.3.4; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# Boson Pipecat Realtime Service
|
|
30
|
+
|
|
31
|
+
This package lets Pipecat pipelines use the Boson Realtime API as a
|
|
32
|
+
speech-to-speech `LLMService`.
|
|
33
|
+
|
|
34
|
+
This integration is maintained by Boson AI for the Boson Realtime API.
|
|
35
|
+
|
|
36
|
+
It follows Boson's OpenAI-compatible realtime interface:
|
|
37
|
+
|
|
38
|
+
- `output_modalities` is exactly `["audio"]` or `["text"]`.
|
|
39
|
+
- Audio defaults to 24 kHz PCM input/output.
|
|
40
|
+
- Server VAD is enabled by default.
|
|
41
|
+
- User transcript events are emitted only when `input_audio_transcription.model`
|
|
42
|
+
is non-empty.
|
|
43
|
+
- Input noise reduction uses OpenAI's object shape:
|
|
44
|
+
`{"type": "near_field"}` or `{"type": "far_field"}`.
|
|
45
|
+
- `voice` is a string preset or voice id.
|
|
46
|
+
- `truncation` is `"auto"` or `"disabled"`.
|
|
47
|
+
- Per-response output modality overrides are not supported. Configure
|
|
48
|
+
text-only output at the session level with `modalities=["text"]`; Pipecat
|
|
49
|
+
`LLMConfigureOutputFrame(skip_tts=True)` is ignored by this service.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
Install the package from PyPI:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
uv add pipecat-boson
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The core service does not require WebRTC. Install the WebRTC extra only when
|
|
60
|
+
you want to run the browser example or use Pipecat's WebRTC transport:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
uv add "pipecat-boson[webrtc]"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For local development from this repository, use:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
uv sync --extra dev
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or run the example directly with `uv run --extra webrtc`, as shown below.
|
|
73
|
+
|
|
74
|
+
## Prerequisites
|
|
75
|
+
|
|
76
|
+
- A Boson API key.
|
|
77
|
+
- A Boson Realtime API WebSocket endpoint.
|
|
78
|
+
- Python 3.11 or newer.
|
|
79
|
+
|
|
80
|
+
## Local development
|
|
81
|
+
|
|
82
|
+
This package is intentionally isolated from Boson's backend Python environment.
|
|
83
|
+
It talks to Boson only through the realtime WebSocket API.
|
|
84
|
+
|
|
85
|
+
Run commands from the repository root:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
cp .env.example .env
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Run the Browser Example
|
|
92
|
+
|
|
93
|
+
The example enables user transcripts, typed chat display handling, and a local
|
|
94
|
+
`get_weather` function tool. It supports Pipecat's WebRTC and WebSocket
|
|
95
|
+
transports. WebRTC needs the `webrtc` extra, which installs `cv2` through
|
|
96
|
+
`opencv-python`.
|
|
97
|
+
|
|
98
|
+
Set the connection values in `.env`:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
BOSON_REALTIME_URL="ws://localhost:12344/v1/realtime/"
|
|
102
|
+
BOSON_API_KEY="..."
|
|
103
|
+
BOSON_PIPECAT_LOG_LEVEL=INFO
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Then run the example from the repository root:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
uv run --extra webrtc --python 3.12 \
|
|
110
|
+
python examples/pipecat_boson_realtime_agent.py \
|
|
111
|
+
-t webrtc \
|
|
112
|
+
--host 127.0.0.1 \
|
|
113
|
+
--port 7860
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
For SSH tunneling or other environments where WebRTC ICE cannot reach the
|
|
117
|
+
server, run the same example with the WebSocket transport:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
uv run --extra webrtc --python 3.12 \
|
|
121
|
+
python examples/pipecat_boson_realtime_agent.py \
|
|
122
|
+
-t websocket \
|
|
123
|
+
--host localhost \
|
|
124
|
+
--port 7860
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Open `http://localhost:7860` in the browser. Select the matching transport in
|
|
128
|
+
the page header before connecting. Use `localhost` for local plain WebSocket
|
|
129
|
+
runs; Pipecat's development runner advertises `wss://` for other host values.
|
|
130
|
+
The example enables user transcripts by default with
|
|
131
|
+
`BOSON_ASR_MODEL=higgs-audio-understanding-v3-asr`. Set `BOSON_ASR_MODEL` to a
|
|
132
|
+
different ASR model if your backend uses another name, or set it to `none` to
|
|
133
|
+
suppress client-facing user transcript events.
|
|
134
|
+
|
|
135
|
+
The example also registers a local `get_weather` function tool. Ask something
|
|
136
|
+
like "what is the weather in Shanghai?" to exercise realtime function calling;
|
|
137
|
+
the example logs the tool call and returns a mock weather result.
|
|
138
|
+
|
|
139
|
+
## Runtime Compatibility
|
|
140
|
+
|
|
141
|
+
This package targets `pipecat-ai>=1.4.0,<2` and has been tested with Pipecat
|
|
142
|
+
`1.5.0`. The only runtime contract is the realtime WebSocket protocol exposed
|
|
143
|
+
at `BOSON_REALTIME_URL`.
|
|
144
|
+
|
|
145
|
+
## Usage
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from pipecat_boson.realtime import BosonRealtimeLLMService
|
|
149
|
+
|
|
150
|
+
llm = BosonRealtimeLLMService(
|
|
151
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
152
|
+
api_key="...",
|
|
153
|
+
model="Qwen2.5-72B-Instruct",
|
|
154
|
+
voice="en_woman",
|
|
155
|
+
instructions="You are a concise voice assistant.",
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Pipeline usage sketch:
|
|
160
|
+
|
|
161
|
+
The snippet below assumes `transport` is a configured Pipecat transport. For a
|
|
162
|
+
complete runnable version, see `examples/pipecat_boson_realtime_agent.py`.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from pipecat.frames.frames import LLMRunFrame
|
|
166
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
167
|
+
from pipecat.pipeline.worker import PipelineParams, PipelineWorker
|
|
168
|
+
from pipecat.processors.aggregators.llm_context import LLMContext
|
|
169
|
+
from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair
|
|
170
|
+
|
|
171
|
+
from pipecat_boson.realtime import BosonRealtimeLLMService
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
llm = BosonRealtimeLLMService(
|
|
175
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
176
|
+
api_key="...",
|
|
177
|
+
model="Qwen2.5-72B-Instruct",
|
|
178
|
+
voice="default",
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
context = LLMContext()
|
|
182
|
+
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
|
|
183
|
+
context,
|
|
184
|
+
realtime_service_mode=True,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
pipeline = Pipeline(
|
|
188
|
+
[
|
|
189
|
+
transport.input(),
|
|
190
|
+
user_aggregator,
|
|
191
|
+
llm,
|
|
192
|
+
transport.output(),
|
|
193
|
+
assistant_aggregator,
|
|
194
|
+
]
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
worker = PipelineWorker(
|
|
198
|
+
pipeline,
|
|
199
|
+
params=PipelineParams(enable_metrics=True, enable_usage_metrics=True),
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
await worker.queue_frames([LLMRunFrame()])
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
With supported Pipecat versions, create context aggregators with realtime
|
|
206
|
+
service mode:
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
|
|
210
|
+
context,
|
|
211
|
+
realtime_service_mode=True,
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
For realtime services, this writes user messages to context when the assistant
|
|
216
|
+
response starts, which matches Pipecat's expected context semantics for
|
|
217
|
+
server-driven turn detection.
|
|
218
|
+
|
|
219
|
+
To receive user transcripts:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
llm = BosonRealtimeLLMService(
|
|
223
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
224
|
+
api_key="...",
|
|
225
|
+
model="Qwen2.5-72B-Instruct",
|
|
226
|
+
input_audio_transcription={"model": "whisper-1", "language": "zh"},
|
|
227
|
+
)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Omitting transcription, passing `None`, or passing a dict without `model` still
|
|
231
|
+
allows Boson to run ASR internally, but no client-facing transcript events
|
|
232
|
+
are emitted.
|
|
233
|
+
|
|
234
|
+
Advanced: use Pipecat/local VAD instead of server VAD:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
llm = BosonRealtimeLLMService(
|
|
238
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
239
|
+
api_key="...",
|
|
240
|
+
model="Qwen2.5-72B-Instruct",
|
|
241
|
+
turn_detection=False,
|
|
242
|
+
)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
When server VAD is disabled, the surrounding Pipecat pipeline must include
|
|
246
|
+
local turn-detection processors that emit user turn boundary frames. The
|
|
247
|
+
included WebRTC examples use Boson's server VAD by default; changing only this
|
|
248
|
+
service option to `False` is not enough for voice turns to commit.
|
|
249
|
+
|
|
250
|
+
For text-only output:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
llm = BosonRealtimeLLMService(
|
|
254
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
255
|
+
api_key="...",
|
|
256
|
+
model="Qwen2.5-72B-Instruct",
|
|
257
|
+
modalities=["text"],
|
|
258
|
+
)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Text-only sessions stream `response.output_text.delta` and do not emit audio
|
|
262
|
+
frames.
|
|
263
|
+
|
|
264
|
+
Boson session lifecycle extensions are exposed as service events:
|
|
265
|
+
`on_session_created` receives the full `session.created` event, including the
|
|
266
|
+
provider session ID in `event.session.id`;
|
|
267
|
+
`on_session_terminated` receives `session.idle_timeout` and
|
|
268
|
+
`session.max_duration_reached`; `on_should_end_call` receives the
|
|
269
|
+
`should_end_call` signal. The service does not automatically close Pipecat
|
|
270
|
+
transports for these events.
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
BSD-2-Clause.
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Boson Pipecat Realtime Service
|
|
2
|
+
|
|
3
|
+
This package lets Pipecat pipelines use the Boson Realtime API as a
|
|
4
|
+
speech-to-speech `LLMService`.
|
|
5
|
+
|
|
6
|
+
This integration is maintained by Boson AI for the Boson Realtime API.
|
|
7
|
+
|
|
8
|
+
It follows Boson's OpenAI-compatible realtime interface:
|
|
9
|
+
|
|
10
|
+
- `output_modalities` is exactly `["audio"]` or `["text"]`.
|
|
11
|
+
- Audio defaults to 24 kHz PCM input/output.
|
|
12
|
+
- Server VAD is enabled by default.
|
|
13
|
+
- User transcript events are emitted only when `input_audio_transcription.model`
|
|
14
|
+
is non-empty.
|
|
15
|
+
- Input noise reduction uses OpenAI's object shape:
|
|
16
|
+
`{"type": "near_field"}` or `{"type": "far_field"}`.
|
|
17
|
+
- `voice` is a string preset or voice id.
|
|
18
|
+
- `truncation` is `"auto"` or `"disabled"`.
|
|
19
|
+
- Per-response output modality overrides are not supported. Configure
|
|
20
|
+
text-only output at the session level with `modalities=["text"]`; Pipecat
|
|
21
|
+
`LLMConfigureOutputFrame(skip_tts=True)` is ignored by this service.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
Install the package from PyPI:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
uv add pipecat-boson
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The core service does not require WebRTC. Install the WebRTC extra only when
|
|
32
|
+
you want to run the browser example or use Pipecat's WebRTC transport:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
uv add "pipecat-boson[webrtc]"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For local development from this repository, use:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv sync --extra dev
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or run the example directly with `uv run --extra webrtc`, as shown below.
|
|
45
|
+
|
|
46
|
+
## Prerequisites
|
|
47
|
+
|
|
48
|
+
- A Boson API key.
|
|
49
|
+
- A Boson Realtime API WebSocket endpoint.
|
|
50
|
+
- Python 3.11 or newer.
|
|
51
|
+
|
|
52
|
+
## Local development
|
|
53
|
+
|
|
54
|
+
This package is intentionally isolated from Boson's backend Python environment.
|
|
55
|
+
It talks to Boson only through the realtime WebSocket API.
|
|
56
|
+
|
|
57
|
+
Run commands from the repository root:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
cp .env.example .env
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Run the Browser Example
|
|
64
|
+
|
|
65
|
+
The example enables user transcripts, typed chat display handling, and a local
|
|
66
|
+
`get_weather` function tool. It supports Pipecat's WebRTC and WebSocket
|
|
67
|
+
transports. WebRTC needs the `webrtc` extra, which installs `cv2` through
|
|
68
|
+
`opencv-python`.
|
|
69
|
+
|
|
70
|
+
Set the connection values in `.env`:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
BOSON_REALTIME_URL="ws://localhost:12344/v1/realtime/"
|
|
74
|
+
BOSON_API_KEY="..."
|
|
75
|
+
BOSON_PIPECAT_LOG_LEVEL=INFO
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Then run the example from the repository root:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
uv run --extra webrtc --python 3.12 \
|
|
82
|
+
python examples/pipecat_boson_realtime_agent.py \
|
|
83
|
+
-t webrtc \
|
|
84
|
+
--host 127.0.0.1 \
|
|
85
|
+
--port 7860
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For SSH tunneling or other environments where WebRTC ICE cannot reach the
|
|
89
|
+
server, run the same example with the WebSocket transport:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
uv run --extra webrtc --python 3.12 \
|
|
93
|
+
python examples/pipecat_boson_realtime_agent.py \
|
|
94
|
+
-t websocket \
|
|
95
|
+
--host localhost \
|
|
96
|
+
--port 7860
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Open `http://localhost:7860` in the browser. Select the matching transport in
|
|
100
|
+
the page header before connecting. Use `localhost` for local plain WebSocket
|
|
101
|
+
runs; Pipecat's development runner advertises `wss://` for other host values.
|
|
102
|
+
The example enables user transcripts by default with
|
|
103
|
+
`BOSON_ASR_MODEL=higgs-audio-understanding-v3-asr`. Set `BOSON_ASR_MODEL` to a
|
|
104
|
+
different ASR model if your backend uses another name, or set it to `none` to
|
|
105
|
+
suppress client-facing user transcript events.
|
|
106
|
+
|
|
107
|
+
The example also registers a local `get_weather` function tool. Ask something
|
|
108
|
+
like "what is the weather in Shanghai?" to exercise realtime function calling;
|
|
109
|
+
the example logs the tool call and returns a mock weather result.
|
|
110
|
+
|
|
111
|
+
## Runtime Compatibility
|
|
112
|
+
|
|
113
|
+
This package targets `pipecat-ai>=1.4.0,<2` and has been tested with Pipecat
|
|
114
|
+
`1.5.0`. The only runtime contract is the realtime WebSocket protocol exposed
|
|
115
|
+
at `BOSON_REALTIME_URL`.
|
|
116
|
+
|
|
117
|
+
## Usage
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from pipecat_boson.realtime import BosonRealtimeLLMService
|
|
121
|
+
|
|
122
|
+
llm = BosonRealtimeLLMService(
|
|
123
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
124
|
+
api_key="...",
|
|
125
|
+
model="Qwen2.5-72B-Instruct",
|
|
126
|
+
voice="en_woman",
|
|
127
|
+
instructions="You are a concise voice assistant.",
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Pipeline usage sketch:
|
|
132
|
+
|
|
133
|
+
The snippet below assumes `transport` is a configured Pipecat transport. For a
|
|
134
|
+
complete runnable version, see `examples/pipecat_boson_realtime_agent.py`.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from pipecat.frames.frames import LLMRunFrame
|
|
138
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
139
|
+
from pipecat.pipeline.worker import PipelineParams, PipelineWorker
|
|
140
|
+
from pipecat.processors.aggregators.llm_context import LLMContext
|
|
141
|
+
from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair
|
|
142
|
+
|
|
143
|
+
from pipecat_boson.realtime import BosonRealtimeLLMService
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
llm = BosonRealtimeLLMService(
|
|
147
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
148
|
+
api_key="...",
|
|
149
|
+
model="Qwen2.5-72B-Instruct",
|
|
150
|
+
voice="default",
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
context = LLMContext()
|
|
154
|
+
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
|
|
155
|
+
context,
|
|
156
|
+
realtime_service_mode=True,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
pipeline = Pipeline(
|
|
160
|
+
[
|
|
161
|
+
transport.input(),
|
|
162
|
+
user_aggregator,
|
|
163
|
+
llm,
|
|
164
|
+
transport.output(),
|
|
165
|
+
assistant_aggregator,
|
|
166
|
+
]
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
worker = PipelineWorker(
|
|
170
|
+
pipeline,
|
|
171
|
+
params=PipelineParams(enable_metrics=True, enable_usage_metrics=True),
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
await worker.queue_frames([LLMRunFrame()])
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
With supported Pipecat versions, create context aggregators with realtime
|
|
178
|
+
service mode:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
|
|
182
|
+
context,
|
|
183
|
+
realtime_service_mode=True,
|
|
184
|
+
)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
For realtime services, this writes user messages to context when the assistant
|
|
188
|
+
response starts, which matches Pipecat's expected context semantics for
|
|
189
|
+
server-driven turn detection.
|
|
190
|
+
|
|
191
|
+
To receive user transcripts:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
llm = BosonRealtimeLLMService(
|
|
195
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
196
|
+
api_key="...",
|
|
197
|
+
model="Qwen2.5-72B-Instruct",
|
|
198
|
+
input_audio_transcription={"model": "whisper-1", "language": "zh"},
|
|
199
|
+
)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Omitting transcription, passing `None`, or passing a dict without `model` still
|
|
203
|
+
allows Boson to run ASR internally, but no client-facing transcript events
|
|
204
|
+
are emitted.
|
|
205
|
+
|
|
206
|
+
Advanced: use Pipecat/local VAD instead of server VAD:
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
llm = BosonRealtimeLLMService(
|
|
210
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
211
|
+
api_key="...",
|
|
212
|
+
model="Qwen2.5-72B-Instruct",
|
|
213
|
+
turn_detection=False,
|
|
214
|
+
)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
When server VAD is disabled, the surrounding Pipecat pipeline must include
|
|
218
|
+
local turn-detection processors that emit user turn boundary frames. The
|
|
219
|
+
included WebRTC examples use Boson's server VAD by default; changing only this
|
|
220
|
+
service option to `False` is not enough for voice turns to commit.
|
|
221
|
+
|
|
222
|
+
For text-only output:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
llm = BosonRealtimeLLMService(
|
|
226
|
+
url="ws://localhost:12344/v1/realtime/",
|
|
227
|
+
api_key="...",
|
|
228
|
+
model="Qwen2.5-72B-Instruct",
|
|
229
|
+
modalities=["text"],
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Text-only sessions stream `response.output_text.delta` and do not emit audio
|
|
234
|
+
frames.
|
|
235
|
+
|
|
236
|
+
Boson session lifecycle extensions are exposed as service events:
|
|
237
|
+
`on_session_created` receives the full `session.created` event, including the
|
|
238
|
+
provider session ID in `event.session.id`;
|
|
239
|
+
`on_session_terminated` receives `session.idle_timeout` and
|
|
240
|
+
`session.max_duration_reached`; `on_should_end_call` receives the
|
|
241
|
+
`should_end_call` signal. The service does not automatically close Pipecat
|
|
242
|
+
transports for these events.
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
BSD-2-Clause.
|