A flexible Python library for building randomized sequential and decision-tree based chains.
Project description
Randchain
Randchain is a Python library for building intelligent decision trees and sequential processing chains powered by Large Language Models (LLMs). It simplifies the creation of automated workflows that can make decisions and execute actions based on natural language inputs.
Features
- Decision Tree Classification: Create dynamic decision trees that use LLMs to classify inputs and follow predefined paths
- Sequential Processing: Build chains of processing layers that transform inputs through multiple steps
- LLM Integration: Support for Ollama and OpenAI models
- Output Actions: Built-in support for sending emails, WhatsApp messages, and writing to files
- Modular Design: Clean separation into decision_tree and sequential modules
Installation
- Clone the repository:
git clone https://github.com/pydevpk/randchain.git
cd randchain
-
Make sure you have Python>=3.10 and created environment for it.
-
Set up environment variables in a
.envfile:
OPENAI_API_KEY=your_openai_api_key_here
sender_email=your_email@example.com
password=your_app_password
account_sid=your_twilio_account_sid
auth_token=your_twilio_auth_token
from_number=whatsapp:+1234567890
to_number=whatsapp:+0987654321
Modules
decision_tree
The decision_tree module provides classes for building LLM-powered decision trees.
Key Classes:
- LLM: Wrapper for LLM interactions with Ollama or OpenAI
- DTCliassifier: A node in the decision tree that makes decisions using LLMs
Usage:
from decision_tree import DTCliassifier, LLM
# Create a decision node
decision_node = DTCliassifier(
"MyAgent",
LLM("Ollama", "qwen2.5:latest", "Your prompt here")
)
# Make a decision
result = decision_node.decide("User query here")
sequential
The sequential module allows you to create chains of processing layers.
Key Classes:
- Layer: Represents a single processing step with configurable inputs and outputs
- Sequential: Manages a sequence of layers that process inputs progressively
Usage:
from sequential import Layer, Sequential
chain = Sequential([
Layer(my_function, whatsapp_config=whatsapp_config),
Layer(another_function)
])
result = chain.run(["input1", "input2"])
Note: First layer takes input from provided list of inputs, then next layers will take input from previous layer's output.
Configuration
Use the config.py classes to set up communication channels:
from core.config import EmailConfig, Whatsappconfig
email_config = EmailConfig(
sender_email="sender@example.com",
password="password",
recipient_email="recipient@example.com",
subject="Automated Message"
)
whatsapp_config = Whatsappconfig(
account_sid="your_account_sid",
auth_token="your_auth_token",
from_number="whatsapp:+1234567890",
to_number="whatsapp:+0987654321"
)
Utilities
The utils module provides helper functions:
send_email(): Send emails using SMTPsend_whatsapp(): Send WhatsApp messages via Twiliotxt_writer(): Write text to filesoutput_conversion(): Convert outputs to desired types
Testing
Run the test suite:
python test.py
The test demonstrates an insurance eligibility system using a decision tree combined with sequential processing for WhatsApp notifications.
Dependencies
- ollama
- openai
- twilio
- python-dotenv
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
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 randchain-0.1.4.tar.gz.
File metadata
- Download URL: randchain-0.1.4.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
378f16c477f4616ec95489ff88d618d3f87d62a2c7ba2a86ecad1b3c6d313a9b
|
|
| MD5 |
b60a214d02365efbaf519f238fc6c865
|
|
| BLAKE2b-256 |
2efe2e7987b2255c3027c70c8d6be1b182d2777b0b17d3f2bf8c6f4affa55397
|
File details
Details for the file randchain-0.1.4-py3-none-any.whl.
File metadata
- Download URL: randchain-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7378533918788bfc7b5a41b703d18fa67041f75427b1f5c1b028e1a1428e5792
|
|
| MD5 |
321e3fcc00054da28b894b29ad1fd49c
|
|
| BLAKE2b-256 |
ab33f13b8469f8fb5d67b09207baf1bb09e2764d7decd423431cee15cebf811a
|