Skip to content

ChatDatabricks() with Anthropic models doesn't work for structured data #94

@cpsievert

Description

@cpsievert
from chatlas import ChatDatabricks
from pydantic import BaseModel


class ArticleSummary(BaseModel):
    """Summary of the article"""

    title: str
    author: str


article = """
# Apples are tasty

By Hadley Wickham
Apples are delicious and tasty and I like to eat them.
Except for red delicious, that is. They are NOT delicious.
"""

chat = ChatDatabricks(model="databricks-claude-3-7-sonnet")
chat.extract_data(article, data_model=ArticleSummary)
Traceback (most recent call last):
  File "/Users/cpsievert/github/chatlas/sandbox/_databricks.py", line 21, in <module>
    chat.extract_data(article, data_model=ArticleSummary)
  File "/Users/cpsievert/github/chatlas/chatlas/_chat.py", line 829, in extract_data
    for _ in response:
  File "/Users/cpsievert/github/chatlas/chatlas/_chat.py", line 1581, in __next__
    chunk = next(self._generator)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cpsievert/github/chatlas/chatlas/_chat.py", line 1330, in _submit_turns
    response = self.provider.chat_perform(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cpsievert/github/chatlas/chatlas/_openai.py", line 238, in chat_perform
    return self._client.chat.completions.create(**kwargs)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cpsievert/github/chatlas/.venv/lib/python3.11/site-packages/openai/_utils/_utils.py", line 287, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cpsievert/github/chatlas/.venv/lib/python3.11/site-packages/openai/resources/chat/completions/completions.py", line 925, in create
    return self._post(
           ^^^^^^^^^^^
  File "/Users/cpsievert/github/chatlas/.venv/lib/python3.11/site-packages/openai/_base_client.py", line 1239, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cpsievert/github/chatlas/.venv/lib/python3.11/site-packages/openai/_base_client.py", line 1034, in request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error_code': 'BAD_REQUEST', 'message': '{"message":"response_format: Extra inputs are not permitted"}'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions