-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
claude sonnet latest: "all messages must have non-empty content except for the optional final assistant message" #10
Comments
Aha, it also works reliably with |
Very nice, thanks for sharing! I'll eventually have a look into, but in the meantime you can utilize the new |
Great! I'll try to use In the meantime, I hope the hint to try earlier sonnet is helpful to anyone who hits this error. Older sonnet is good enough for my development purposes, no complaints here. Thanks so much for chatlas! |
I solved this by upgrading to anthropic 0.42. |
Actually, using the latest anthropic package does not fix the error. I think that the error arises when Claude's response ends with a tool call and no chat after it. This causes a message to be put in history with Currently I'll return to this if Claude gets terse again. |
The error is a bit more clear with anthropic 0.42
I get the error consistently with streaming enabled and with a system prompt to submit answers as Quarto documents using the tool I register. In this circumstance Claude will usually chat something and then submit a Quarto document and not chat further. Sometimes it shows a spinner as if it's waiting for more response, but it is done. When I ask a follow-up question, it will crash. In this case it seems chatlas or I have made a stupid patch which solves the issue for me. As noted, it's overkill, but I do see it removing as many as 7 messages with empty content. diff --git a/chatlas/_anthropic.py b/chatlas/_anthropic.py
index 9d7d0e9..56d6fa7 100644
--- a/chatlas/_anthropic.py
+++ b/chatlas/_anthropic.py
@@ -241,6 +241,14 @@ class AnthropicProvider(Provider[Message, RawMessageStreamEvent, Message]):
kwargs: Optional["SubmitInputArgs"] = None,
):
kwargs = self._chat_perform_args(stream, turns, tools, data_model, kwargs)
+ messages = kwargs['messages']
+ if messages:
+ # this is overkill as it will remove the one allowed empty content at the end
+ # "all messages must have non-empty content except for the optional final assistant message"
+ no_empties = [m for m in messages if len(m['content']) != 0]
+ if len(no_empties) != len(messages):
+ print(f'averting sending {len(messages) - len(no_empties)} message(s) with empty content')
+ kwargs['messages'] = no_empties
return self._client.messages.create(**kwargs) # type: ignore I'd be glad to submit a repro but it won't be trivial since it involves both streaming and tool calling. |
claude-3-5-sonnet-latest
Hi Carson!
Thanks to chatlas, I have my quarto chatbot working on both anthropic and openai! ✨
https://github.com/gordonwoodhull/quarto-data-science-chatbot/
It took less than an hour to port from the
openapi
python library, and the output toolshow_answer
is connected much more reliably.Chatlas also multiplexes the streaming chat and sending the documents via the tool very nicely!
I find that with
anthropic claude-3-opus-20240229
my chatbot works reliably but it is very chatty. If I switch toclaude-3-5-sonnet-latest
withIt seems both speedier and more to-the-point, but when I ask it to revise its answer, my second input, it crashes with
Typical conversation:
please draw a heatmap of synthetic randomized hourly temperatures for a place that's in the 70s in the afternoon and gets down to 40 at night, using ggplot2 (or altair, or plotnine, etc.)
yeah that's great but please put the days in x and the hours in y and nights should be colder than days (or whatever silly thing it got wrong)
My chatbot crashes consistently on step 2 with sonnet, but works reliably with opus and with openai gpt-4o. I haven't tested others yet.
Here is the full stack trace:
The text was updated successfully, but these errors were encountered: