A lightweight, no-strings-attached Chain-of-Thought framework for your LLM, ensuring reliable results for bulk input requests.
Project description
bulk-chain 1.2.0
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
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 we use JSON format.
The field schema is a list of CoT instructions for the Large Language Model.
Each item of the list represent a dictionary with prompt and out keys that corresponds to the input prompt and output variable name respectively.
All the variable names should be mentioned in {}.
Example:
[
{"prompt": "Given customer message: {text}, detect the customer's intent?", "out": "intent" },
{"prompt": "Given customer message: {text}, extract relevant entities?", "out": "entities"},
{"prompt": "Given intent: {intent} and entities: {entities}, generate a concise response or action recommendation for support agent.", "out": "action"}
]
Usage
🤖 Prepare
- schema
- LLM model from the Third-party providers hosting↗️.
- Data (iter of dictionaries)
🚀 Launch
API: For more details see the related Wiki page
from bulk_chain.core.utils import dynamic_init
from bulk_chain.api import iter_content
content_it = iter_content(
# 1. Your schema.
schema=[
{"prompt": "Given customer message: {text}, detect the customer's intent?", "out": "intent" },
{"prompt": "Given customer message: {text}, extract relevant entities?", "out": "entities"},
{"prompt": "Given intent: {intent} and entities: {entities}, generate a concise response or action recommendation for support agent.", "out": "action"}
],
# 2. Your third-party model implementation.
llm=dynamic_init(class_filepath="replicate_104.py")(
api_token="<API-KEY>",
model_name="meta/meta-llama-3-70b-instruct"),
# 3. Customize your inference and result providing modes:
infer_mode="batch_async",
# 4. Your iterator of dictionaries
input_dicts_it=YOUR_DATA_IT,
)
for content in content_it:
# Handle your LLM responses here ...
Inference Modes
The type of the content variable depends on infer_mode declared above.
Below is the table that describes expected content type to the infer mode:
| Infer Modes | Content Type |
|---|---|
single |
record |
single_stream |
chunk |
batch |
batch |
batch_async |
batch |
batch_stream_async |
chunk |
API
| Method | Mode | Description |
|---|---|---|
ask(prompt) |
Sync | Infers the model with a single prompt. |
ask_stream(prompt) |
Sync | Returns a generator that yields chunks of the inferred result. |
ask_async(prompt) |
Async | Asynchronously infers the model with a single prompt. |
ask_stream_async(prompt) |
Async | Asynchronously returns a generator of result chunks of the inferred result. |
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-1.2.0.tar.gz.
File metadata
- Download URL: bulk_chain-1.2.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.67.1 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f071e91b8ac091d339ad9b5d009e1bfd3cf1725f16f2ce1cbd8e91c7562ef3a2
|
|
| MD5 |
6d6c6f37c221242d61257274261cdc75
|
|
| BLAKE2b-256 |
c45b783b08af67c6e5de438e1c4c233edad9ec78f235d3d42ffb7a7c1da64b37
|
File details
Details for the file bulk_chain-1.2.0-py3-none-any.whl.
File metadata
- Download URL: bulk_chain-1.2.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.67.1 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70f836a04ef7248d40e16a71645bab00971d1235a2f4ec720943427ff623e016
|
|
| MD5 |
b5c68bea16b82268094f2cb3082c8595
|
|
| BLAKE2b-256 |
57e3747e8388940062e9fafa9f5c713be75c0ee9f9be89d7087597fdf20c2390
|