livekit-plugins-anthropic 0.2.4__py3-none-any.whl → 0.2.6__py3-none-any.whl
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/anthropic/llm.py +55 -9
- livekit/plugins/anthropic/models.py +1 -0
- livekit/plugins/anthropic/version.py +1 -1
- {livekit_plugins_anthropic-0.2.4.dist-info → livekit_plugins_anthropic-0.2.6.dist-info}/METADATA +3 -3
- livekit_plugins_anthropic-0.2.6.dist-info/RECORD +10 -0
- {livekit_plugins_anthropic-0.2.4.dist-info → livekit_plugins_anthropic-0.2.6.dist-info}/WHEEL +1 -1
- livekit_plugins_anthropic-0.2.4.dist-info/RECORD +0 -10
- {livekit_plugins_anthropic-0.2.4.dist-info → livekit_plugins_anthropic-0.2.6.dist-info}/top_level.txt +0 -0
livekit/plugins/anthropic/llm.py
CHANGED
@@ -19,7 +19,16 @@ import inspect
|
|
19
19
|
import json
|
20
20
|
import os
|
21
21
|
from dataclasses import dataclass
|
22
|
-
from typing import
|
22
|
+
from typing import (
|
23
|
+
Any,
|
24
|
+
Awaitable,
|
25
|
+
List,
|
26
|
+
Literal,
|
27
|
+
Tuple,
|
28
|
+
Union,
|
29
|
+
get_args,
|
30
|
+
get_origin,
|
31
|
+
)
|
23
32
|
|
24
33
|
import httpx
|
25
34
|
from livekit import rtc
|
@@ -30,6 +39,8 @@ from livekit.agents import (
|
|
30
39
|
llm,
|
31
40
|
utils,
|
32
41
|
)
|
42
|
+
from livekit.agents.llm import ToolChoice
|
43
|
+
from livekit.agents.types import DEFAULT_API_CONNECT_OPTIONS, APIConnectOptions
|
33
44
|
|
34
45
|
import anthropic
|
35
46
|
|
@@ -44,18 +55,22 @@ class LLMOptions:
|
|
44
55
|
model: str | ChatModels
|
45
56
|
user: str | None
|
46
57
|
temperature: float | None
|
58
|
+
parallel_tool_calls: bool | None
|
59
|
+
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] | None
|
47
60
|
|
48
61
|
|
49
62
|
class LLM(llm.LLM):
|
50
63
|
def __init__(
|
51
64
|
self,
|
52
65
|
*,
|
53
|
-
model: str | ChatModels = "claude-3-
|
66
|
+
model: str | ChatModels = "claude-3-5-sonnet-20241022",
|
54
67
|
api_key: str | None = None,
|
55
68
|
base_url: str | None = None,
|
56
69
|
user: str | None = None,
|
57
70
|
client: anthropic.AsyncClient | None = None,
|
58
71
|
temperature: float | None = None,
|
72
|
+
parallel_tool_calls: bool | None = None,
|
73
|
+
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = "auto",
|
59
74
|
) -> None:
|
60
75
|
"""
|
61
76
|
Create a new instance of Anthropic LLM.
|
@@ -70,7 +85,13 @@ class LLM(llm.LLM):
|
|
70
85
|
if api_key is None:
|
71
86
|
raise ValueError("Anthropic API key is required")
|
72
87
|
|
73
|
-
self._opts = LLMOptions(
|
88
|
+
self._opts = LLMOptions(
|
89
|
+
model=model,
|
90
|
+
user=user,
|
91
|
+
temperature=temperature,
|
92
|
+
parallel_tool_calls=parallel_tool_calls,
|
93
|
+
tool_choice=tool_choice,
|
94
|
+
)
|
74
95
|
self._client = client or anthropic.AsyncClient(
|
75
96
|
api_key=api_key,
|
76
97
|
base_url=base_url,
|
@@ -89,13 +110,20 @@ class LLM(llm.LLM):
|
|
89
110
|
self,
|
90
111
|
*,
|
91
112
|
chat_ctx: llm.ChatContext,
|
113
|
+
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
|
92
114
|
fnc_ctx: llm.FunctionContext | None = None,
|
93
115
|
temperature: float | None = None,
|
94
116
|
n: int | None = 1,
|
95
117
|
parallel_tool_calls: bool | None = None,
|
118
|
+
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]]
|
119
|
+
| None = None,
|
96
120
|
) -> "LLMStream":
|
97
121
|
if temperature is None:
|
98
122
|
temperature = self._opts.temperature
|
123
|
+
if parallel_tool_calls is None:
|
124
|
+
parallel_tool_calls = self._opts.parallel_tool_calls
|
125
|
+
if tool_choice is None:
|
126
|
+
tool_choice = self._opts.tool_choice
|
99
127
|
|
100
128
|
opts: dict[str, Any] = dict()
|
101
129
|
if fnc_ctx and len(fnc_ctx.ai_functions) > 0:
|
@@ -104,9 +132,20 @@ class LLM(llm.LLM):
|
|
104
132
|
fncs_desc.append(_build_function_description(fnc))
|
105
133
|
|
106
134
|
opts["tools"] = fncs_desc
|
107
|
-
|
108
|
-
|
109
|
-
|
135
|
+
if tool_choice is not None:
|
136
|
+
anthropic_tool_choice: dict[str, Any] = {"type": "auto"}
|
137
|
+
if isinstance(tool_choice, ToolChoice):
|
138
|
+
if tool_choice.type == "function":
|
139
|
+
anthropic_tool_choice = {
|
140
|
+
"type": "tool",
|
141
|
+
"name": tool_choice.name,
|
142
|
+
}
|
143
|
+
elif isinstance(tool_choice, str):
|
144
|
+
if tool_choice == "required":
|
145
|
+
anthropic_tool_choice = {"type": "any"}
|
146
|
+
if parallel_tool_calls is not None and parallel_tool_calls is False:
|
147
|
+
anthropic_tool_choice["disable_parallel_tool_use"] = True
|
148
|
+
opts["tool_choice"] = anthropic_tool_choice
|
110
149
|
|
111
150
|
latest_system_message = _latest_system_message(chat_ctx)
|
112
151
|
anthropic_ctx = _build_anthropic_context(chat_ctx.messages, id(self))
|
@@ -124,7 +163,11 @@ class LLM(llm.LLM):
|
|
124
163
|
)
|
125
164
|
|
126
165
|
return LLMStream(
|
127
|
-
self,
|
166
|
+
self,
|
167
|
+
anthropic_stream=stream,
|
168
|
+
chat_ctx=chat_ctx,
|
169
|
+
fnc_ctx=fnc_ctx,
|
170
|
+
conn_options=conn_options,
|
128
171
|
)
|
129
172
|
|
130
173
|
|
@@ -138,8 +181,11 @@ class LLMStream(llm.LLMStream):
|
|
138
181
|
],
|
139
182
|
chat_ctx: llm.ChatContext,
|
140
183
|
fnc_ctx: llm.FunctionContext | None,
|
184
|
+
conn_options: APIConnectOptions,
|
141
185
|
) -> None:
|
142
|
-
super().__init__(
|
186
|
+
super().__init__(
|
187
|
+
llm, chat_ctx=chat_ctx, fnc_ctx=fnc_ctx, conn_options=conn_options
|
188
|
+
)
|
143
189
|
self._awaitable_anthropic_stream = anthropic_stream
|
144
190
|
self._anthropic_stream: (
|
145
191
|
anthropic.AsyncStream[anthropic.types.RawMessageStreamEvent] | None
|
@@ -155,7 +201,7 @@ class LLMStream(llm.LLMStream):
|
|
155
201
|
self._input_tokens = 0
|
156
202
|
self._output_tokens = 0
|
157
203
|
|
158
|
-
async def
|
204
|
+
async def _run(self) -> None:
|
159
205
|
try:
|
160
206
|
if not self._anthropic_stream:
|
161
207
|
self._anthropic_stream = await self._awaitable_anthropic_stream
|
{livekit_plugins_anthropic-0.2.4.dist-info → livekit_plugins_anthropic-0.2.6.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: livekit-plugins-anthropic
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.6
|
4
4
|
Summary: Agent Framework plugin for services from Anthropic
|
5
5
|
Home-page: https://github.com/livekit/agents
|
6
6
|
License: Apache-2.0
|
@@ -19,8 +19,8 @@ Classifier: Programming Language :: Python :: 3.10
|
|
19
19
|
Classifier: Programming Language :: Python :: 3 :: Only
|
20
20
|
Requires-Python: >=3.9.0
|
21
21
|
Description-Content-Type: text/markdown
|
22
|
-
Requires-Dist: livekit-agents
|
23
|
-
Requires-Dist: anthropic
|
22
|
+
Requires-Dist: livekit-agents>=0.11
|
23
|
+
Requires-Dist: anthropic>=0.34
|
24
24
|
|
25
25
|
# LiveKit Plugins Anthropic
|
26
26
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
livekit/plugins/anthropic/__init__.py,sha256=1WCyNEaR6qBsX54qJQM0SeY-QHIucww16PLXcSnMqRo,1175
|
2
|
+
livekit/plugins/anthropic/llm.py,sha256=Qz8POfM4A4Z-MuwcNoD9uJt8lpNi0SvatJvNtqls5p4,20650
|
3
|
+
livekit/plugins/anthropic/log.py,sha256=fG1pYSY88AnT738gZrmzF9FO4l4BdGENj3VKHMQB3Yo,72
|
4
|
+
livekit/plugins/anthropic/models.py,sha256=wyTr2nl6SL4ylN6s4mHJcqtmgV2mjJysZo89FknWdhI,213
|
5
|
+
livekit/plugins/anthropic/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
livekit/plugins/anthropic/version.py,sha256=qiU8NmY5thT_I47ndTlA5TMw4pNi5-r9qqSsLmz-9ps,600
|
7
|
+
livekit_plugins_anthropic-0.2.6.dist-info/METADATA,sha256=7v72icRCffOPETvp3GbhrJXKRO2yZG7O1eU3OpCeGnM,1263
|
8
|
+
livekit_plugins_anthropic-0.2.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
9
|
+
livekit_plugins_anthropic-0.2.6.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
|
10
|
+
livekit_plugins_anthropic-0.2.6.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
livekit/plugins/anthropic/__init__.py,sha256=1WCyNEaR6qBsX54qJQM0SeY-QHIucww16PLXcSnMqRo,1175
|
2
|
-
livekit/plugins/anthropic/llm.py,sha256=6rNtLJOfvB72gmmkFk8qN-N8fKnm-vhflpiBKTU_gqM,18921
|
3
|
-
livekit/plugins/anthropic/log.py,sha256=fG1pYSY88AnT738gZrmzF9FO4l4BdGENj3VKHMQB3Yo,72
|
4
|
-
livekit/plugins/anthropic/models.py,sha256=AVEhrEtKfWxsd-R03u7R74hcKjJq4oDVSTukvoPQGb0,179
|
5
|
-
livekit/plugins/anthropic/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
livekit/plugins/anthropic/version.py,sha256=tN8tlqGAXIPQnY08orbN5nkR9arbRiBxsZ9tNAY4f-A,600
|
7
|
-
livekit_plugins_anthropic-0.2.4.dist-info/METADATA,sha256=BchNIDgmsoEiEI-A9Rvu0U0tVlM7atZl39oXp1W6BzQ,1265
|
8
|
-
livekit_plugins_anthropic-0.2.4.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
9
|
-
livekit_plugins_anthropic-0.2.4.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
|
10
|
-
livekit_plugins_anthropic-0.2.4.dist-info/RECORD,,
|
File without changes
|