How to load session to print out messenges via python api #3156
-
Hi,
However, when I print out the variable response: <Response [200]>. So obviously, The response is wrong and an error occurs JSONDecodeError: Expecting value: line 1 column 1 (char 0) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 41 replies
-
To correctly load and print out the session messages using the Python API for Langflow, you can use the from langflow.components.helpers.Memory import MemoryComponent
# Create an instance of the MemoryComponent
memory_component = MemoryComponent()
# Set the necessary inputs
memory_component.sender = "Machine and User"
memory_component.sender_name = "User"
memory_component.session_id = "your_session_id"
memory_component.n_messages = 100
memory_component.order = "Ascending"
memory_component.template = "{sender_name}: {text}"
# Retrieve messages
messages = memory_component.retrieve_messages()
# Print out the messages
for message in messages:
print(message)
# Alternatively, retrieve messages as text
messages_text = memory_component.retrieve_messages_as_text()
# Print out the messages as text
print(messages_text.text) This code snippet demonstrates how to use the |
Beta Was this translation helpful? Give feedback.
-
@dosu
However, when I print out the variable response: So obviously, The response is wrong and an error occurs |
Beta Was this translation helpful? Give feedback.
-
@dosu
streamlit-1 | 2024-08-13 01:38:09.075 | WARNING | langflow.services.database.utils:migrate_transactions_from_monitor_service_to_database:166 - Error retrieving transactions from monitor service: IO Error: Cannot open database "/root/.cache/langflow/monitor.duckdb" in read-only mode: database does not exist |
Beta Was this translation helpful? Give feedback.
To correctly load and print out the session messages using the Python API for Langflow, you can use the
retrieve_messages
andretrieve_messages_as_text
methods from theMemoryComponent
class. Here is an example of how you can achieve this: