-
Notifications
You must be signed in to change notification settings - Fork 975
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
Fix: DynamoDB Typeerror with AWS Bedrock #1163
Open
munday-tech
wants to merge
9
commits into
Chainlit:main
Choose a base branch
from
munday-tech:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
93e81ab
Fix langchain_aws Decimal errors
munday-tech 0f51615
fix: update type check
munday-tech c1b313f
Update backend/chainlit/data/dynamodb.py
munday-tech 67a57d0
Update backend/chainlit/data/dynamodb.py
munday-tech 64646d5
Move function calls to sterilization calls
munday-tech 6ecb06a
fix mypy
munday-tech 4833922
Merge branch 'main' into main
dokterbob ca3358a
Merge branch 'main' into main
dokterbob 49f5f19
Merge branch 'Chainlit:main' into main
munday-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import logging | ||
import os | ||
import random | ||
from decimal import Decimal | ||
from dataclasses import asdict | ||
from datetime import datetime | ||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union | ||
|
@@ -60,17 +61,49 @@ def __init__( | |
def _get_current_timestamp(self) -> str: | ||
return datetime.now().isoformat() + "Z" | ||
|
||
def _convert_floats_to_decimal(self, obj): | ||
if isinstance(obj, list): | ||
return [self._convert_floats_to_decimal(i) for i in obj] | ||
|
||
for key, value in obj.items(): | ||
if isinstance(value, float): | ||
obj[key] = Decimal(str(value)) | ||
elif isinstance(value, dict): | ||
self._convert_floats_to_decimal(value) | ||
elif isinstance(value, list): | ||
obj[key] = [self._convert_floats_to_decimal(i) for i in value] | ||
|
||
return obj | ||
|
||
def _convert_decimal_to_floats(self, obj): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type hints here as well please. 🙏🏼 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And a docstring, if possible. |
||
if isinstance(obj, list): | ||
return [self._convert_decimal_to_floats(i) for i in obj] | ||
|
||
for key, value in obj.items(): | ||
if isinstance(value, Decimal): | ||
obj[key] = float(value) | ||
elif isinstance(value, dict): | ||
self._convert_decimal_to_floats(value) | ||
elif isinstance(value, list): | ||
obj[key] = [self._convert_decimal_to_floats(i) for i in value] | ||
|
||
return obj | ||
|
||
def _serialize_item(self, item: Dict[str, Any]) -> Dict[str, Any]: | ||
item = self._convert_floats_to_decimal(item) | ||
return { | ||
key: self._type_serializer.serialize(value) for key, value in item.items() | ||
key: self._type_serializer.serialize(value) | ||
for key, value in item.items() | ||
} | ||
|
||
def _deserialize_item(self, item: Dict[str, Any]) -> Dict[str, Any]: | ||
item = self._convert_decimal_to_floats(item) | ||
return { | ||
key: self._type_deserializer.deserialize(value) | ||
for key, value in item.items() | ||
} | ||
|
||
|
||
def _update_item(self, key: Dict[str, Any], updates: Dict[str, Any]): | ||
update_expr: List[str] = [] | ||
expression_attribute_names = {} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add type hints here so that we can use type checking to ensure that what we think this is doing is actually what it's doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a docstring, if possible.