vana-pipecat 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.
- vana_pipecat-0.1.0/LICENSE +202 -0
- vana_pipecat-0.1.0/PKG-INFO +88 -0
- vana_pipecat-0.1.0/README.md +62 -0
- vana_pipecat-0.1.0/pyproject.toml +33 -0
- vana_pipecat-0.1.0/setup.cfg +4 -0
- vana_pipecat-0.1.0/tests/test_vana_observer.py +130 -0
- vana_pipecat-0.1.0/vana_pipecat/__init__.py +13 -0
- vana_pipecat-0.1.0/vana_pipecat/events.py +134 -0
- vana_pipecat-0.1.0/vana_pipecat/ingest.py +130 -0
- vana_pipecat-0.1.0/vana_pipecat/observer.py +155 -0
- vana_pipecat-0.1.0/vana_pipecat.egg-info/PKG-INFO +88 -0
- vana_pipecat-0.1.0/vana_pipecat.egg-info/SOURCES.txt +13 -0
- vana_pipecat-0.1.0/vana_pipecat.egg-info/dependency_links.txt +1 -0
- vana_pipecat-0.1.0/vana_pipecat.egg-info/requires.txt +3 -0
- vana_pipecat-0.1.0/vana_pipecat.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vana-pipecat
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Send per-turn latency, transcripts and cost from any Pipecat voice bot to vAna, the open-source voice agent analytics app.
|
|
5
|
+
Author: Chaitanya Kalluri
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/kkchaitanya1012/vAna
|
|
8
|
+
Project-URL: Documentation, https://github.com/kkchaitanya1012/vAna/tree/main/sdk/pipecat#readme
|
|
9
|
+
Project-URL: Issues, https://github.com/kkchaitanya1012/vAna/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/kkchaitanya1012/vAna/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: pipecat,voice-ai,voice-agent,latency,observability,analytics
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
18
|
+
Classifier: Topic :: System :: Monitoring
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pipecat-ai<2,>=1.15
|
|
23
|
+
Requires-Dist: httpx>=0.27
|
|
24
|
+
Requires-Dist: loguru>=0.7
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# vana-pipecat
|
|
28
|
+
|
|
29
|
+
Send per-turn latency, transcripts and cost from any [Pipecat](https://github.com/pipecat-ai/pipecat) voice bot to [vAna](https://github.com/kkchaitanya1012/vAna).
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install vana-pipecat
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or from a checkout of the repository: `pip install -e sdk/pipecat`.
|
|
38
|
+
|
|
39
|
+
It needs `pipecat-ai` 1.15 or later (below 2.0) and a running vAna API.
|
|
40
|
+
|
|
41
|
+
## Use
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from vana_pipecat import VanaObserver
|
|
45
|
+
|
|
46
|
+
task = PipelineTask(
|
|
47
|
+
pipeline,
|
|
48
|
+
params=PipelineParams(enable_metrics=True, enable_usage_metrics=True),
|
|
49
|
+
observers=[VanaObserver(name="support-bot")],
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The observer:
|
|
54
|
+
|
|
55
|
+
1. Finds the speech-to-text, language model and voice services in the pipeline (class and model or voice), so vAna can label the call and estimate its cost from `config/providers.yaml`.
|
|
56
|
+
2. Creates a vAna session when the pipeline starts. Events are buffered until the session exists, so none are lost.
|
|
57
|
+
3. Turns Pipecat frames into vAna's events (user speech, end of turn, final transcript, first LLM token, first TTS audio, bot speech, interruptions, usage metrics), batched and retried in the background. It never blocks the audio pipeline.
|
|
58
|
+
4. Closes the session when the pipeline is torn down. vAna then derives turns, the verdict and the summary.
|
|
59
|
+
|
|
60
|
+
## Options
|
|
61
|
+
|
|
62
|
+
| Argument | Default | Meaning |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `name` | `pipecat-bot` | Label shown in vAna's session list |
|
|
65
|
+
| `url` | `$VANA_URL`, then `http://localhost:8000` | vAna API base URL |
|
|
66
|
+
| `api_key` | `$VANA_INGEST_KEY` | Ingest key; not needed for a local API without one |
|
|
67
|
+
| `stt`, `llm`, `tts` | detected | Overrides, for example `llm={"provider": "openai", "model": "gpt-4.1-mini"}` |
|
|
68
|
+
| `source` | `pipecat` | Short tag for where the call came from |
|
|
69
|
+
|
|
70
|
+
`observer.session_id` holds the vAna session id once it is created, for linking to `http://<web>/sessions/<id>`.
|
|
71
|
+
|
|
72
|
+
## What is measured
|
|
73
|
+
|
|
74
|
+
Times come from the observer's own monotonic clock, at the moment frames pass through your pipeline. They are server-side: they do not include the caller's microphone or network. Recordings are not sent by the observer; you can upload a WAV yourself with `observer.client.upload_audio(wav_bytes)` before the pipeline ends.
|
|
75
|
+
|
|
76
|
+
## Troubleshooting
|
|
77
|
+
|
|
78
|
+
**The browser never connects to a SmallWebRTC bot.** This is a Pipecat and aiortc issue, not one in this package, but a fresh install hits it. With current releases of the crypto packages that aiortc uses, the WebRTC handshake stalls and Pipecat logs `Timeout establishing the connection to the remote peer`. These versions work with `pipecat-ai` 1.15:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install aiortc==1.15.0 aioice==0.12.1 cryptography==50.0.2 pyOpenSSL==26.4.0 pylibsrtp==1.0.0
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Test
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
python -m pytest # from sdk/pipecat, in an environment with pipecat-ai installed
|
|
88
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# vana-pipecat
|
|
2
|
+
|
|
3
|
+
Send per-turn latency, transcripts and cost from any [Pipecat](https://github.com/pipecat-ai/pipecat) voice bot to [vAna](https://github.com/kkchaitanya1012/vAna).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install vana-pipecat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or from a checkout of the repository: `pip install -e sdk/pipecat`.
|
|
12
|
+
|
|
13
|
+
It needs `pipecat-ai` 1.15 or later (below 2.0) and a running vAna API.
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from vana_pipecat import VanaObserver
|
|
19
|
+
|
|
20
|
+
task = PipelineTask(
|
|
21
|
+
pipeline,
|
|
22
|
+
params=PipelineParams(enable_metrics=True, enable_usage_metrics=True),
|
|
23
|
+
observers=[VanaObserver(name="support-bot")],
|
|
24
|
+
)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The observer:
|
|
28
|
+
|
|
29
|
+
1. Finds the speech-to-text, language model and voice services in the pipeline (class and model or voice), so vAna can label the call and estimate its cost from `config/providers.yaml`.
|
|
30
|
+
2. Creates a vAna session when the pipeline starts. Events are buffered until the session exists, so none are lost.
|
|
31
|
+
3. Turns Pipecat frames into vAna's events (user speech, end of turn, final transcript, first LLM token, first TTS audio, bot speech, interruptions, usage metrics), batched and retried in the background. It never blocks the audio pipeline.
|
|
32
|
+
4. Closes the session when the pipeline is torn down. vAna then derives turns, the verdict and the summary.
|
|
33
|
+
|
|
34
|
+
## Options
|
|
35
|
+
|
|
36
|
+
| Argument | Default | Meaning |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `name` | `pipecat-bot` | Label shown in vAna's session list |
|
|
39
|
+
| `url` | `$VANA_URL`, then `http://localhost:8000` | vAna API base URL |
|
|
40
|
+
| `api_key` | `$VANA_INGEST_KEY` | Ingest key; not needed for a local API without one |
|
|
41
|
+
| `stt`, `llm`, `tts` | detected | Overrides, for example `llm={"provider": "openai", "model": "gpt-4.1-mini"}` |
|
|
42
|
+
| `source` | `pipecat` | Short tag for where the call came from |
|
|
43
|
+
|
|
44
|
+
`observer.session_id` holds the vAna session id once it is created, for linking to `http://<web>/sessions/<id>`.
|
|
45
|
+
|
|
46
|
+
## What is measured
|
|
47
|
+
|
|
48
|
+
Times come from the observer's own monotonic clock, at the moment frames pass through your pipeline. They are server-side: they do not include the caller's microphone or network. Recordings are not sent by the observer; you can upload a WAV yourself with `observer.client.upload_audio(wav_bytes)` before the pipeline ends.
|
|
49
|
+
|
|
50
|
+
## Troubleshooting
|
|
51
|
+
|
|
52
|
+
**The browser never connects to a SmallWebRTC bot.** This is a Pipecat and aiortc issue, not one in this package, but a fresh install hits it. With current releases of the crypto packages that aiortc uses, the WebRTC handshake stalls and Pipecat logs `Timeout establishing the connection to the remote peer`. These versions work with `pipecat-ai` 1.15:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install aiortc==1.15.0 aioice==0.12.1 cryptography==50.0.2 pyOpenSSL==26.4.0 pylibsrtp==1.0.0
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Test
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python -m pytest # from sdk/pipecat, in an environment with pipecat-ai installed
|
|
62
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vana-pipecat"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Send per-turn latency, transcripts and cost from any Pipecat voice bot to vAna, the open-source voice agent analytics app."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Chaitanya Kalluri" }]
|
|
13
|
+
requires-python = ">=3.11"
|
|
14
|
+
dependencies = ["pipecat-ai>=1.15,<2", "httpx>=0.27", "loguru>=0.7"]
|
|
15
|
+
keywords = ["pipecat", "voice-ai", "voice-agent", "latency", "observability", "analytics"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Topic :: Multimedia :: Sound/Audio :: Speech",
|
|
23
|
+
"Topic :: System :: Monitoring",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/kkchaitanya1012/vAna"
|
|
28
|
+
Documentation = "https://github.com/kkchaitanya1012/vAna/tree/main/sdk/pipecat#readme"
|
|
29
|
+
Issues = "https://github.com/kkchaitanya1012/vAna/issues"
|
|
30
|
+
Changelog = "https://github.com/kkchaitanya1012/vAna/blob/main/CHANGELOG.md"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
packages = ["vana_pipecat"]
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
import pytest
|
|
6
|
+
from pipecat.frames.frames import (
|
|
7
|
+
BotStartedSpeakingFrame,
|
|
8
|
+
LLMFullResponseEndFrame,
|
|
9
|
+
LLMFullResponseStartFrame,
|
|
10
|
+
LLMTextFrame,
|
|
11
|
+
TranscriptionFrame,
|
|
12
|
+
TTSAudioRawFrame,
|
|
13
|
+
TTSStartedFrame,
|
|
14
|
+
UserStoppedSpeakingFrame,
|
|
15
|
+
VADUserStartedSpeakingFrame,
|
|
16
|
+
VADUserStoppedSpeakingFrame,
|
|
17
|
+
)
|
|
18
|
+
from pipecat.observers.base_observer import FramePushed, ProcessorSetUp
|
|
19
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
20
|
+
from pipecat.processors.frame_processor import FrameDirection
|
|
21
|
+
from pipecat.services.deepgram.stt import DeepgramSTTService
|
|
22
|
+
|
|
23
|
+
from vana_pipecat import VanaObserver
|
|
24
|
+
from vana_pipecat import ingest
|
|
25
|
+
from vana_pipecat.ingest import describe_service
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture(autouse=True)
|
|
29
|
+
def short_setup_wait(monkeypatch):
|
|
30
|
+
monkeypatch.setattr(ingest, "SETUP_WAIT_S", 0.2)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class FakeApi:
|
|
34
|
+
def __init__(self):
|
|
35
|
+
self.created, self.events, self.headers = None, [], []
|
|
36
|
+
|
|
37
|
+
def __call__(self, request: httpx.Request) -> httpx.Response:
|
|
38
|
+
self.headers.append(request.headers.get("authorization"))
|
|
39
|
+
if request.url.path == "/ingest/sessions":
|
|
40
|
+
self.created = json.loads(request.content)
|
|
41
|
+
return httpx.Response(201, json={"session_id": "s-1"})
|
|
42
|
+
if request.url.path == "/ingest/sessions/s-1/events":
|
|
43
|
+
self.events += json.loads(request.content)["events"]
|
|
44
|
+
return httpx.Response(204)
|
|
45
|
+
return httpx.Response(404)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def observer(api: FakeApi, **kw) -> VanaObserver:
|
|
49
|
+
obs = VanaObserver("support-bot", url="http://vana", api_key="k", **kw)
|
|
50
|
+
obs.client._http = httpx.AsyncClient(transport=httpx.MockTransport(api), headers=obs.client._http.headers)
|
|
51
|
+
return obs
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
async def push(obs, *frames, source=None):
|
|
55
|
+
for f in frames:
|
|
56
|
+
await obs.on_push_frame(FramePushed(source, None, f, FrameDirection.DOWNSTREAM, 0))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_describe_service_reads_class_and_model():
|
|
60
|
+
stage, info = describe_service(DeepgramSTTService(api_key="x"))
|
|
61
|
+
assert stage == "stt"
|
|
62
|
+
assert info["service"] == "pipecat.services.deepgram.stt.DeepgramSTTService"
|
|
63
|
+
assert describe_service(object()) is None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def test_full_call_creates_session_streams_events_and_closes():
|
|
67
|
+
api = FakeApi()
|
|
68
|
+
obs = observer(api, llm={"provider": "openai", "model": "gpt-4.1-mini"})
|
|
69
|
+
await obs.on_processor_setup(ProcessorSetUp(DeepgramSTTService(api_key="x"), 0, 0))
|
|
70
|
+
await obs.on_pipeline_started()
|
|
71
|
+
await push(
|
|
72
|
+
obs,
|
|
73
|
+
VADUserStartedSpeakingFrame(start_secs=0.2),
|
|
74
|
+
VADUserStoppedSpeakingFrame(stop_secs=0.4),
|
|
75
|
+
UserStoppedSpeakingFrame(),
|
|
76
|
+
TranscriptionFrame(text="hi", user_id="u", timestamp="t"),
|
|
77
|
+
LLMFullResponseStartFrame(),
|
|
78
|
+
LLMTextFrame(text="hello"),
|
|
79
|
+
TTSStartedFrame(),
|
|
80
|
+
TTSAudioRawFrame(audio=b"\0\0", sample_rate=16000, num_channels=1),
|
|
81
|
+
BotStartedSpeakingFrame(),
|
|
82
|
+
LLMFullResponseEndFrame(),
|
|
83
|
+
)
|
|
84
|
+
await obs.cleanup()
|
|
85
|
+
|
|
86
|
+
assert api.created["name"] == "support-bot"
|
|
87
|
+
assert api.created["stt"]["service"].endswith("DeepgramSTTService")
|
|
88
|
+
assert api.created["llm"] == {"provider": "openai", "model": "gpt-4.1-mini"}
|
|
89
|
+
types = [e["type"] for e in api.events]
|
|
90
|
+
assert types[0] == "session_started" and types[-1] == "session_closed"
|
|
91
|
+
assert {"stt_final", "llm_first_token", "tts_first_byte", "bot_started_speaking"} <= set(types)
|
|
92
|
+
assert [e["seq"] for e in api.events] == sorted(e["seq"] for e in api.events)
|
|
93
|
+
assert set(api.headers) == {"Bearer k"}
|
|
94
|
+
assert obs.session_id == "s-1"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
async def test_events_are_kept_until_the_session_exists():
|
|
98
|
+
calls = {"n": 0}
|
|
99
|
+
|
|
100
|
+
def flaky(request):
|
|
101
|
+
if request.url.path == "/ingest/sessions":
|
|
102
|
+
calls["n"] += 1
|
|
103
|
+
if calls["n"] == 1:
|
|
104
|
+
return httpx.Response(503)
|
|
105
|
+
return httpx.Response(201, json={"session_id": "s-1"})
|
|
106
|
+
api.events += json.loads(request.content)["events"]
|
|
107
|
+
return httpx.Response(204)
|
|
108
|
+
|
|
109
|
+
api = FakeApi()
|
|
110
|
+
obs = VanaObserver("bot", url="http://vana")
|
|
111
|
+
obs.client._http = httpx.AsyncClient(transport=httpx.MockTransport(flaky))
|
|
112
|
+
await obs.on_pipeline_started()
|
|
113
|
+
await obs.cleanup()
|
|
114
|
+
assert calls["n"] == 2
|
|
115
|
+
assert [e["type"] for e in api.events] == ["session_started", "session_closed"]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
async def test_session_waits_for_services_set_up_after_the_pipeline_started():
|
|
119
|
+
# Pipecat can start the pipeline before a slow service (here speech-to-text) finishes setting up.
|
|
120
|
+
api = FakeApi()
|
|
121
|
+
obs = observer(api)
|
|
122
|
+
await obs.on_pipeline_started()
|
|
123
|
+
|
|
124
|
+
async def late_setup():
|
|
125
|
+
await asyncio.sleep(0.05)
|
|
126
|
+
await obs.on_processor_setup(ProcessorSetUp(DeepgramSTTService(api_key="x"), 0, 0))
|
|
127
|
+
await obs.on_processor_setup(ProcessorSetUp(Pipeline([]), 0, 0))
|
|
128
|
+
|
|
129
|
+
await asyncio.gather(late_setup(), obs.cleanup())
|
|
130
|
+
assert api.created["stt"]["service"].endswith("DeepgramSTTService")
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""vAna for Pipecat: per-turn latency, transcript and cost for any Pipecat voice bot."""
|
|
2
|
+
|
|
3
|
+
from vana_pipecat.events import ApiEvents
|
|
4
|
+
from vana_pipecat.ingest import VanaObserver
|
|
5
|
+
from vana_pipecat.observer import SessionMetricsObserver
|
|
6
|
+
|
|
7
|
+
__all__ = ["ApiEvents", "SessionMetricsObserver", "VanaObserver"]
|
|
8
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = version("vana-pipecat") # single source: pyproject.toml
|
|
12
|
+
except PackageNotFoundError: # running from a source checkout that was not installed
|
|
13
|
+
__version__ = "0.0.0"
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Buffered event delivery to the vAna API.
|
|
2
|
+
|
|
3
|
+
emit() is synchronous and never blocks the audio pipeline. A background task
|
|
4
|
+
flushes batches and retries with backoff. Delivery is at-least-once; the API
|
|
5
|
+
drops duplicate seq values.
|
|
6
|
+
|
|
7
|
+
Two ways to use it:
|
|
8
|
+
- vAna's own voice server knows the session id up front and posts to
|
|
9
|
+
/sessions/{id}/events with the internal token.
|
|
10
|
+
- An external bot (VanaObserver) posts to /ingest/sessions/{id}/events with an
|
|
11
|
+
ingest key, and creates the session lazily through `open_session`. Events are
|
|
12
|
+
buffered until the session exists, so none are lost while it is created.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
import os
|
|
17
|
+
import time
|
|
18
|
+
from collections.abc import Awaitable, Callable
|
|
19
|
+
|
|
20
|
+
import httpx
|
|
21
|
+
from loguru import logger
|
|
22
|
+
|
|
23
|
+
FLUSH_INTERVAL_S = 0.4
|
|
24
|
+
MAX_BATCH = 100
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ApiEvents:
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
api_url: str,
|
|
31
|
+
session_id: str | None = None,
|
|
32
|
+
*,
|
|
33
|
+
prefix: str = "",
|
|
34
|
+
headers: dict[str, str] | None = None,
|
|
35
|
+
open_session: Callable[[httpx.AsyncClient], Awaitable[str]] | None = None,
|
|
36
|
+
):
|
|
37
|
+
self._base = f"{api_url.rstrip('/')}{prefix}/sessions"
|
|
38
|
+
self.session_id = session_id
|
|
39
|
+
self._open_session = open_session
|
|
40
|
+
self._seq = 0
|
|
41
|
+
self._t0 = time.monotonic()
|
|
42
|
+
self._buf: list[dict] = []
|
|
43
|
+
if headers is None:
|
|
44
|
+
token = os.getenv("VANA_INTERNAL_TOKEN", "")
|
|
45
|
+
headers = {"x-internal-token": token} if token else {}
|
|
46
|
+
self._http = httpx.AsyncClient(timeout=httpx.Timeout(5, read=60, write=120), headers=headers)
|
|
47
|
+
self._task: asyncio.Task | None = None
|
|
48
|
+
self._stopping = False
|
|
49
|
+
|
|
50
|
+
def t_ms(self) -> float:
|
|
51
|
+
return (time.monotonic() - self._t0) * 1000
|
|
52
|
+
|
|
53
|
+
def start(self):
|
|
54
|
+
if self._task is None:
|
|
55
|
+
self._task = asyncio.create_task(self._loop())
|
|
56
|
+
|
|
57
|
+
def emit(self, type_: str, payload: dict | None = None, turn_idx: int | None = None):
|
|
58
|
+
self._seq += 1
|
|
59
|
+
self._buf.append({"seq": self._seq, "type": type_, "t_ms": round(self.t_ms(), 1),
|
|
60
|
+
"turn_idx": turn_idx, "payload": payload})
|
|
61
|
+
|
|
62
|
+
async def _ensure_session(self) -> bool:
|
|
63
|
+
if self.session_id:
|
|
64
|
+
return True
|
|
65
|
+
if self._open_session is None:
|
|
66
|
+
return False
|
|
67
|
+
try:
|
|
68
|
+
self.session_id = await self._open_session(self._http)
|
|
69
|
+
return True
|
|
70
|
+
except (httpx.HTTPError, KeyError, ValueError) as e:
|
|
71
|
+
logger.warning(f"vAna session not created yet: {e}")
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
async def _send(self, batch: list[dict]) -> bool:
|
|
75
|
+
try:
|
|
76
|
+
r = await self._http.post(f"{self._base}/{self.session_id}/events", json={"events": batch})
|
|
77
|
+
r.raise_for_status()
|
|
78
|
+
return True
|
|
79
|
+
except httpx.HTTPError as e:
|
|
80
|
+
logger.warning(f"events not delivered ({len(batch)}): {e}")
|
|
81
|
+
return False
|
|
82
|
+
|
|
83
|
+
async def _flush_once(self) -> bool:
|
|
84
|
+
if not self._buf:
|
|
85
|
+
return True
|
|
86
|
+
if not await self._ensure_session():
|
|
87
|
+
return False
|
|
88
|
+
batch = self._buf[:MAX_BATCH]
|
|
89
|
+
if await self._send(batch):
|
|
90
|
+
del self._buf[: len(batch)]
|
|
91
|
+
return True
|
|
92
|
+
return False
|
|
93
|
+
|
|
94
|
+
async def _loop(self):
|
|
95
|
+
delay = FLUSH_INTERVAL_S
|
|
96
|
+
while not self._stopping:
|
|
97
|
+
await asyncio.sleep(delay)
|
|
98
|
+
ok = await self._flush_once()
|
|
99
|
+
delay = FLUSH_INTERVAL_S if ok else min(delay * 2, 4.0)
|
|
100
|
+
|
|
101
|
+
async def upload_audio(self, wav: bytes) -> bool:
|
|
102
|
+
if not await self._ensure_session():
|
|
103
|
+
return False
|
|
104
|
+
for attempt in range(3):
|
|
105
|
+
try:
|
|
106
|
+
r = await self._http.put(f"{self._base}/{self.session_id}/audio", content=wav,
|
|
107
|
+
headers={"content-type": "audio/wav"})
|
|
108
|
+
r.raise_for_status()
|
|
109
|
+
return True
|
|
110
|
+
except httpx.HTTPError as e:
|
|
111
|
+
logger.warning(f"audio upload failed (attempt {attempt + 1}): {e}")
|
|
112
|
+
await asyncio.sleep(0.5 * (attempt + 1))
|
|
113
|
+
logger.error("recording was not uploaded")
|
|
114
|
+
return False
|
|
115
|
+
|
|
116
|
+
async def close(self):
|
|
117
|
+
"""Stop the loop, then make a last effort to deliver everything buffered."""
|
|
118
|
+
self._stopping = True
|
|
119
|
+
if self._task:
|
|
120
|
+
self._task.cancel()
|
|
121
|
+
try:
|
|
122
|
+
await self._task
|
|
123
|
+
except asyncio.CancelledError:
|
|
124
|
+
pass
|
|
125
|
+
for attempt in range(4):
|
|
126
|
+
while self._buf:
|
|
127
|
+
if not await self._flush_once():
|
|
128
|
+
break
|
|
129
|
+
if not self._buf:
|
|
130
|
+
break
|
|
131
|
+
await asyncio.sleep(0.5 * (attempt + 1))
|
|
132
|
+
if self._buf:
|
|
133
|
+
logger.error(f"{len(self._buf)} events were never delivered")
|
|
134
|
+
await self._http.aclose()
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""VanaObserver: send per-turn latency from any Pipecat bot to a vAna API.
|
|
2
|
+
|
|
3
|
+
from vana_pipecat import VanaObserver
|
|
4
|
+
|
|
5
|
+
task = PipelineTask(pipeline, params=PipelineParams(enable_metrics=True, enable_usage_metrics=True),
|
|
6
|
+
observers=[VanaObserver(name="support-bot")])
|
|
7
|
+
|
|
8
|
+
The observer finds the speech-to-text, language model and voice services in the
|
|
9
|
+
pipeline by itself, so vAna can label the call and estimate its cost. It creates
|
|
10
|
+
the session when the pipeline starts and closes it when the pipeline ends.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import asyncio
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
import httpx
|
|
17
|
+
from loguru import logger
|
|
18
|
+
from pipecat.observers.base_observer import FramePushed, ProcessorSetUp
|
|
19
|
+
from pipecat.pipeline.base_pipeline import BasePipeline
|
|
20
|
+
from pipecat.services.llm_service import LLMService
|
|
21
|
+
from pipecat.services.stt_service import STTService
|
|
22
|
+
from pipecat.services.tts_service import TTSService
|
|
23
|
+
|
|
24
|
+
from vana_pipecat.events import ApiEvents
|
|
25
|
+
from vana_pipecat.observer import SessionMetricsObserver
|
|
26
|
+
|
|
27
|
+
_STAGES = (("stt", STTService), ("llm", LLMService), ("tts", TTSService))
|
|
28
|
+
# Pipecat sets processors up concurrently and can start the pipeline before slow services
|
|
29
|
+
# (Deepgram, Cartesia) finish, so the session waits this long at most for the stack to be known.
|
|
30
|
+
SETUP_WAIT_S = 3.0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _setting(processor, name: str) -> str | None:
|
|
34
|
+
value = getattr(getattr(processor, "_settings", None), name, None)
|
|
35
|
+
return value if isinstance(value, str) and value else None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def describe_service(processor) -> tuple[str, dict] | None:
|
|
39
|
+
"""(stage, {service, model or voice}) for an STT, LLM or TTS service; None for anything else."""
|
|
40
|
+
for stage, base in _STAGES:
|
|
41
|
+
if isinstance(processor, base):
|
|
42
|
+
cls = type(processor)
|
|
43
|
+
info = {"service": f"{cls.__module__}.{cls.__qualname__}", "model": _setting(processor, "model")}
|
|
44
|
+
if stage == "tts":
|
|
45
|
+
info["voice"] = _setting(processor, "voice")
|
|
46
|
+
return stage, info
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class VanaObserver(SessionMetricsObserver):
|
|
51
|
+
"""Pipecat observer that records a call in vAna.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
name: Label shown in vAna's session list (for example the bot or persona name).
|
|
55
|
+
url: vAna API base URL. Defaults to $VANA_URL, then http://localhost:8000.
|
|
56
|
+
api_key: Ingest key. Defaults to $VANA_INGEST_KEY. Not needed for a local API without one.
|
|
57
|
+
stt, llm, tts: Optional overrides, for example {"provider": "deepgram", "model": "nova-3-general"}.
|
|
58
|
+
Anything not given is detected from the pipeline's services.
|
|
59
|
+
source: Short tag for where the call came from. Defaults to "pipecat".
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def __init__(self, name: str = "pipecat-bot", *, url: str | None = None, api_key: str | None = None,
|
|
63
|
+
stt: dict | None = None, llm: dict | None = None, tts: dict | None = None,
|
|
64
|
+
source: str = "pipecat"):
|
|
65
|
+
url = url or os.getenv("VANA_URL", "http://localhost:8000")
|
|
66
|
+
key = api_key if api_key is not None else os.getenv("VANA_INGEST_KEY", "")
|
|
67
|
+
self._label, self._source = name, source
|
|
68
|
+
self._overrides = {"stt": stt or {}, "llm": llm or {}, "tts": tts or {}}
|
|
69
|
+
self._detected: dict[str, dict] = {}
|
|
70
|
+
self._started = self._closed = False
|
|
71
|
+
self._setup_done = asyncio.Event()
|
|
72
|
+
self.client = ApiEvents(url, prefix="/ingest", headers={"authorization": f"Bearer {key}"} if key else {},
|
|
73
|
+
open_session=self._create_session)
|
|
74
|
+
super().__init__(self.client)
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def session_id(self) -> str | None:
|
|
78
|
+
return self.client.session_id
|
|
79
|
+
|
|
80
|
+
def _note(self, processor) -> None:
|
|
81
|
+
found = describe_service(processor)
|
|
82
|
+
if found and found[0] not in self._detected:
|
|
83
|
+
self._detected[found[0]] = found[1]
|
|
84
|
+
known = self._detected.keys() | {stage for stage, o in self._overrides.items() if o}
|
|
85
|
+
if isinstance(processor, BasePipeline) or known >= {"stt", "llm", "tts"}:
|
|
86
|
+
self._setup_done.set() # a pipeline finished setting up, or every step is known
|
|
87
|
+
|
|
88
|
+
def stack(self) -> dict:
|
|
89
|
+
"""What will be sent for each step: detected values, with any overrides on top."""
|
|
90
|
+
out = {}
|
|
91
|
+
for stage in ("stt", "llm", "tts"):
|
|
92
|
+
merged = {**self._detected.get(stage, {}), **self._overrides[stage]}
|
|
93
|
+
out[stage] = {k: v for k, v in merged.items() if v is not None}
|
|
94
|
+
return out
|
|
95
|
+
|
|
96
|
+
async def _create_session(self, http: httpx.AsyncClient) -> str:
|
|
97
|
+
try:
|
|
98
|
+
await asyncio.wait_for(self._setup_done.wait(), SETUP_WAIT_S)
|
|
99
|
+
except TimeoutError:
|
|
100
|
+
pass # send what was found; events stay buffered meanwhile
|
|
101
|
+
r = await http.post(f"{self.client._base}", json={"name": self._label, "source": self._source, **self.stack()})
|
|
102
|
+
r.raise_for_status()
|
|
103
|
+
sid = r.json()["session_id"]
|
|
104
|
+
logger.info(f"vAna session {sid}")
|
|
105
|
+
return sid
|
|
106
|
+
|
|
107
|
+
async def on_processor_setup(self, data: ProcessorSetUp):
|
|
108
|
+
self._note(data.processor)
|
|
109
|
+
|
|
110
|
+
async def on_pipeline_started(self):
|
|
111
|
+
if self._started:
|
|
112
|
+
return
|
|
113
|
+
self._started = True
|
|
114
|
+
self.client.start()
|
|
115
|
+
self.client.emit("session_started", {"persona": self._label, "source": self._source, **self.stack()})
|
|
116
|
+
|
|
117
|
+
async def on_push_frame(self, data: FramePushed):
|
|
118
|
+
self._note(data.source) # fallback when setup events were not observed
|
|
119
|
+
if not self._started:
|
|
120
|
+
await self.on_pipeline_started()
|
|
121
|
+
await super().on_push_frame(data)
|
|
122
|
+
|
|
123
|
+
async def cleanup(self):
|
|
124
|
+
"""Called by Pipecat when the pipeline is torn down: close the session and flush."""
|
|
125
|
+
await super().cleanup()
|
|
126
|
+
if self._closed or not self._started:
|
|
127
|
+
return
|
|
128
|
+
self._closed = True
|
|
129
|
+
self.client.emit("session_closed", {"duration_ms": round(self.client.t_ms())})
|
|
130
|
+
await self.client.close()
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Turns Pipecat frames into the session events defined in DESIGN.md 2.4.
|
|
2
|
+
|
|
3
|
+
Turn rules (the API groups events by turn_idx):
|
|
4
|
+
- The bot's greeting is turn 0 with no user timings.
|
|
5
|
+
- A new turn starts when the user starts speaking and the current turn has
|
|
6
|
+
already begun its response (bot or LLM output). That also flags an interruption
|
|
7
|
+
of the previous turn if its response was still in progress.
|
|
8
|
+
- User pauses before any response started stay in the same turn.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from pipecat.frames.frames import (
|
|
12
|
+
BotStartedSpeakingFrame,
|
|
13
|
+
BotStoppedSpeakingFrame,
|
|
14
|
+
ErrorFrame,
|
|
15
|
+
LLMFullResponseEndFrame,
|
|
16
|
+
LLMFullResponseStartFrame,
|
|
17
|
+
LLMTextFrame,
|
|
18
|
+
MetricsFrame,
|
|
19
|
+
TranscriptionFrame,
|
|
20
|
+
TTSAudioRawFrame,
|
|
21
|
+
TTSStartedFrame,
|
|
22
|
+
TTSStoppedFrame,
|
|
23
|
+
UserStoppedSpeakingFrame,
|
|
24
|
+
VADUserStartedSpeakingFrame,
|
|
25
|
+
VADUserStoppedSpeakingFrame,
|
|
26
|
+
)
|
|
27
|
+
from pipecat.metrics.metrics import (
|
|
28
|
+
LLMUsageMetricsData,
|
|
29
|
+
ProcessingMetricsData,
|
|
30
|
+
TTFBMetricsData,
|
|
31
|
+
TTSUsageMetricsData,
|
|
32
|
+
)
|
|
33
|
+
from pipecat.observers.base_observer import BaseObserver, FramePushed
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class SessionMetricsObserver(BaseObserver):
|
|
37
|
+
def __init__(self, events):
|
|
38
|
+
super().__init__(observe_every_push=False) # each frame once
|
|
39
|
+
self._ev = events
|
|
40
|
+
self.turn = -1
|
|
41
|
+
self._responding = False # LLM output or bot speech has begun in this turn
|
|
42
|
+
self._user_speaking = False
|
|
43
|
+
self._bot_speaking = False
|
|
44
|
+
self._llm_active = False
|
|
45
|
+
self._first_token = False
|
|
46
|
+
self._tts_first = False
|
|
47
|
+
self._tts_started = False
|
|
48
|
+
self._tts_active = False # TTS is synthesizing right now
|
|
49
|
+
self._llm_text: list[str] = []
|
|
50
|
+
|
|
51
|
+
def _emit(self, type_: str, payload: dict | None = None, turn: int | None = None):
|
|
52
|
+
self._ev.emit(type_, payload, self.turn if turn is None else turn)
|
|
53
|
+
|
|
54
|
+
def _new_turn(self):
|
|
55
|
+
self.turn += 1
|
|
56
|
+
self._responding = False
|
|
57
|
+
self._first_token = False
|
|
58
|
+
self._tts_first = False
|
|
59
|
+
self._tts_started = False
|
|
60
|
+
self._llm_text = []
|
|
61
|
+
|
|
62
|
+
def _ensure_turn(self):
|
|
63
|
+
if self.turn < 0:
|
|
64
|
+
self._new_turn()
|
|
65
|
+
|
|
66
|
+
async def on_push_frame(self, data: FramePushed):
|
|
67
|
+
f = data.frame
|
|
68
|
+
|
|
69
|
+
if isinstance(f, VADUserStartedSpeakingFrame):
|
|
70
|
+
if self._user_speaking:
|
|
71
|
+
return
|
|
72
|
+
self._user_speaking = True
|
|
73
|
+
if self.turn < 0 or self._responding:
|
|
74
|
+
if self.turn >= 0 and (self._bot_speaking or self._llm_active or self._tts_active):
|
|
75
|
+
during = "playout" if self._bot_speaking else "tts" if self._tts_first else "llm"
|
|
76
|
+
self._emit("interruption", {"during": during}, turn=self.turn)
|
|
77
|
+
self._new_turn()
|
|
78
|
+
self._emit("user_started_speaking", {"start_secs": f.start_secs})
|
|
79
|
+
|
|
80
|
+
elif isinstance(f, VADUserStoppedSpeakingFrame):
|
|
81
|
+
if not self._user_speaking:
|
|
82
|
+
return
|
|
83
|
+
self._user_speaking = False
|
|
84
|
+
self._ensure_turn()
|
|
85
|
+
self._emit("user_stopped_speaking", {"stop_secs": f.stop_secs})
|
|
86
|
+
|
|
87
|
+
elif isinstance(f, UserStoppedSpeakingFrame):
|
|
88
|
+
self._ensure_turn()
|
|
89
|
+
self._emit("turn_end_detected")
|
|
90
|
+
|
|
91
|
+
elif isinstance(f, TranscriptionFrame):
|
|
92
|
+
self._ensure_turn()
|
|
93
|
+
self._emit("stt_final", {"text": f.text})
|
|
94
|
+
|
|
95
|
+
elif isinstance(f, LLMFullResponseStartFrame):
|
|
96
|
+
self._ensure_turn()
|
|
97
|
+
self._responding = True
|
|
98
|
+
self._llm_active = True
|
|
99
|
+
self._first_token = False
|
|
100
|
+
self._llm_text = []
|
|
101
|
+
self._emit("llm_started")
|
|
102
|
+
|
|
103
|
+
elif isinstance(f, LLMTextFrame):
|
|
104
|
+
if self._llm_active:
|
|
105
|
+
if not self._first_token:
|
|
106
|
+
self._first_token = True
|
|
107
|
+
self._emit("llm_first_token")
|
|
108
|
+
self._llm_text.append(f.text)
|
|
109
|
+
|
|
110
|
+
elif isinstance(f, LLMFullResponseEndFrame):
|
|
111
|
+
if self._llm_active:
|
|
112
|
+
self._llm_active = False
|
|
113
|
+
self._emit("llm_completed", {"text": "".join(self._llm_text).strip()})
|
|
114
|
+
|
|
115
|
+
elif isinstance(f, TTSStartedFrame):
|
|
116
|
+
self._tts_started = True
|
|
117
|
+
self._tts_active = True
|
|
118
|
+
|
|
119
|
+
elif isinstance(f, TTSStoppedFrame):
|
|
120
|
+
self._tts_active = False
|
|
121
|
+
|
|
122
|
+
elif isinstance(f, TTSAudioRawFrame):
|
|
123
|
+
if self._tts_started and not self._tts_first:
|
|
124
|
+
self._tts_first = True
|
|
125
|
+
self._emit("tts_first_byte")
|
|
126
|
+
|
|
127
|
+
elif isinstance(f, BotStartedSpeakingFrame):
|
|
128
|
+
if self._bot_speaking:
|
|
129
|
+
return
|
|
130
|
+
self._bot_speaking = True
|
|
131
|
+
self._ensure_turn()
|
|
132
|
+
self._responding = True
|
|
133
|
+
self._emit("bot_started_speaking")
|
|
134
|
+
|
|
135
|
+
elif isinstance(f, BotStoppedSpeakingFrame):
|
|
136
|
+
if not self._bot_speaking:
|
|
137
|
+
return
|
|
138
|
+
self._bot_speaking = False
|
|
139
|
+
self._emit("bot_stopped_speaking")
|
|
140
|
+
|
|
141
|
+
elif isinstance(f, MetricsFrame):
|
|
142
|
+
for m in f.data:
|
|
143
|
+
if isinstance(m, LLMUsageMetricsData):
|
|
144
|
+
self._emit("metrics", {"kind": "llm_usage", "processor": m.processor,
|
|
145
|
+
"prompt_tokens": m.value.prompt_tokens,
|
|
146
|
+
"completion_tokens": m.value.completion_tokens})
|
|
147
|
+
elif isinstance(m, TTSUsageMetricsData):
|
|
148
|
+
self._emit("metrics", {"kind": "tts_chars", "processor": m.processor, "chars": m.value})
|
|
149
|
+
elif isinstance(m, TTFBMetricsData):
|
|
150
|
+
self._emit("metrics", {"kind": "ttfb", "processor": m.processor, "ms": round(m.value * 1000)})
|
|
151
|
+
elif isinstance(m, ProcessingMetricsData):
|
|
152
|
+
self._emit("metrics", {"kind": "processing", "processor": m.processor, "ms": round(m.value * 1000)})
|
|
153
|
+
|
|
154
|
+
elif isinstance(f, ErrorFrame):
|
|
155
|
+
self._emit("error", {"message": str(f.error)[:300]})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vana-pipecat
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Send per-turn latency, transcripts and cost from any Pipecat voice bot to vAna, the open-source voice agent analytics app.
|
|
5
|
+
Author: Chaitanya Kalluri
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/kkchaitanya1012/vAna
|
|
8
|
+
Project-URL: Documentation, https://github.com/kkchaitanya1012/vAna/tree/main/sdk/pipecat#readme
|
|
9
|
+
Project-URL: Issues, https://github.com/kkchaitanya1012/vAna/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/kkchaitanya1012/vAna/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: pipecat,voice-ai,voice-agent,latency,observability,analytics
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
18
|
+
Classifier: Topic :: System :: Monitoring
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pipecat-ai<2,>=1.15
|
|
23
|
+
Requires-Dist: httpx>=0.27
|
|
24
|
+
Requires-Dist: loguru>=0.7
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# vana-pipecat
|
|
28
|
+
|
|
29
|
+
Send per-turn latency, transcripts and cost from any [Pipecat](https://github.com/pipecat-ai/pipecat) voice bot to [vAna](https://github.com/kkchaitanya1012/vAna).
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install vana-pipecat
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or from a checkout of the repository: `pip install -e sdk/pipecat`.
|
|
38
|
+
|
|
39
|
+
It needs `pipecat-ai` 1.15 or later (below 2.0) and a running vAna API.
|
|
40
|
+
|
|
41
|
+
## Use
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from vana_pipecat import VanaObserver
|
|
45
|
+
|
|
46
|
+
task = PipelineTask(
|
|
47
|
+
pipeline,
|
|
48
|
+
params=PipelineParams(enable_metrics=True, enable_usage_metrics=True),
|
|
49
|
+
observers=[VanaObserver(name="support-bot")],
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The observer:
|
|
54
|
+
|
|
55
|
+
1. Finds the speech-to-text, language model and voice services in the pipeline (class and model or voice), so vAna can label the call and estimate its cost from `config/providers.yaml`.
|
|
56
|
+
2. Creates a vAna session when the pipeline starts. Events are buffered until the session exists, so none are lost.
|
|
57
|
+
3. Turns Pipecat frames into vAna's events (user speech, end of turn, final transcript, first LLM token, first TTS audio, bot speech, interruptions, usage metrics), batched and retried in the background. It never blocks the audio pipeline.
|
|
58
|
+
4. Closes the session when the pipeline is torn down. vAna then derives turns, the verdict and the summary.
|
|
59
|
+
|
|
60
|
+
## Options
|
|
61
|
+
|
|
62
|
+
| Argument | Default | Meaning |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `name` | `pipecat-bot` | Label shown in vAna's session list |
|
|
65
|
+
| `url` | `$VANA_URL`, then `http://localhost:8000` | vAna API base URL |
|
|
66
|
+
| `api_key` | `$VANA_INGEST_KEY` | Ingest key; not needed for a local API without one |
|
|
67
|
+
| `stt`, `llm`, `tts` | detected | Overrides, for example `llm={"provider": "openai", "model": "gpt-4.1-mini"}` |
|
|
68
|
+
| `source` | `pipecat` | Short tag for where the call came from |
|
|
69
|
+
|
|
70
|
+
`observer.session_id` holds the vAna session id once it is created, for linking to `http://<web>/sessions/<id>`.
|
|
71
|
+
|
|
72
|
+
## What is measured
|
|
73
|
+
|
|
74
|
+
Times come from the observer's own monotonic clock, at the moment frames pass through your pipeline. They are server-side: they do not include the caller's microphone or network. Recordings are not sent by the observer; you can upload a WAV yourself with `observer.client.upload_audio(wav_bytes)` before the pipeline ends.
|
|
75
|
+
|
|
76
|
+
## Troubleshooting
|
|
77
|
+
|
|
78
|
+
**The browser never connects to a SmallWebRTC bot.** This is a Pipecat and aiortc issue, not one in this package, but a fresh install hits it. With current releases of the crypto packages that aiortc uses, the WebRTC handshake stalls and Pipecat logs `Timeout establishing the connection to the remote peer`. These versions work with `pipecat-ai` 1.15:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install aiortc==1.15.0 aioice==0.12.1 cryptography==50.0.2 pyOpenSSL==26.4.0 pylibsrtp==1.0.0
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Test
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
python -m pytest # from sdk/pipecat, in an environment with pipecat-ai installed
|
|
88
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
tests/test_vana_observer.py
|
|
5
|
+
vana_pipecat/__init__.py
|
|
6
|
+
vana_pipecat/events.py
|
|
7
|
+
vana_pipecat/ingest.py
|
|
8
|
+
vana_pipecat/observer.py
|
|
9
|
+
vana_pipecat.egg-info/PKG-INFO
|
|
10
|
+
vana_pipecat.egg-info/SOURCES.txt
|
|
11
|
+
vana_pipecat.egg-info/dependency_links.txt
|
|
12
|
+
vana_pipecat.egg-info/requires.txt
|
|
13
|
+
vana_pipecat.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vana_pipecat
|