livekit-plugins-anthropic 1.0.0rc3__py3-none-any.whl → 1.0.0rc5__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.
@@ -44,7 +44,7 @@ class _LLMOptions:
44
44
  user: NotGivenOr[str]
45
45
  temperature: NotGivenOr[float]
46
46
  parallel_tool_calls: NotGivenOr[bool]
47
- tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]]
47
+ tool_choice: NotGivenOr[ToolChoice]
48
48
  caching: NotGivenOr[Literal["ephemeral"]]
49
49
  top_k: NotGivenOr[int]
50
50
  max_tokens: NotGivenOr[int]
@@ -64,7 +64,7 @@ class LLM(llm.LLM):
64
64
  max_tokens: NotGivenOr[int] = NOT_GIVEN,
65
65
  temperature: NotGivenOr[float] = NOT_GIVEN,
66
66
  parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
67
- tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]] = NOT_GIVEN,
67
+ tool_choice: NotGivenOr[ToolChoice] = NOT_GIVEN,
68
68
  caching: NotGivenOr[Literal["ephemeral"]] = NOT_GIVEN,
69
69
  ) -> None:
70
70
  """
@@ -74,14 +74,14 @@ class LLM(llm.LLM):
74
74
  the ``ANTHROPIC_API_KEY`` environmental variable.
75
75
 
76
76
  model (str | ChatModels): The model to use. Defaults to "claude-3-5-sonnet-20241022".
77
- api_key (str | None): The Anthropic API key. Defaults to the ANTHROPIC_API_KEY environment variable.
78
- base_url (str | None): The base URL for the Anthropic API. Defaults to None.
79
- user (str | None): The user for the Anthropic API. Defaults to None.
77
+ api_key (str, optional): The Anthropic API key. Defaults to the ANTHROPIC_API_KEY environment variable.
78
+ base_url (str, optional): The base URL for the Anthropic API. Defaults to None.
79
+ user (str, optional): The user for the Anthropic API. Defaults to None.
80
80
  client (anthropic.AsyncClient | None): The Anthropic client to use. Defaults to None.
81
- temperature (float | None): The temperature for the Anthropic API. Defaults to None.
82
- parallel_tool_calls (bool | None): Whether to parallelize tool calls. Defaults to None.
83
- tool_choice (Union[ToolChoice, Literal["auto", "required", "none"]] | None): The tool choice for the Anthropic API. Defaults to "auto".
84
- caching (Literal["ephemeral"] | None): If set to "ephemeral", caching will be enabled for the system prompt, tools, and chat history.
81
+ temperature (float, optional): The temperature for the Anthropic API. Defaults to None.
82
+ parallel_tool_calls (bool, optional): Whether to parallelize tool calls. Defaults to None.
83
+ tool_choice (ToolChoice, optional): The tool choice for the Anthropic API. Defaults to "auto".
84
+ caching (Literal["ephemeral"], optional): If set to "ephemeral", caching will be enabled for the system prompt, tools, and chat history.
85
85
  """ # noqa: E501
86
86
 
87
87
  super().__init__()
@@ -121,7 +121,7 @@ class LLM(llm.LLM):
121
121
  tools: list[FunctionTool] | None = None,
122
122
  conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
123
123
  parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
124
- tool_choice: NotGivenOr[ToolChoice | Literal["auto", "required", "none"]] = NOT_GIVEN,
124
+ tool_choice: NotGivenOr[ToolChoice] = NOT_GIVEN,
125
125
  extra_kwargs: NotGivenOr[dict[str, Any]] = NOT_GIVEN,
126
126
  ) -> LLMStream:
127
127
  extra = {}
@@ -145,12 +145,11 @@ class LLM(llm.LLM):
145
145
  tool_choice = tool_choice if is_given(tool_choice) else self._opts.tool_choice
146
146
  if is_given(tool_choice):
147
147
  anthropic_tool_choice: dict[str, Any] | None = {"type": "auto"}
148
- if isinstance(tool_choice, ToolChoice):
149
- if tool_choice.type == "function":
150
- anthropic_tool_choice = {
151
- "type": "tool",
152
- "name": tool_choice.name,
153
- }
148
+ if isinstance(tool_choice, dict) and tool_choice.get("type") == "function":
149
+ anthropic_tool_choice = {
150
+ "type": "tool",
151
+ "name": tool_choice["function"]["name"],
152
+ }
154
153
  elif isinstance(tool_choice, str):
155
154
  if tool_choice == "required":
156
155
  anthropic_tool_choice = {"type": "any"}
