bulk-chain 0.25.1__py3-none-any.whl → 0.25.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ class BaseLM(object):
24
24
  try:
25
25
  if self.__support_batching:
26
26
  # Launch in batch mode.
27
- content = self.ask(batch)
27
+ content = batch
28
28
  else:
29
29
  # Launch in non-batch mode.
30
30
  assert len(batch) == 1, "The LM does not support batching," \
@@ -8,21 +8,12 @@ def pad_str(text, pad):
8
8
  return text.rjust(len(text) + pad, ' ')
9
9
 
10
10
 
11
- def text_wrap(content, width, handle_line=lambda l: l):
12
- lines = []
13
- for text in content.split('\n'):
14
- for i in range(0, len(text), width):
15
- line = handle_line(text[i:i + width])
16
- lines.append(line)
17
- return '\n'.join(lines)
18
-
19
-
20
- def nice_output(text, width, pad=4, remove_new_line=False):
11
+ def nice_output(text, remove_new_line=False):
21
12
  short_text = text.replace("\n", "") if remove_new_line else text
22
- return text_wrap(content=short_text, width=width, handle_line=lambda line: pad_str(line, pad=pad))
13
+ return short_text
23
14
 
24
15
 
25
- def chat_with_lm(lm, preset_dict=None, chain=None, model_name=None, line_width=80, pad=0):
16
+ def chat_with_lm(lm, preset_dict=None, chain=None, model_name=None, pad=0):
26
17
  assert (isinstance(lm, BaseLM))
27
18
  assert (isinstance(chain, list))
28
19
  assert (isinstance(model_name, str) or model_name is None)
