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.1
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": "extract topic: {text}", "out": "topic"},
{"prompt": "extract subject: {text}", "out": "subject"},
]
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": "extract topic: {text}", "out": "topic" },
{"prompt": "extract subject: {text}", "out": "subject"},
],
# 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. Toggle streaming if needed
stream=False,
# 4. Toggle Async API mode usage.
async_mode=True,
# 5. Batch size.
batch_size=10,
# 6. Your iterator of dictionaries
input_dicts_it=[
# Example of data ...
{ "text": "Rocks are hard" },
{ "text": "Water is wet" },
{ "text": "Fire is hot" }
],
)
for batch in content_it:
for entry in batch:
print(entry)
Outputs entries represent texts augmented with topic and subject:
{'text': 'Rocks are hard', 'topic': 'The topic is: Geology/Rocks', 'subject': 'The subject is: "Rocks"'}
{'text': 'Water is wet', 'topic': 'The topic is: Properties of Water', 'subject': 'The subject is: Water'}
{'text': 'Fire is hot', 'topic': 'The topic is: Temperature/Properties of Fire', 'subject': 'The subject is: "Fire"'}
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.1.tar.gz.
File metadata
- Download URL: bulk_chain-1.2.1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1851082a3dc3dbdde0946a78f9714824c44551117de754e236d856d6352691ff
|
|
| MD5 |
703db7809f606fd6626677e3d9e1ce65
|
|
| BLAKE2b-256 |
37118d46d28a7e4a9946495fb8b2cfc3bec51f3f4c8c113852533fcb093fe9cf
|
File details
Details for the file bulk_chain-1.2.1-py3-none-any.whl.
File metadata
- Download URL: bulk_chain-1.2.1-py3-none-any.whl
- Upload date:
- Size: 12.2 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 |
2cf6956f74b60ff361617ca859b2fe6827b85309d8a2bef38860bb1cd6168dfc
|
|
| MD5 |
da1a526969fc5a0725ab996cdefa5349
|
|
| BLAKE2b-256 |
2fc39ca9d43efc14dfa50dfb49e3149011624fc749569c8f97fe37f8b69b999c
|