livekit-plugins-cerebras 1.5.3__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,179 @@
1
+ **/.vscode
2
+ **/.DS_Store
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py,cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # poetry
101
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105
+ #poetry.lock
106
+
107
+ # pdm
108
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109
+ #pdm.lock
110
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111
+ # in version control.
112
+ # https://pdm.fming.dev/#use-with-ide
113
+ .pdm.toml
114
+
115
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116
+ __pypackages__/
117
+
118
+ # Celery stuff
119
+ celerybeat-schedule
120
+ celerybeat.pid
121
+
122
+ # SageMath parsed files
123
+ *.sage.py
124
+
125
+ # Environments
126
+ .env
127
+ .venv
128
+ env/
129
+ venv/
130
+ ENV/
131
+ env.bak/
132
+ venv.bak/
133
+
134
+ # Spyder project settings
135
+ .spyderproject
136
+ .spyproject
137
+
138
+ # Rope project settings
139
+ .ropeproject
140
+
141
+ # mkdocs documentation
142
+ /site
143
+
144
+ # mypy
145
+ .mypy_cache/
146
+ .dmypy.json
147
+ dmypy.json
148
+
149
+ # trunk
150
+ .trunk/
151
+
152
+ # Pyre type checker
153
+ .pyre/
154
+
155
+ # pytype static type analyzer
156
+ .pytype/
157
+
158
+ # Cython debug symbols
159
+ cython_debug/
160
+
161
+ # PyCharm
162
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
163
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
164
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
165
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
166
+ .idea/
167
+
168
+ node_modules
169
+
170
+ credentials.json
171
+ pyrightconfig.json
172
+ docs/
173
+
174
+ # Database files
175
+ *.db
176
+
177
+
178
+ # Examples for development
179
+ examples/dev/*
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: livekit-plugins-cerebras
3
+ Version: 1.5.3
4
+ Summary: Cerebras inference plugin for LiveKit Agents
5
+ Project-URL: Documentation, https://docs.livekit.io
6
+ Project-URL: Website, https://livekit.io/
7
+ Project-URL: Source, https://github.com/livekit/agents
8
+ Author-email: LiveKit <hello@livekit.io>
9
+ License-Expression: Apache-2.0
10
+ Keywords: ai,audio,cerebras,livekit,realtime,video,voice
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Topic :: Multimedia :: Sound/Audio
17
+ Classifier: Topic :: Multimedia :: Video
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10.0
20
+ Requires-Dist: livekit-agents[codecs,openai]>=1.5.3
21
+ Requires-Dist: msgpack-types>=0.7.0
22
+ Requires-Dist: msgpack>=1.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # Cerebras plugin for LiveKit Agents
26
+
27
+ Support for LLM with [Cerebras](https://cerebras.ai/) fast inference.
28
+
29
+ See [https://docs.livekit.io/agents/integrations/llm/](https://docs.livekit.io/agents/integrations/llm/) for more information.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install livekit-plugins-cerebras
35
+ ```
36
+
37
+ ## Pre-requisites
38
+
39
+ For credentials, you'll need a Cerebras account and API key. Credentials can be passed directly or via `CEREBRAS_API_KEY` environment variable.
@@ -0,0 +1,15 @@
1
+ # Cerebras plugin for LiveKit Agents
2
+
3
+ Support for LLM with [Cerebras](https://cerebras.ai/) fast inference.
4
+
5
+ See [https://docs.livekit.io/agents/integrations/llm/](https://docs.livekit.io/agents/integrations/llm/) for more information.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install livekit-plugins-cerebras
11
+ ```
12
+
13
+ ## Pre-requisites
14
+
15
+ For credentials, you'll need a Cerebras account and API key. Credentials can be passed directly or via `CEREBRAS_API_KEY` environment variable.
@@ -0,0 +1,44 @@
1
+ # Copyright 2026 LiveKit, Inc.
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.
14
+
15
+ """Cerebras plugin for LiveKit Agents
16
+
17
+ Support for LLM with Cerebras fast inference, including payload optimization
18
+ via gzip compression and msgpack encoding.
19
+ """
20
+
21
+ from livekit.agents import Plugin
22
+
23
+ from .llm import LLM
24
+ from .log import logger
25
+ from .version import __version__
26
+
27
+ __all__ = ["LLM", "__version__"]
28
+
29
+
30
+ class CerebrasPlugin(Plugin):
31
+ def __init__(self) -> None:
32
+ super().__init__(__name__, __version__, __package__, logger)
33
+
34
+
35
+ Plugin.register_plugin(CerebrasPlugin())
36
+
37
+ # Cleanup docs of unexported modules
38
+ _module = dir()
39
+ NOT_IN_ALL = [m for m in _module if m not in __all__]
40
+
41
+ __pdoc__ = {}
42
+
43
+ for n in NOT_IN_ALL:
44
+ __pdoc__[n] = False
@@ -0,0 +1,189 @@
1
+ # Copyright 2026 LiveKit, Inc.
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.
14
+
15
+ from __future__ import annotations
16
+
17
+ import gzip
18
+ import json
19
+ import os
20
+ from typing import Any
21
+
22
+ import httpx
23
+ import msgpack
24
+ import openai
25
+ from openai._models import FinalRequestOptions
26
+ from openai._utils import is_mapping
27
+ from openai.types import ReasoningEffort
28
+
29
+ from livekit.agents.llm import ToolChoice
30
+ from livekit.agents.types import (
31
+ NOT_GIVEN,
32
+ NotGivenOr,
33
+ )
34
+ from livekit.agents.utils import is_given
35
+ from livekit.plugins.openai import LLM as OpenAILLM
36
+
37
+ from .models import CerebrasChatModels
38
+
39
+
40
+ class _CerebrasClient(openai.AsyncClient):
41
+ """AsyncClient subclass that compresses request payloads via msgpack and/or gzip.
42
+
43
+ Overrides _build_request() to serialize json_data directly to the target
44
+ format, avoiding a JSON->dict->msgpack round-trip when msgpack is enabled.
45
+
46
+ See https://inference-docs.cerebras.ai/payload-optimization
47
+ """
48
+
49
+ def __init__(
50
+ self,
51
+ *,
52
+ use_msgpack: bool = False,
53
+ use_gzip: bool = True,
54
+ **kwargs: Any,
55
+ ) -> None:
56
+ super().__init__(**kwargs)
57
+ self._use_msgpack = use_msgpack
58
+ self._use_gzip = use_gzip
59
+
60
+ def _build_request(
61
+ self,
62
+ options: FinalRequestOptions,
63
+ *,
64
+ retries_taken: int = 0,
65
+ ) -> httpx.Request:
66
+ if not (self._use_msgpack or self._use_gzip):
67
+ return super()._build_request(options, retries_taken=retries_taken)
68
+
69
+ json_data = options.json_data
70
+ if json_data is not None:
71
+ # merge extra_json (same logic as base class)
72
+ if options.extra_json is not None:
73
+ if is_mapping(json_data):
74
+ json_data = {**json_data, **options.extra_json}
75
+
76
+ if self._use_msgpack:
77
+ body = msgpack.packb(json_data)
78
+ content_type = "application/vnd.msgpack"
79
+ else:
80
+ body = json.dumps(json_data, separators=(",", ":"), ensure_ascii=False).encode()
81
+ content_type = "application/json"
82
+
83
+ if self._use_gzip:
84
+ body = gzip.compress(body, compresslevel=5)
85
+
86
+ # bypass openapi_dumps() by switching to the content path
87
+ options.json_data = None
88
+ options.extra_json = None
89
+ options.content = body
90
+
91
+ existing = (
92
+ dict(options.headers) if is_given(options.headers) and options.headers else {}
93
+ )
94
+ overrides: dict[str, str] = {"Content-Type": content_type}
95
+ if self._use_gzip:
96
+ overrides["Content-Encoding"] = "gzip"
97
+ options.headers = existing | overrides
98
+
99
+ return super()._build_request(options, retries_taken=retries_taken)
100
+
101
+
102
+ class LLM(OpenAILLM):
103
+ def __init__(
104
+ self,
105
+ *,
106
+ model: str | CerebrasChatModels = "llama3.1-8b",
107
+ api_key: NotGivenOr[str] = NOT_GIVEN,
108
+ base_url: NotGivenOr[str] = "https://api.cerebras.ai/v1",
109
+ client: openai.AsyncClient | None = None,
110
+ user: NotGivenOr[str] = NOT_GIVEN,
111
+ temperature: NotGivenOr[float] = NOT_GIVEN,
112
+ parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
113
+ tool_choice: NotGivenOr[ToolChoice] = NOT_GIVEN,
114
+ reasoning_effort: NotGivenOr[ReasoningEffort] = NOT_GIVEN,
115
+ safety_identifier: NotGivenOr[str] = NOT_GIVEN,
116
+ prompt_cache_key: NotGivenOr[str] = NOT_GIVEN,
117
+ top_p: NotGivenOr[float] = NOT_GIVEN,
118
+ timeout: httpx.Timeout | None = None,
119
+ max_retries: NotGivenOr[int] = NOT_GIVEN,
120
+ gzip_compression: bool = True,
121
+ msgpack_encoding: bool = True,
122
+ ):
123
+ """
124
+ Create a new instance of Cerebras LLM.
125
+
126
+ ``api_key`` must be set to your Cerebras API key, either using the argument or by setting
127
+ the ``CEREBRAS_API_KEY`` environmental variable.
128
+
129
+ When ``gzip_compression`` is True (default), request payloads are gzip-compressed,
130
+ which can reduce TTFT for requests with large prompts.
131
+
132
+ When ``msgpack_encoding`` is True (default), request payloads are encoded with msgpack
133
+ binary format instead of JSON.
134
+ """
135
+
136
+ cerebras_api_key = _get_api_key(api_key)
137
+
138
+ created_client = False
139
+ if client is None and (gzip_compression or msgpack_encoding):
140
+ client = _CerebrasClient(
141
+ use_msgpack=msgpack_encoding,
142
+ use_gzip=gzip_compression,
143
+ api_key=cerebras_api_key,
144
+ base_url=base_url if is_given(base_url) else None,
145
+ max_retries=max_retries if is_given(max_retries) else 0,
146
+ http_client=httpx.AsyncClient(
147
+ timeout=timeout
148
+ if timeout
149
+ else httpx.Timeout(connect=15.0, read=5.0, write=5.0, pool=5.0),
150
+ follow_redirects=True,
151
+ limits=httpx.Limits(
152
+ max_connections=50,
153
+ max_keepalive_connections=50,
154
+ keepalive_expiry=120,
155
+ ),
156
+ ),
157
+ )
158
+ created_client = True
159
+
160
+ super().__init__(
161
+ model=model,
162
+ api_key=cerebras_api_key,
163
+ base_url=base_url,
164
+ client=client,
165
+ user=user,
166
+ temperature=temperature,
167
+ parallel_tool_calls=parallel_tool_calls,
168
+ tool_choice=tool_choice,
169
+ reasoning_effort=reasoning_effort,
170
+ safety_identifier=safety_identifier,
171
+ prompt_cache_key=prompt_cache_key,
172
+ top_p=top_p,
173
+ timeout=timeout,
174
+ max_retries=max_retries,
175
+ _strict_tool_schema=False,
176
+ )
177
+
178
+ if created_client:
179
+ self._owns_client = True
180
+
181
+
182
+ def _get_api_key(key: NotGivenOr[str]) -> str:
183
+ cerebras_api_key = key if is_given(key) else os.environ.get("CEREBRAS_API_KEY")
184
+ if not cerebras_api_key:
185
+ raise ValueError(
186
+ "CEREBRAS_API_KEY is required, either as argument or set "
187
+ "CEREBRAS_API_KEY environmental variable"
188
+ )
189
+ return cerebras_api_key
@@ -0,0 +1,3 @@
1
+ import logging
2
+
3
+ logger = logging.getLogger("livekit.plugins.cerebras")
@@ -0,0 +1,13 @@
1
+ from typing import Literal
2
+
3
+ CerebrasChatModels = Literal[
4
+ "llama3.1-8b",
5
+ "llama-3.3-70b",
6
+ "llama-4-scout-17b-16e-instruct",
7
+ "llama-4-maverick-17b-128e-instruct",
8
+ "qwen-3-32b",
9
+ "qwen-3-235b-a22b-instruct-2507",
10
+ "qwen-3-235b-a22b-thinking-2507",
11
+ "qwen-3-coder-480b",
12
+ "gpt-oss-120b",
13
+ ]
@@ -0,0 +1,15 @@
1
+ # Copyright 2026 LiveKit, Inc.
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.
14
+
15
+ __version__ = "1.5.3"
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "livekit-plugins-cerebras"
7
+ dynamic = ["version"]
8
+ description = "Cerebras inference plugin for LiveKit Agents"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.10.0"
12
+ authors = [{ name = "LiveKit", email = "hello@livekit.io" }]
13
+ keywords = ["voice", "ai", "realtime", "audio", "video", "livekit", "cerebras"]
14
+ classifiers = [
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: Apache Software License",
17
+ "Topic :: Multimedia :: Sound/Audio",
18
+ "Topic :: Multimedia :: Video",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3 :: Only",
23
+ ]
24
+ dependencies = [
25
+ "livekit-agents[codecs, openai]>=1.5.3",
26
+ "msgpack>=1.0",
27
+ "msgpack-types>=0.7.0",
28
+ ]
29
+
30
+ [project.urls]
31
+ Documentation = "https://docs.livekit.io"
32
+ Website = "https://livekit.io/"
33
+ Source = "https://github.com/livekit/agents"
34
+
35
+ [tool.hatch.version]
36
+ path = "livekit/plugins/cerebras/version.py"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["livekit"]
40
+
41
+ [tool.hatch.build.targets.sdist]
42
+ include = ["/livekit"]
43
+
44
+ [tool.uv]
45
+ exclude-newer = "7 days"
46
+ exclude-newer-package = { livekit = "0 days", livekit-agents = "0 days" }