Skip to content

ChatDatabricks() chokes on empty responses with Anthropic models #93

Closed
@cpsievert

Description

@cpsievert

Related to #86

from chatlas import ChatDatabricks

chat = ChatDatabricks(model="databricks-claude-3-7-sonnet")
chat.chat("Respond with only two blank lines")
chat.chat("What's 1+1? Just give me the number")
Traceback (most recent call last):
  File "/Users/cpsievert/github/chatlas/sandbox/_databricks.py", line 5, in <module>
    resp = chat.chat("What's 1+1? Just give me the number")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cpsievert/github/chatlas/chatlas/_chat.py", line 575, in chat
    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 1195, in _chat_impl
    for chunk in self._submit_turns(
  File "/Users/cpsievert/github/chatlas/chatlas/_chat.py", line 1305, 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': 'messages: text content blocks must contain non-whitespace text'}

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