AnswerDotAI / fasthtml-example

Example fasthtml applications demonstrating a range of web programming techniques
Apache License 2.0
640 stars 98 forks source link

Fix messages handling in send function to prevent API errors #35

Closed gnoparus closed 2 months ago

gnoparus commented 2 months ago

This PR fixes a bug in the send function related to improper handling of the messages list, which led to a BadRequestError from the Anthropics API. The error message highlighted that text content blocks must contain non-whitespace text, which could happen if messages contained non-string objects or strings with only whitespace.

anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: text content blocks must contain non-whitespace text'}}