A lightweight, no-strings-attached Chain-of-Thought framework for your LLM, ensuring reliable results for bulk input requests.
Project description
bulk-chain 0.25.2
Third-party providers hosting↗️
👉demo👈
A no-strings-attached framework for your LLM that allows applying Chain-of-Thought-alike prompt schema towards a massive textual collections using custom third-party providers ↗️.
Main Features
- ✅ No-strings: you're free to LLM dependencies and flexible
venvcustomization. - ✅ Support schemas descriptions for Chain-of-Thought concept.
- ✅ Provides iterator over infinite amount of input contexts served in
CSV/JSONL.
Extra Features
- ✅ Progress caching [for remote LLMs]: withstanding exception during LLM calls by using
sqlite3engine for caching LLM answers;
Installation
From PyPI:
pip install --no-deps bulk-chain
or latest version from here:
pip install git+https://github.com/nicolay-r/bulk-chain@master
Chain-of-Thought Schema
To declare Chain-of-Though (CoT) schema, this project exploits JSON format.
This format adopts name field for declaring a name and schema is a list of CoT instructions for the Large Language Model.
Each step represents a dictionary with prompt and out keys that corresponds to the input prompt and output variable name respectively.
All the variable names are expected to be mentioned in {}.
Below, is an example on how to declare your own schema:
{
"name": "schema-name",
"schema": [
{"prompt": "Given the question '{text}', let's think step-by-step.",
"out": "steps"},
{"prompt": "For the question '{text}' the reasoining steps are '{steps}'. what would be an answer?",
"out": "answer"},
]
}
Usage
Preliminary steps:
- Define your schema (Example for Sentiment Analysis))
- Wrap or pick LLM model from the Third-party providers hosting↗️.
Shell
Demo Mode
demo mode to interact with LLM via command line with LLM output streaming support. The video below illustrates an example of application for sentiment analysis on author opinion extraction towards mentioned object in text.
Quck start with launching demo:
- ⬇️ Download replicate provider for
bulk-chain: - 📜 Setup your reasoning
thor_cot_schema.jsonaccording to the following example ↗️ - 🚀 Launch
demo.pyas follows:
python3 -m bulk_chain.demo \
--schema "test/schema/thor_cot_schema.json" \
--adapter "dynamic:replicate_104.py:Replicate" \
%%m \
--model_name "meta/meta-llama-3-70b-instruct" \
--api_token "<REPLICATE-API-TOKEN>" \
--stream
📺 This video showcase application of the ↗️ Sentiment Analysis Schema towards LLaMA-3-70B-Instruct hosted by Replicate for reasoning over submitted texts
Inference Mode
NOTE: You have to install
source-iterandtqdmpackages that actual dependencies of this project
- ⬇️ Download replicate provider for
bulk-chain:
wget https://raw.githubusercontent.com/nicolay-r/nlp-thirdgate/refs/heads/master/llm/replicate_104.py
- 📜 Setup your reasoning
schema.jsonaccording to the following example ↗️ - 🚀 Launch inference using
DeepSeek-R1:
python3 -m bulk_chain.infer \
--src "<PATH-TO-YOUR-CSV-or-JSONL>" \
--schema "test/schema/default.json" \
--adapter "replicate_104.py:Replicate" \
%%m \
--model_name "deepseek-ai/deepseek-r1" \
--api_token "<REPLICATE-API-TOKEN>"
API
Please take a look at the related Wiki page
Embed your LLM
All you have to do is to implement BaseLM class, that includes:
__init__-- for setting up batching mode support and (optional) model name;ask(prompt)-- infer your model with the givenprompt.
See examples with models at nlp-thirdgate 🌌.
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 bulk_chain-0.25.2.tar.gz.
File metadata
- Download URL: bulk_chain-0.25.2.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ab2cd4405374d52357c1b0b7b506e6265f18d950ed9391cba15ae357c76733c
|
|
| MD5 |
cacb069f5ecf3749eddc51db7b094a92
|
|
| BLAKE2b-256 |
fb3d3420e6486f4afa847c65ae4a2ecf165cf775f74c2e492aab0ae15559be5b
|
File details
Details for the file bulk_chain-0.25.2-py3-none-any.whl.
File metadata
- Download URL: bulk_chain-0.25.2-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2f308d99fd96c30b434f62d702f9209641bebcbea91f6130f17961a385d0e25
|
|
| MD5 |
85ae49a510be045b37ad7af13d3401c3
|
|
| BLAKE2b-256 |
da26cda4f300df76faf30aea9a6d246ab4775b8134513bf7e40b619a5fb11b45
|