chatlas 0.6.1__py3-none-any.whl → 0.7.1__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.

Potentially problematic release.


This version of chatlas might be problematic. Click here for more details.

chatlas/__init__.py CHANGED
@@ -2,8 +2,10 @@ from . import types
2
2
  from ._anthropic import ChatAnthropic, ChatBedrockAnthropic
3
3
  from ._auto import ChatAuto
4
4
  from ._chat import Chat
5
+ from ._content import ContentToolRequest, ContentToolResult
5
6
  from ._content_image import content_image_file, content_image_plot, content_image_url
6
7
  from ._content_pdf import content_pdf_file, content_pdf_url
8
+ from ._databricks import ChatDatabricks
7
9
  from ._github import ChatGithub
8
10
  from ._google import ChatGoogle, ChatVertex
9
11
  from ._groq import ChatGroq
@@ -26,6 +28,7 @@ __all__ = (
26
28
  "ChatAnthropic",
27
29
  "ChatAuto",
28
30
  "ChatBedrockAnthropic",
31
+ "ChatDatabricks",
29
32
  "ChatGithub",
30
33
  "ChatGoogle",
31
34
  "ChatGroq",
@@ -41,6 +44,8 @@ __all__ = (
41
44
  "content_image_url",
42
45
  "content_pdf_file",
43
46
  "content_pdf_url",
47
+ "ContentToolRequest",
48
+ "ContentToolResult",
44
49
  "interpolate",
45
50
  "interpolate_file",
46
51
  "Provider",
chatlas/_anthropic.py CHANGED
@@ -1,10 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import base64
4
- import json
5
4
  import warnings
6
5
  from typing import TYPE_CHECKING, Any, Literal, Optional, Union, cast, overload
7
6
 
7
+ import orjson
8
8
  from pydantic import BaseModel
9
9
 
10
10
  from ._chat import Chat
@@ -366,8 +366,8 @@ class AnthropicProvider(Provider[Message, RawMessageStreamEvent, Message]):
366
366
  this_content = completion.content[chunk.index]
367
367
  if this_content.type == "tool_use" and isinstance(this_content.input, str):
368
368
  try:
369
- this_content.input = json.loads(this_content.input or "{}")
370
- except json.JSONDecodeError as e:
369
+ this_content.input = orjson.loads(this_content.input or "{}")
370
+ except orjson.JSONDecodeError as e:
371
371
  raise ValueError(f"Invalid JSON input: {e}")
372
372
  elif chunk.type == "message_delta":
373
373
  completion.stop_reason = chunk.delta.stop_reason
@@ -451,7 +451,10 @@ class AnthropicProvider(Provider[Message, RawMessageStreamEvent, Message]):
451
451
  @staticmethod
452
452
  def _as_content_block(content: Content) -> "ContentBlockParam":
453
453
  if isinstance(content, ContentText):
454
- return {"text": content.text, "type": "text"}
454
+ text = content.text
455
+ if text == "" or text.isspace():
456
+ text = "[empty string]"
457
+ return {"type": "text", "text": text}
455
458
  elif isinstance(content, ContentJson):
456
459
  return {"text": "<structured data/>", "type": "text"}
457
460
  elif isinstance(content, ContentPDF):
@@ -485,12 +488,15 @@ class AnthropicProvider(Provider[Message, RawMessageStreamEvent, Message]):
485
488
  "input": content.arguments,
486
489
  }
487
490
  elif isinstance(content, ContentToolResult):
488
- return {
491
+ res: ToolResultBlockParam = {
489
492
  "type": "tool_result",
490
493
  "tool_use_id": content.id,
491
- "content": content.get_final_value(),
492
494
  "is_error": content.error is not None,
493
495
  }
496
+ # Anthropic supports non-text contents like ImageBlockParam
497
+ res["content"] = content.get_model_value() # type: ignore
498
+ return res
499
+
494
500
  raise ValueError(f"Unknown content type: {type(content)}")
495
501
 
496
502
  @staticmethod
chatlas/_auto.py CHANGED
@@ -1,11 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
- import json
4
3
  import os
5
4
  from typing import Callable, Literal, Optional
6
5
 
6
+ import orjson
7
+
7
8
  from ._anthropic import ChatAnthropic, ChatBedrockAnthropic
8
9
  from ._chat import Chat
10
+ from ._databricks import ChatDatabricks
9
11
  from ._github import ChatGithub
10
12
  from ._google import ChatGoogle, ChatVertex
11
13
  from ._groq import ChatGroq
@@ -18,6 +20,7 @@ from ._turn import Turn
18
20
  AutoProviders = Literal[
19
21
  "anthropic",
20
22
  "bedrock-anthropic",
23
+ "databricks",
21
24
  "github",
22
25
  "google",
23
26
  "groq",
@@ -32,6 +35,7 @@ AutoProviders = Literal[
32
35
  _provider_chat_model_map: dict[AutoProviders, Callable[..., Chat]] = {
33
36
  "anthropic": ChatAnthropic,
34
37
  "bedrock-anthropic": ChatBedrockAnthropic,
38
+ "databricks": ChatDatabricks,
35
39
  "github": ChatGithub,
36
40
  "google": ChatGoogle,
37
41
  "groq": ChatGroq,
@@ -55,7 +59,7 @@ def ChatAuto(
55
59
  """
56
60
  Use environment variables (env vars) to configure the Chat provider and model.
57
61
 
58
- Creates a `:class:~chatlas.Chat` instance based on the specified provider.
62
+ Creates a :class:`~chatlas.Chat` instance based on the specified provider.
59
63
  The provider may be specified through the `provider` parameter and/or the
60
64
  `CHATLAS_CHAT_PROVIDER` env var. If both are set, the env var takes
61
65
  precedence. Similarly, the provider's model may be specified through the
@@ -175,7 +179,7 @@ def ChatAuto(
175
179
 
176
180
  env_kwargs = {}
177
181
  if env_kwargs_str := os.environ.get("CHATLAS_CHAT_ARGS"):
178
- env_kwargs = json.loads(env_kwargs_str)
182
+ env_kwargs = orjson.loads(env_kwargs_str)
179
183
 
180
184
  kwargs = {**kwargs, **env_kwargs, **base_args}
181
185
  kwargs = {k: v for k, v in kwargs.items() if v is not None}