@@ -81,7 +72,7 @@ def chat_with_lm(lm, preset_dict=None, chain=None, model_name=None, line_width=8
81
72
  # Returning meta information, passed to LLM.
82
73
  streamed_logger.info(pad_str(f"{model_name} (ask [{chain_ind+1}/{len(chain)}]) ->", pad=pad))
83
74
  streamed_logger.info("\n")
84
- streamed_logger.info(nice_output(actual_prompt, pad=pad, remove_new_line=True, width=line_width))
75
+ streamed_logger.info(nice_output(actual_prompt, remove_new_line=True))
85
76
  streamed_logger.info("\n\n")
86
77
 
87
78
  # Response.
@@ -89,7 +80,7 @@ def chat_with_lm(lm, preset_dict=None, chain=None, model_name=None, line_width=8
89
80
  streamed_logger.info(pad_str(f"{model_name} (resp [{chain_ind+1}/{len(chain)}])->", pad=pad))
90
81
  streamed_logger.info("\n")
91
82
  if isinstance(response, str):
92
- streamed_logger.info(nice_output(response, pad=pad, remove_new_line=False, width=line_width))
83
+ streamed_logger.info(nice_output(response, remove_new_line=False))
93
84
  buffer = [response]
94
85
  else:
95
86
  buffer = []
bulk_chain/demo.py CHANGED
@@ -81,5 +81,4 @@ if __name__ == '__main__':
81
81
  preset_dict[key] = value
82
82
 
83
83
  # Launch Demo.
84
- chat_with_lm(llm, preset_dict=preset_dict, chain=schema.chain, model_name=llm_model_name,
85
- line_width=120)
84
+ chat_with_lm(llm, preset_dict=preset_dict, chain=schema.chain, model_name=llm_model_name)
bulk_chain/infer.py CHANGED
@@ -68,7 +68,6 @@ if __name__ == '__main__':
68
68
 
69
69
  parser = argparse.ArgumentParser(description="Infer Instruct LLM inference based on CoT schema")
70
70
  parser.add_argument('--adapter', dest='adapter', type=str, default=None)
71
- parser.add_argument('--attempts', dest='attempts', type=int, default=None)
72
71
  parser.add_argument('--id-col', dest='id_col', type=str, default="uid")
73
72
  parser.add_argument('--src', dest='src', type=str, nargs="?", default=None)
74
73
  parser.add_argument('--schema', dest='schema', type=str, default=None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bulk_chain
3
- Version: 0.25.1
3
+ Version: 0.25.2
4
4
  Summary: A lightweight, no-strings-attached Chain-of-Thought framework for your LLM, ensuring reliable results for bulk input requests.
5
5
  Home-page: https://github.com/nicolay-r/bulk-chain
6
6
  Author: Nicolay Rusnachenko
@@ -18,7 +18,7 @@ License-File: LICENSE
18
18
  Requires-Dist: tqdm
19
19
  Requires-Dist: source-iter ==0.24.3
20
20
 
21
- # bulk-chain 0.25.1
21
+ # bulk-chain 0.25.2
22
22
  ![](https://img.shields.io/badge/Python-3.9-brightgreen.svg)
23
23
  [![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nicolay-r/bulk-chain/blob/master/bulk_chain_tutorial.ipynb)
24
24
  [![twitter](https://img.shields.io/twitter/url/https/shields.io.svg?style=social)](https://x.com/nicolayr_/status/1847969224636961033)
@@ -30,6 +30,8 @@ Requires-Dist: source-iter ==0.24.3
30
30
 
31
31
  <p align="center">
32
32
  <a href="https://github.com/nicolay-r/nlp-thirdgate?tab=readme-ov-file#llm"><b>Third-party providers hosting</b>↗️</a>
33
+ <br>
34
+ <a href="https://github.com/nicolay-r/bulk-chain/blob/master/README.md#demo-mode">👉<b>demo</b>👈</a>
33
35
  </p>
34
36
 
35
37
  A no-strings-attached **framework** for your LLM that allows applying Chain-of-Thought-alike [prompt `schema`](#chain-of-thought-schema) towards a massive textual collections using custom **[third-party providers ↗️](https://github.com/nicolay-r/nlp-thirdgate?tab=readme-ov-file#llm)**.
@@ -86,11 +88,32 @@ Preliminary steps:
86
88
  1. Define your [schema](#chain-of-thought-schema) ([Example for Sentiment Analysis](/ext/schema/thor_cot_schema.json)))
87
89
  2. Wrap or pick **LLM model** from the [<b>Third-party providers hosting</b>↗️](https://github.com/nicolay-r/nlp-thirdgate?tab=readme-ov-file#llm).
88
90
 
89
- ## API
91
+ ## Shell
90
92
 
91
- Please take a look at the [**related Wiki page**](https://github.com/nicolay-r/bulk-chain/wiki)
93
+ ### Demo Mode
92
94
 
93
- ## Shell
95
+ **demo mode** to interact with LLM via command line with LLM output streaming support.
96
+ The video below illustrates an example of application for sentiment analysis on author opinion extraction towards mentioned object in text.
97
+
98
+ Quck start with launching demo:
99
+ 1. ⬇️ Download [replicate](https://replicate.com/) provider for `bulk-chain`:
100
+ 2. 📜 Setup your reasoning `thor_cot_schema.json` according to the [following example ↗️](test/schema/thor_cot_schema.json)
101
+ 3. 🚀 Launch `demo.py` as follows:
102
+ ```bash
103
+ python3 -m bulk_chain.demo \
104
+ --schema "test/schema/thor_cot_schema.json" \
105
+ --adapter "dynamic:replicate_104.py:Replicate" \
106
+ %%m \
107
+ --model_name "meta/meta-llama-3-70b-instruct" \
108
+ --api_token "<REPLICATE-API-TOKEN>" \
109
+ --stream
110
+ ```
111
+
112
+ 📺 This video showcase application of the [↗️ Sentiment Analysis Schema](https://github.com/nicolay-r/bulk-chain/blob/master/test/schema/thor_cot_schema.json) towards [LLaMA-3-70B-Instruct](https://replicate.com/meta/meta-llama-3-70b-instruct) hosted by Replicate for reasoning over submitted texts
113
+ ![sa-bulk-chain-cot-final](https://github.com/user-attachments/assets/0cc8fdcb-6ddb-44a3-8f05-d76250ae6423)
114
+
115
+
116
+ ### Inference Mode
94
117
 
95
118
  > **NOTE:** You have to install `source-iter` and `tqdm` packages that actual [dependencies](dependencies.txt) of this project
96
119
 
@@ -110,17 +133,10 @@ python3 -m bulk_chain.infer \
110
133
  --api_token "<REPLICATE-API-TOKEN>"
111
134
  ```
112
135
 
113
- Or, you can launch **demo mode** to interact with LLM via command line:
114
- > **NOTE:** Demo supports streaming!
115
- ```bash
116
- python3 -m bulk_chain.demo \
117
- --schema "test/schema/thor_cot_schema.json" \
118
- --adapter "dynamic:replicate_104.py:Replicate" \
119
- %%m \
120
- --model_name "meta/meta-llama-3-70b-instruct" \
121
- --api_token "<REPLICATE-API-TOKEN>" \
122
- --stream
123
- ```
136
+ ## API
137
+
138
+ Please take a look at the [**related Wiki page**](https://github.com/nicolay-r/bulk-chain/wiki)
139
+
124
140
 
125
141
  # Embed your LLM
126
142
 
@@ -1,20 +1,20 @@
1
1
  bulk_chain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  bulk_chain/api.py,sha256=3q1t4A5wop_BRgYanFCCSQBiGu38P9ds0hTbuxNIUKQ,3590
3
- bulk_chain/demo.py,sha256=x5OPyc7NSSr9KsfSx09KQkntJIev6gytqdhtx4b9FdU,3224
4
- bulk_chain/infer.py,sha256=VsqP8CP1pHBNeaDYAv__W6EPL8qBibuAtHzl4-S54iU,8148
3
+ bulk_chain/demo.py,sha256=3mvgEu03EyDDFzXtpx2fxozLITOn9Lo7ati6H1y54S4,3191
4
+ bulk_chain/infer.py,sha256=gq6G48XpOK56g5I_AU2kiQirQgcrZ353kfwjjRfQhSo,8069
5
5
  bulk_chain/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- bulk_chain/core/llm_base.py,sha256=uX_uibm5y8STfMKNYL64EeF8UowfJGwCD_t-uftHoJE,1849
6
+ bulk_chain/core/llm_base.py,sha256=fuWxfEOSRYvnoZMOcfnq1E2LIJKnrpsnxQ1z6SmY1nM,1839
7
7
  bulk_chain/core/service_args.py,sha256=lq4Veuh4QNu8mlCv8MT9S1rMxTn4FKalyp-3boYonVk,2136
8
8
  bulk_chain/core/service_batch.py,sha256=yQr6fbQd4ifQBGMhZMrQQeZpXtDchMKMGJi8XPG7thc,1430
9
9
  bulk_chain/core/service_data.py,sha256=ZjJDtd1jrQm9hRCXMqe4CT_qF2XDbWBE1lVibP7tAWo,942
10
10
  bulk_chain/core/service_dict.py,sha256=lAghLU-3V3xYGv5BTA327Qcw8UJYmgQRMFdggzlrUgo,383
11
11
  bulk_chain/core/service_json.py,sha256=6o1xM_8c9QEjH9Q3qEmJylU9nahfRXhUd5sFF2dGJwo,182
12
- bulk_chain/core/service_llm.py,sha256=uxtEw9OANFyjS4IECos_N5pUfAPQZVul61m64gnlwt0,3880
12
+ bulk_chain/core/service_llm.py,sha256=0lFqX02-BHI9OOdC-7hZhpsb9QrhCbKE7In3jhKXq3I,3452
13
13
  bulk_chain/core/service_schema.py,sha256=KIP4n0Tz2h1i7SIMGhgAhoiCgUFXOT1rzMt38yACS2U,1154
14
14
  bulk_chain/core/utils.py,sha256=UV6Cefaw7yZiYblsCr-s9LsbcI83xe7eESBvha9A2Og,2784
15
15
  bulk_chain/core/utils_logger.py,sha256=BD-ADxaeeuHztaYjqtIY_cIzc5r2Svq9XwRtrgIEqyI,1636
16
- bulk_chain-0.25.1.dist-info/LICENSE,sha256=VF9SjNpwwSSFEY_eP_8A1ocDCrbwfjI1pZexXdCkOwo,1076
17
- bulk_chain-0.25.1.dist-info/METADATA,sha256=EQNb6FwovXUSNXL5QpWf-3003863kL84ZWU7wya3ZeM,5071
18
- bulk_chain-0.25.1.dist-info/WHEEL,sha256=pL8R0wFFS65tNSRnaOVrsw9EOkOqxLrlUPenUYnJKNo,91
19
- bulk_chain-0.25.1.dist-info/top_level.txt,sha256=Hxq_wyH-GDXKBaA63UfBIiMJO2eCHJG5EOrXDphpeB4,11
20
- bulk_chain-0.25.1.dist-info/RECORD,,
16
+ bulk_chain-0.25.2.dist-info/LICENSE,sha256=VF9SjNpwwSSFEY_eP_8A1ocDCrbwfjI1pZexXdCkOwo,1076
17
+ bulk_chain-0.25.2.dist-info/METADATA,sha256=-N7-wOVXryBY1jkARSgWYZUAhdLYZlxkJ8qa8Vuj9no,6037
18
+ bulk_chain-0.25.2.dist-info/WHEEL,sha256=pL8R0wFFS65tNSRnaOVrsw9EOkOqxLrlUPenUYnJKNo,91
19
+ bulk_chain-0.25.2.dist-info/top_level.txt,sha256=Hxq_wyH-GDXKBaA63UfBIiMJO2eCHJG5EOrXDphpeB4,11
20
+ bulk_chain-0.25.2.dist-info/RECORD,,