You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
1 year ago
|
To store your conversation on DynamoDB you can use DynamoDbConversationMemoryDriver.
|
||
|
```python
|
||
|
from swarms.memory.structure import ConversationMemory
|
||
|
from swarms.memory.structure import ConversationMemoryElement, Turn, Message
|
||
|
from swarms.drivers import DynamoDbConversationMemoryDriver
|
||
|
|
||
|
# Instantiate DynamoDbConversationMemoryDriver
|
||
|
dynamo_driver = DynamoDbConversationMemoryDriver(
|
||
|
aws_region="us-east-1",
|
||
|
table_name="conversations",
|
||
|
partition_key="convo_id",
|
||
|
value_attribute_key="convo_data",
|
||
|
partition_key_value="convo1"
|
||
|
)
|
||
|
|
||
|
# Create a ConversationMemory structure
|
||
|
conv_mem = ConversationMemory(
|
||
|
turns=[
|
||
|
Turn(
|
||
|
turn_index=0,
|
||
|
system=Message("Hello"),
|
||
|
user=Message("Hi")
|
||
|
),
|
||
|
Turn(
|
||
|
turn_index=1,
|
||
|
system=Message("How can I assist you today?"),
|
||
|
user=Message("I need some information")
|
||
|
)
|
||
|
],
|
||
|
latest_turn=Turn(
|
||
|
turn_index=2,
|
||
|
system=Message("Sure, what information do you need?"),
|
||
|
user=None # user has not yet responded
|
||
|
),
|
||
|
driver=dynamo_driver # set the driver
|
||
|
)
|
||
|
|
||
|
# Store the conversation in DynamoDB
|
||
|
dynamo_driver.store(conv_mem)
|
||
|
|
||
|
# Load the conversation from DynamoDB
|
||
|
loaded_conv_mem = dynamo_driver.load()
|
||
|
|
||
|
# Display the loaded conversation
|
||
|
print(loaded_conv_mem.to_json())
|
||
|
|
||
|
```
|