@@ -36,7 +36,7 @@ def to_chat_ctx(
36
36
  for i, msg in enumerate(chat_ctx.items):
37
37
  if msg.type == "message" and msg.role == "system":
38
38
  for content in msg.content:
39
- if isinstance(content, str):
39
+ if content and isinstance(content, str):
40
40
  system_message = anthropic.types.TextBlockParam(
41
41
  text=content,
42
42
  type="text",
@@ -64,7 +64,7 @@ def to_chat_ctx(
64
64
 
65
65
  if msg.type == "message":
66
66
  for c in msg.content:
67
- if isinstance(c, str):
67
+ if c and isinstance(c, str):
68
68
  content.append(
69
69
  anthropic.types.TextBlockParam(
70
70
  text=c, type="text", cache_control=cache_ctrl
@@ -114,6 +114,12 @@ def _to_image_content(
114
114
  cache_ctrl: anthropic.types.CacheControlEphemeralParam | None,
115
115
  ) -> anthropic.types.ImageBlockParam:
116
116
  img = llm.utils.serialize_image(image)
117
+ if img.external_url:
118
+ return {
119
+ "type": "image",
120
+ "source": {"type": "url", "url": img.external_url},
121
+ "cache_control": cache_ctrl,
122
+ }
117
123
  if cache_key not in image._cache:
118
124
  image._cache[cache_key] = img.data_bytes
119
125
  b64_data = base64.b64encode(image._cache[cache_key]).decode("utf-8")
@@ -121,8 +127,8 @@ def _to_image_content(
121
127
  "type": "image",
122
128
  "source": {
123
129
  "type": "base64",
124
- "data": f"data:{img.media_type};base64,{b64_data}",
125
- "media_type": img.media_type,
130
+ "data": f"data:{img.mime_type};base64,{b64_data}",
131
+ "media_type": img.mime_type,
126
132
  },
127
133
  "cache_control": cache_ctrl,
128
134
  }
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = '1.0.0.rc3'
15
+ __version__ = '1.0.0.rc5'
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: livekit-plugins-anthropic
3
- Version: 1.0.0rc3
3
+ Version: 1.0.0rc5
4
4
  Summary: Agent Framework plugin for services from Anthropic
5
5
  Project-URL: Documentation, https://docs.livekit.io
6
6
  Project-URL: Website, https://livekit.io/
7
7
  Project-URL: Source, https://github.com/livekit/agents
8
- Author-email: LiveKit <support@livekit.io>
8
+ Author-email: LiveKit <hello@livekit.io>
9
9
  License-Expression: Apache-2.0
10
10
  Keywords: audio,livekit,realtime,video,webrtc
11
11
  Classifier: Intended Audience :: Developers
@@ -19,7 +19,7 @@ Classifier: Topic :: Multimedia :: Video
19
19
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
20
  Requires-Python: >=3.9.0
21
21
  Requires-Dist: anthropic>=0.34
22
- Requires-Dist: livekit-agents>=1.0.0.rc3
22
+ Requires-Dist: livekit-agents>=1.0.0.rc5
23
23
  Description-Content-Type: text/markdown
24
24
 
25
25
  # LiveKit Plugins Anthropic
@@ -0,0 +1,10 @@
1
+ livekit/plugins/anthropic/__init__.py,sha256=1WCyNEaR6qBsX54qJQM0SeY-QHIucww16PLXcSnMqRo,1175
2
+ livekit/plugins/anthropic/llm.py,sha256=0O0ed5GZsTrEy_tWgrVadbA9IaEZfBm-oKjicT69l34,12885
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/utils.py,sha256=Nfl9dGCZGDEJAHj_f-TmePr8bKJrc8IwM6Houjev4DE,5158
7
+ livekit/plugins/anthropic/version.py,sha256=G8-S67mIdz56XcVImzUB7osx6o_lG2oShZz-PjWeOeo,604
8
+ livekit_plugins_anthropic-1.0.0rc5.dist-info/METADATA,sha256=r60nMSf-kbpQGphqIZvfu5wFWJMxAarij8wqeBMjjbM,1278
9
+ livekit_plugins_anthropic-1.0.0rc5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ livekit_plugins_anthropic-1.0.0rc5.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- livekit/plugins/anthropic/__init__.py,sha256=1WCyNEaR6qBsX54qJQM0SeY-QHIucww16PLXcSnMqRo,1175
2
- livekit/plugins/anthropic/llm.py,sha256=Gj9oGm16kdeEHw1I4GB7EGSBLpgkzhv36f55Msby5o0,13042
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/utils.py,sha256=SgF7No3XxiF62zt_ija9scqqOUkuB51Yxpe9X2QTuf8,4956
7
- livekit/plugins/anthropic/version.py,sha256=wYcaYw0AmH9qt8_atfIwl-Qo0WMWL73z2vqRF8LOjms,604
8
- livekit_plugins_anthropic-1.0.0rc3.dist-info/METADATA,sha256=lADiAACTnZZ5pKVe9FF8wbIqmZ7EcJ-F4sYbrnYx2Kg,1280
9
- livekit_plugins_anthropic-1.0.0rc3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- livekit_plugins_anthropic-1.0.0rc3.dist-info/RECORD,,