livekit-plugins-openai 1.0.0.dev2__tar.gz → 1.0.0.dev4__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.
- livekit_plugins_openai-1.0.0.dev4/.gitignore +168 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/PKG-INFO +12 -23
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/embeddings.py +1 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/llm.py +29 -37
- livekit_plugins_openai-1.0.0.dev4/livekit/plugins/openai/realtime/__init__.py +6 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/realtime/realtime_model.py +344 -114
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/tts.py +13 -15
- livekit_plugins_openai-1.0.0.dev4/livekit/plugins/openai/utils.py +114 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/version.py +1 -1
- livekit_plugins_openai-1.0.0.dev4/pyproject.toml +42 -0
- livekit_plugins_openai-1.0.0.dev2/livekit/plugins/openai/realtime/__init__.py +0 -9
- livekit_plugins_openai-1.0.0.dev2/livekit/plugins/openai/realtime/log.py +0 -3
- livekit_plugins_openai-1.0.0.dev2/livekit/plugins/openai/utils.py +0 -99
- livekit_plugins_openai-1.0.0.dev2/livekit_plugins_openai.egg-info/PKG-INFO +0 -62
- livekit_plugins_openai-1.0.0.dev2/livekit_plugins_openai.egg-info/SOURCES.txt +0 -21
- livekit_plugins_openai-1.0.0.dev2/livekit_plugins_openai.egg-info/dependency_links.txt +0 -1
- livekit_plugins_openai-1.0.0.dev2/livekit_plugins_openai.egg-info/requires.txt +0 -5
- livekit_plugins_openai-1.0.0.dev2/livekit_plugins_openai.egg-info/top_level.txt +0 -1
- livekit_plugins_openai-1.0.0.dev2/pyproject.toml +0 -3
- livekit_plugins_openai-1.0.0.dev2/setup.cfg +0 -4
- livekit_plugins_openai-1.0.0.dev2/setup.py +0 -63
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/README.md +0 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/__init__.py +0 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/log.py +0 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/models.py +0 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/py.typed +0 -0
- {livekit_plugins_openai-1.0.0.dev2 → livekit_plugins_openai-1.0.0.dev4}/livekit/plugins/openai/stt.py +2 -2
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
# Pyre type checker
|
|
150
|
+
.pyre/
|
|
151
|
+
|
|
152
|
+
# pytype static type analyzer
|
|
153
|
+
.pytype/
|
|
154
|
+
|
|
155
|
+
# Cython debug symbols
|
|
156
|
+
cython_debug/
|
|
157
|
+
|
|
158
|
+
# PyCharm
|
|
159
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
160
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
161
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
162
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
163
|
+
.idea/
|
|
164
|
+
|
|
165
|
+
node_modules
|
|
166
|
+
|
|
167
|
+
credentials.json
|
|
168
|
+
pyrightconfig.json
|
|
@@ -1,39 +1,28 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: livekit-plugins-openai
|
|
3
|
-
Version: 1.0.0.
|
|
3
|
+
Version: 1.0.0.dev4
|
|
4
4
|
Summary: Agent Framework plugin for services from OpenAI
|
|
5
|
-
Home-page: https://github.com/livekit/agents
|
|
6
|
-
License: Apache-2.0
|
|
7
5
|
Project-URL: Documentation, https://docs.livekit.io
|
|
8
6
|
Project-URL: Website, https://livekit.io/
|
|
9
7
|
Project-URL: Source, https://github.com/livekit/agents
|
|
10
|
-
|
|
8
|
+
Author-email: LiveKit <support@livekit.io>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Keywords: audio,livekit,realtime,video,webrtc
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
-
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
14
|
-
Classifier: Topic :: Multimedia :: Video
|
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.9
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
-
Classifier:
|
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
18
|
+
Classifier: Topic :: Multimedia :: Video
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
20
|
Requires-Python: >=3.9.0
|
|
21
|
-
|
|
22
|
-
Requires-Dist: livekit-agents[codecs,images]>=0.12.3
|
|
21
|
+
Requires-Dist: livekit-agents>=1.0.0.dev4
|
|
23
22
|
Requires-Dist: openai[realtime]>=1.65
|
|
24
23
|
Provides-Extra: vertex
|
|
25
|
-
Requires-Dist: google-auth>=2.0.0; extra ==
|
|
26
|
-
|
|
27
|
-
Dynamic: description
|
|
28
|
-
Dynamic: description-content-type
|
|
29
|
-
Dynamic: home-page
|
|
30
|
-
Dynamic: keywords
|
|
31
|
-
Dynamic: license
|
|
32
|
-
Dynamic: project-url
|
|
33
|
-
Dynamic: provides-extra
|
|
34
|
-
Dynamic: requires-dist
|
|
35
|
-
Dynamic: requires-python
|
|
36
|
-
Dynamic: summary
|
|
24
|
+
Requires-Dist: google-auth>=2.0.0; extra == 'vertex'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
37
26
|
|
|
38
27
|
# LiveKit Plugins OpenAI
|
|
39
28
|
|
|
@@ -17,18 +17,16 @@ from __future__ import annotations
|
|
|
17
17
|
|
|
18
18
|
import os
|
|
19
19
|
from dataclasses import dataclass
|
|
20
|
-
from typing import Any
|
|
20
|
+
from typing import Any
|
|
21
21
|
|
|
22
22
|
import httpx
|
|
23
|
-
from
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
llm,
|
|
28
|
-
)
|
|
23
|
+
from typing_extensions import Literal
|
|
24
|
+
|
|
25
|
+
import openai
|
|
26
|
+
from livekit.agents import APIConnectionError, APIStatusError, APITimeoutError, llm
|
|
29
27
|
from livekit.agents.llm import ToolChoice
|
|
30
28
|
from livekit.agents.llm.chat_context import ChatContext
|
|
31
|
-
from livekit.agents.llm.
|
|
29
|
+
from livekit.agents.llm.tool_context import FunctionTool
|
|
32
30
|
from livekit.agents.types import (
|
|
33
31
|
DEFAULT_API_CONNECT_OPTIONS,
|
|
34
32
|
NOT_GIVEN,
|
|
@@ -36,13 +34,7 @@ from livekit.agents.types import (
|
|
|
36
34
|
NotGivenOr,
|
|
37
35
|
)
|
|
38
36
|
from livekit.agents.utils import is_given
|
|
39
|
-
from
|
|
40
|
-
|
|
41
|
-
import openai
|
|
42
|
-
from openai.types.chat import (
|
|
43
|
-
ChatCompletionChunk,
|
|
44
|
-
ChatCompletionToolChoiceOptionParam,
|
|
45
|
-
)
|
|
37
|
+
from openai.types.chat import ChatCompletionChunk, ChatCompletionToolChoiceOptionParam
|
|
46
38
|
from openai.types.chat.chat_completion_chunk import Choice
|
|
47
39
|
|
|
48
40
|
from .models import (
|
|
@@ -65,7 +57,7 @@ class _LLMOptions:
|
|
|
65
57
|
user: NotGivenOr[str]
|
|
66
58
|
temperature: NotGivenOr[float]
|
|
67
59
|
parallel_tool_calls: NotGivenOr[bool]
|
|
68
|
-
tool_choice: NotGivenOr[
|
|
60
|
+
tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]]
|
|
69
61
|
store: NotGivenOr[bool]
|
|
70
62
|
metadata: NotGivenOr[dict[str, str]]
|
|
71
63
|
|
|
@@ -81,7 +73,7 @@ class LLM(llm.LLM):
|
|
|
81
73
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
82
74
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
83
75
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
84
|
-
tool_choice: NotGivenOr[
|
|
76
|
+
tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]] = NOT_GIVEN,
|
|
85
77
|
store: NotGivenOr[bool] = NOT_GIVEN,
|
|
86
78
|
metadata: NotGivenOr[dict[str, str]] = NOT_GIVEN,
|
|
87
79
|
) -> None:
|
|
@@ -132,7 +124,7 @@ class LLM(llm.LLM):
|
|
|
132
124
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
133
125
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
134
126
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
135
|
-
tool_choice: NotGivenOr[
|
|
127
|
+
tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]] = NOT_GIVEN,
|
|
136
128
|
) -> LLM:
|
|
137
129
|
"""
|
|
138
130
|
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
|
|
@@ -176,7 +168,7 @@ class LLM(llm.LLM):
|
|
|
176
168
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
177
169
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
178
170
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
179
|
-
tool_choice: NotGivenOr[
|
|
171
|
+
tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]] = NOT_GIVEN,
|
|
180
172
|
) -> LLM:
|
|
181
173
|
"""
|
|
182
174
|
Create a new instance of Cerebras LLM.
|
|
@@ -213,7 +205,7 @@ class LLM(llm.LLM):
|
|
|
213
205
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
214
206
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
215
207
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
216
|
-
tool_choice:
|
|
208
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
217
209
|
) -> LLM:
|
|
218
210
|
"""
|
|
219
211
|
Create a new instance of Fireworks LLM.
|
|
@@ -249,7 +241,7 @@ class LLM(llm.LLM):
|
|
|
249
241
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
250
242
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
251
243
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
252
|
-
tool_choice:
|
|
244
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
253
245
|
):
|
|
254
246
|
"""
|
|
255
247
|
Create a new instance of XAI LLM.
|
|
@@ -284,7 +276,7 @@ class LLM(llm.LLM):
|
|
|
284
276
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
285
277
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
286
278
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
287
|
-
tool_choice:
|
|
279
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
288
280
|
) -> LLM:
|
|
289
281
|
"""
|
|
290
282
|
Create a new instance of Groq LLM.
|
|
@@ -320,7 +312,7 @@ class LLM(llm.LLM):
|
|
|
320
312
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
321
313
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
322
314
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
323
|
-
tool_choice:
|
|
315
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
324
316
|
) -> LLM:
|
|
325
317
|
"""
|
|
326
318
|
Create a new instance of DeepSeek LLM.
|
|
@@ -356,7 +348,7 @@ class LLM(llm.LLM):
|
|
|
356
348
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
357
349
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
358
350
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
359
|
-
tool_choice:
|
|
351
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
360
352
|
) -> LLM:
|
|
361
353
|
"""
|
|
362
354
|
Create a new instance of OctoAI LLM.
|
|
@@ -390,7 +382,7 @@ class LLM(llm.LLM):
|
|
|
390
382
|
client: openai.AsyncClient | None = None,
|
|
391
383
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
392
384
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
393
|
-
tool_choice:
|
|
385
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
394
386
|
) -> LLM:
|
|
395
387
|
"""
|
|
396
388
|
Create a new instance of Ollama LLM.
|
|
@@ -416,7 +408,7 @@ class LLM(llm.LLM):
|
|
|
416
408
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
417
409
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
418
410
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
419
|
-
tool_choice:
|
|
411
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
420
412
|
) -> LLM:
|
|
421
413
|
"""
|
|
422
414
|
Create a new instance of PerplexityAI LLM.
|
|
@@ -452,7 +444,7 @@ class LLM(llm.LLM):
|
|
|
452
444
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
453
445
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
454
446
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
455
|
-
tool_choice:
|
|
447
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
456
448
|
) -> LLM:
|
|
457
449
|
"""
|
|
458
450
|
Create a new instance of TogetherAI LLM.
|
|
@@ -488,7 +480,7 @@ class LLM(llm.LLM):
|
|
|
488
480
|
user: NotGivenOr[str] = NOT_GIVEN,
|
|
489
481
|
temperature: NotGivenOr[float] = NOT_GIVEN,
|
|
490
482
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
491
|
-
tool_choice:
|
|
483
|
+
tool_choice: ToolChoice | Literal["auto", "required", "none"] = "auto",
|
|
492
484
|
) -> LLM:
|
|
493
485
|
"""
|
|
494
486
|
Create a new instance of Telnyx LLM.
|
|
@@ -518,12 +510,12 @@ class LLM(llm.LLM):
|
|
|
518
510
|
self,
|
|
519
511
|
*,
|
|
520
512
|
chat_ctx: ChatContext,
|
|
521
|
-
|
|
513
|
+
tools: list[FunctionTool] | None = None,
|
|
522
514
|
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
|
|
523
515
|
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
|
|
524
|
-
tool_choice: NotGivenOr[
|
|
516
|
+
tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]] = NOT_GIVEN,
|
|
525
517
|
extra_kwargs: NotGivenOr[dict[str, Any]] = NOT_GIVEN,
|
|
526
|
-
) ->
|
|
518
|
+
) -> LLMStream:
|
|
527
519
|
extra = {}
|
|
528
520
|
|
|
529
521
|
if is_given(extra_kwargs):
|
|
@@ -559,9 +551,9 @@ class LLM(llm.LLM):
|
|
|
559
551
|
model=self._opts.model,
|
|
560
552
|
client=self._client,
|
|
561
553
|
chat_ctx=chat_ctx,
|
|
562
|
-
|
|
554
|
+
tools=tools or [],
|
|
563
555
|
conn_options=conn_options,
|
|
564
|
-
|
|
556
|
+
extra_kwargs=extra,
|
|
565
557
|
)
|
|
566
558
|
|
|
567
559
|
|
|
@@ -573,11 +565,11 @@ class LLMStream(llm.LLMStream):
|
|
|
573
565
|
model: str | ChatModels,
|
|
574
566
|
client: openai.AsyncClient,
|
|
575
567
|
chat_ctx: llm.ChatContext,
|
|
576
|
-
|
|
568
|
+
tools: list[FunctionTool],
|
|
577
569
|
conn_options: APIConnectOptions,
|
|
578
|
-
extra_kwargs: dict[str, Any]
|
|
570
|
+
extra_kwargs: dict[str, Any],
|
|
579
571
|
) -> None:
|
|
580
|
-
super().__init__(llm, chat_ctx=chat_ctx,
|
|
572
|
+
super().__init__(llm, chat_ctx=chat_ctx, tools=tools, conn_options=conn_options)
|
|
581
573
|
self._model = model
|
|
582
574
|
self._client = client
|
|
583
575
|
self._llm = llm
|
|
@@ -598,7 +590,7 @@ class LLMStream(llm.LLMStream):
|
|
|
598
590
|
ChatCompletionChunk
|
|
599
591
|
] = await self._client.chat.completions.create(
|
|
600
592
|
messages=to_chat_ctx(self._chat_ctx, id(self._llm)),
|
|
601
|
-
tools=to_fnc_ctx(self.
|
|
593
|
+
tools=to_fnc_ctx(self._tools) if self._tools else openai.NOT_GIVEN,
|
|
602
594
|
model=self._model,
|
|
603
595
|
stream_options={"include_usage": True},
|
|
604
596
|
stream=True,
|