Branching conversation trees for AI chat. Store, retrieve, and route conversations with tree-based memory.
Project description
branchy-chat
Store conversation messages as a tree structure, retrieve relevant context traces, and let your LLM automatically route new prompts to the right branch.
- 🌳 Tree-based conversation memory
- 🔍 Retrieve relevant conversation traces
- 🧠 LLM-powered branch routing
- 📦 Publishable pip package
Installation
pip install branchy-chat
Usage
from branchy import BranchingChat
chat = BranchingChat(
model="openai/gpt-4o-mini",
api_key="<your-api-key>",
api_base="http://localhost:4000", # Optional, useful for LiteLLM proxy
)
message_id_1 = chat.add_message("How do I build an index in Postgres?")
message_id_2 = chat.add_message("What if I need it concurrently?")
# Display the tree structure
print(chat.show_tree())
# Display a subtree starting from a specific message
print(chat.show_subtree(message_id_1))
LiteLLM compatibility
BranchingChat supports LiteLLM-style parameters:
modelapi_keyapi_base
This means you can point it at a LiteLLM proxy endpoint by setting api_base.
API
BranchingChat(*, model, api_key=None, api_base=None, **lm_kwargs): Initialize using LiteLLM-compatible arguments.BranchingChat.add_message(user_message: str) -> str: Routes a message to the best branch, stores it in the tree, and returns the newmessage_id.BranchingChat.show_tree() -> str: Renders user messages in an ASCII tree format and returns the formatted string.BranchingChat.show_subtree(message_id: str) -> str: Renders a subtree starting from a givenmessage_idand all its child branches.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file branchy_chat-0.1.2.tar.gz.
File metadata
- Download URL: branchy_chat-0.1.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0cdcb5f432caeb3700e25af244c242f33f1b21c56f341446c416aa02aa8b353
|
|
| MD5 |
361a529a4a6b2eaeff53881461de26f4
|
|
| BLAKE2b-256 |
7022bb9aad824608e9ebbe51694b6fff35d0b0a5fc96ee6f83d4e39b18021ddd
|
File details
Details for the file branchy_chat-0.1.2-py3-none-any.whl.
File metadata
- Download URL: branchy_chat-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d925d7da71da02be8b33aab082392b5f09e6d5cd76c2372df80748a5b57eae2c
|
|
| MD5 |
2d70dde8ab933d0b91c90826bc0a004b
|
|
| BLAKE2b-256 |
4610c41205b67ecb50efbea82c203dce9bd12b4f10f4af0e59bda8c728cbf49b
|