You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use claudette with Claude 3.5 Sonnet via Bedrock and I run into this error:
chat("Which football team is known as the Lionesses?")
> TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Here's a reprex to reproduce the error.
importboto3fromanthropicimportAnthropicBedrockfromclaudetteimportChat, Clientsession=boto3.Session(profile_name="claudette")
credentials=session.get_credentials()
# Claude 3.5 Sonnet on Bedrock with cross-region inferencemodel="us.anthropic.claude-3-5-sonnet-20241022-v2:0"ab=AnthropicBedrock(
aws_access_key=credentials.access_key,
aws_secret_key=credentials.secret_key,
aws_region="us-west-2",
)
cli=Client(model, cli=ab)
chat=Chat(model, cli=cli, sp="""You are a helpful and concise assistant.""")
chat("Which football team is known as the Lionesses?")
# > return usage(self.input_tokens+b.input_tokens, self.output_tokens+b.output_tokens, getattr(self,'cache_creation_input_tokens',0)+getattr(b,'cache_creation_input_tokens',0), getattr(self,'cache_read_input_tokens',0)+getattr(b,'cache_read_input_tokens',0))# ># > TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Here's the requirements.txt. I install these packages in a new environment.
(Unless I'm doing something wrong) the issue seems to be with getting the cache_creation_input_tokens and cache_read_input_tokens attributes: these are actually None rather than missing. So getattr(b,'cache_creation_input_tokens',0) returns None rather than 0.
Something like the following fixes the issue. (It's verbose though and there's probably a better solution; __repr__ and total need fixing as well.)
@patchdef__add__(self: Usage, b: Usage):
"Add together each of `input_tokens` and `output_tokens`"cache_creation_input_tokens=getattr(self, "cache_creation_input_tokens", 0) or0cache_creation_input_tokens+=getattr(b, "cache_creation_input_tokens", 0) or0cache_read_input_tokens=getattr(self, "cache_read_input_tokens", 0) or0cache_read_input_tokens+=getattr(b, "cache_read_input_tokens", 0) or0returnusage(
self.input_tokens+b.input_tokens,
self.output_tokens+b.output_tokens,
cache_creation_input_tokens,
cache_read_input_tokens,
)
The text was updated successfully, but these errors were encountered:
I'm trying to use claudette with Claude 3.5 Sonnet via Bedrock and I run into this error:
Here's a reprex to reproduce the error.
Here's the requirements.txt. I install these packages in a new environment.
(Unless I'm doing something wrong) the issue seems to be with getting the
cache_creation_input_tokens
andcache_read_input_tokens
attributes: these are actually None rather than missing. Sogetattr(b,'cache_creation_input_tokens',0)
returns None rather than 0.Something like the following fixes the issue. (It's verbose though and there's probably a better solution;
__repr__
andtotal
need fixing as well.)The text was updated successfully, but these errors were encountered: