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
import os
# set env for prompt builder
os.environ["BEDROCK_PROMPT"] = "anthropic"
os.environ["AWS_REGION"] = "us-east-1"
os.environ["AWS_ACCESS_KEY_ID"] = "xxx"
os.environ["AWS_SECRET_ACCESS_KEY"] = "xxx"
from easyllm.clients import bedrock
from easyllm.schema.base import ChatMessage
response = bedrock.ChatCompletion.create(
model="anthropic.claude-v2",
messages=[
ChatMessage(role="user", content="What is 2 + 2?"),
],
temperature=0.9,
top_p=0.6,
max_tokens=1024,
debug=False,
)
print(response)
Result:
Traceback (most recent call last):
File "<path_to>\main.py", line 27, in <module>
response = bedrock.ChatCompletion.create(
File "<path_to>\lib\site-packages\easyllm\clients\bedrock.py", line 208, in create
usage=Usage(
File "<path_to>\lib\site-packages\pydantic\main.py", line 159, in __init__
__pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Usage
completion_tokens
Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=2.25, input_type=float]
For further information visit https://errors.pydantic.dev/2.1/v/int_from_float
total_tokens
Input should be a valid integer, got a number with a fractional part [type=int_from_float, input_value=11.25, input_type=float]
For further information visit https://errors.pydantic.dev/2.1/v/int_from_float
The text was updated successfully, but these errors were encountered:
5c0rp
changed the title
pydantic ValidationError for bedrock ChatCompletion
bedrock.ChatCompletion.create Raises ValidationError for Non-Integer Token Values in Python 3.9
Oct 30, 2023
Python 3.9
Code to reproduce:
Result:
Expected result:
{'id': 'hf-iE53Kvwnlr', 'object': 'chat.completion', 'created': 1698683234, 'model': 'anthropic.claude-v2', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': '2 + 2 = 4'}, 'finish_reason': 'stop_sequence'}], 'usage': {'prompt_tokens': 9, 'completion_tokens': 2, 'total_tokens': 11}}
The text was updated successfully, but these errors were encountered: