Add conversation history export docs

Add conversation history export docs
pull/888/head
Pavan Kumar 1 month ago committed by GitHub
commit 5bc09234f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -491,6 +491,19 @@ agent.model_dump_json()
print(agent.to_toml())
```
### Export Conversation History
```python
from swarms.structs.conversation import Conversation
from swarms.utils.history_output_formatter import history_output_formatter
conversation = Conversation()
conversation.add("user", "Hello")
conversation.add("assistant", "Hi!")
yaml_history = history_output_formatter(conversation, type="yaml")
xml_history = history_output_formatter(conversation, type="xml")
```

@ -281,6 +281,8 @@ nav:
- Pinecone: "swarms_memory/pinecone.md"
- Faiss: "swarms_memory/faiss.md"
- Utilities:
- History Output Formatter: "utils/history_output_formatter.md"
- Deployment Solutions:
- Deploy your Swarms on Google Cloud Run: "swarms_cloud/cloud_run.md"
- Deploy your Swarms on Phala: "swarms_cloud/phala_deploy.md"

@ -0,0 +1,25 @@
# history_output_formatter Utility
The `history_output_formatter` function converts a `Conversation` object into various formats.
It supports lists, dictionaries, strings, JSON, YAML, and XML.
## Export to YAML
```python
from swarms.structs.conversation import Conversation
from swarms.utils.history_output_formatter import history_output_formatter
conversation = Conversation()
conversation.add("user", "Hello")
conversation.add("assistant", "Hi there!")
yaml_history = history_output_formatter(conversation, type="yaml")
print(yaml_history)
```
## Export to XML
```python
xml_history = history_output_formatter(conversation, type="xml")
print(xml_history)
```

@ -0,0 +1,15 @@
from swarms.structs.conversation import Conversation
from swarms.utils.history_output_formatter import history_output_formatter
# Create a simple conversation
conversation = Conversation()
conversation.add("user", "Hello")
conversation.add("assistant", "Hi there!")
# Export the conversation to YAML
yaml_output = history_output_formatter(conversation, type="yaml")
print("YAML Format:\n", yaml_output)
# Export the conversation to XML
xml_output = history_output_formatter(conversation, type="xml")
print("\nXML Format:\n", xml_output)
Loading…
Cancel
Save