llm_batch_helper 0.1.3__tar.gz → 0.1.5__tar.gz

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.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: llm_batch_helper
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: A Python package that enables batch submission of prompts to LLM APIs, with built-in async capabilities and response caching.
5
5
  License: MIT
6
- Keywords: llm,openai,batch,async,ai,nlp,api
6
+ Keywords: llm,openai,together,batch,async,ai,nlp,api
7
7
  Author: Tianyi Peng
8
8
  Author-email: tianyipeng95@gmail.com
9
9
  Requires-Python: >=3.11,<4.0
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
- Requires-Dist: httpx (>=0.24.0,<0.25.0)
20
+ Requires-Dist: httpx (>=0.24.0,<2.0.0)
21
21
  Requires-Dist: openai (>=1.0.0,<2.0.0)
22
22
  Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
23
23
  Requires-Dist: tenacity (>=8.0.0,<9.0.0)
@@ -35,7 +35,7 @@ A Python package that enables batch submission of prompts to LLM APIs, with buil
35
35
  - **Async Processing**: Submit multiple prompts concurrently for faster processing
36
36
  - **Response Caching**: Automatically cache responses to avoid redundant API calls
37
37
  - **Multiple Input Formats**: Support for both file-based and list-based prompts
38
- - **Provider Support**: Works with OpenAI API
38
+ - **Provider Support**: Works with OpenAI and Together.ai APIs
39
39
  - **Retry Logic**: Built-in retry mechanism with exponential backoff
40
40
  - **Verification Callbacks**: Custom verification for response quality
41
41
  - **Progress Tracking**: Real-time progress bars for batch operations
@@ -70,6 +70,9 @@ poetry shell
70
70
  ```bash
71
71
  # For OpenAI
72
72
  export OPENAI_API_KEY="your-openai-api-key"
73
+
74
+ # For Together.ai
75
+ export TOGETHER_API_KEY="your-together-api-key"
73
76
  ```
74
77
 
75
78
  ### 2. Interactive Tutorial (Recommended)
@@ -89,7 +92,7 @@ async def main():
89
92
  config = LLMConfig(
90
93
  model_name="gpt-4o-mini",
91
94
  temperature=0.7,
92
- max_tokens=100,
95
+ max_completion_tokens=100, # or use max_tokens for backward compatibility
93
96
  max_concurrent_requests=30 # number of concurrent requests with asyncIO
94
97
  )
95
98
 
@@ -127,7 +130,7 @@ async def process_files():
127
130
  config = LLMConfig(
128
131
  model_name="gpt-4o-mini",
129
132
  temperature=0.7,
130
- max_tokens=200
133
+ max_completion_tokens=200
131
134
  )
132
135
 
133
136
  # Process all .txt files in a directory
@@ -183,7 +186,8 @@ Configuration class for LLM requests.
183
186
  LLMConfig(
184
187
  model_name: str,
185
188
  temperature: float = 0.7,
186
- max_tokens: Optional[int] = None,
189
+ max_completion_tokens: Optional[int] = None, # Preferred parameter
190
+ max_tokens: Optional[int] = None, # Deprecated, kept for backward compatibility
187
191
  system_instruction: Optional[str] = None,
188
192
  max_retries: int = 10,
189
193
  max_concurrent_requests: int = 5,
@@ -199,7 +203,7 @@ Main function for batch processing of prompts.
199
203
  ```python
200
204
  async def process_prompts_batch(
201
205
  config: LLMConfig,
202
- provider: str, # "openai"
206
+ provider: str, # "openai" or "together"
203
207
  prompts: Optional[List[str]] = None,
204
208
  input_dir: Optional[str] = None,
205
209
  cache_dir: str = "llm_cache",
@@ -256,6 +260,23 @@ llm_batch_helper/
256
260
  - gpt-4
257
261
  - gpt-3.5-turbo
258
262
 
263
+ ### Together.ai
264
+ - meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo
265
+ - meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo
266
+ - mistralai/Mixtral-8x7B-Instruct-v0.1
267
+ - And many other open-source models
268
+
269
+ ## Documentation
270
+
271
+ 📖 **[Complete Documentation](https://llm-batch-helper.readthedocs.io/)** - Comprehensive docs on Read the Docs
272
+
273
+ ### Quick Links:
274
+ - [Quick Start Guide](https://llm-batch-helper.readthedocs.io/en/latest/quickstart.html) - Get started quickly
275
+ - [API Reference](https://llm-batch-helper.readthedocs.io/en/latest/api.html) - Complete API documentation
276
+ - [Examples](https://llm-batch-helper.readthedocs.io/en/latest/examples.html) - Practical usage examples
277
+ - [Tutorials](https://llm-batch-helper.readthedocs.io/en/latest/tutorials.html) - Step-by-step tutorials
278
+ - [Provider Guide](https://llm-batch-helper.readthedocs.io/en/latest/providers.html) - OpenAI & Together.ai setup
279
+
259
280
  ## Contributing
260
281
 
261
282
  1. Fork the repository
@@ -271,6 +292,12 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
271
292
 
272
293
  ## Changelog
273
294
 
295
+ ### v0.1.5
296
+ - Added Together.ai provider support
297
+ - Support for open-source models (Llama, Mixtral, etc.)
298
+ - Enhanced documentation with Read the Docs
299
+ - Updated examples and tutorials
300
+
274
301
  ### v0.1.0
275
302
  - Initial release
276
303
  - Support for OpenAI API
@@ -7,7 +7,7 @@ A Python package that enables batch submission of prompts to LLM APIs, with buil
7
7
  - **Async Processing**: Submit multiple prompts concurrently for faster processing
8
8
  - **Response Caching**: Automatically cache responses to avoid redundant API calls
9
9
  - **Multiple Input Formats**: Support for both file-based and list-based prompts
10
- - **Provider Support**: Works with OpenAI API
10
+ - **Provider Support**: Works with OpenAI and Together.ai APIs
11
11
  - **Retry Logic**: Built-in retry mechanism with exponential backoff
12
12
  - **Verification Callbacks**: Custom verification for response quality
13
13
  - **Progress Tracking**: Real-time progress bars for batch operations
@@ -42,6 +42,9 @@ poetry shell
42
42
  ```bash
43
43
  # For OpenAI
44
44
  export OPENAI_API_KEY="your-openai-api-key"
45
+
46
+ # For Together.ai
47
+ export TOGETHER_API_KEY="your-together-api-key"
45
48
  ```
46
49
 
47
50
  ### 2. Interactive Tutorial (Recommended)
@@ -61,7 +64,7 @@ async def main():
61
64
  config = LLMConfig(
62
65
  model_name="gpt-4o-mini",
63
66
  temperature=0.7,
64
- max_tokens=100,
67
+ max_completion_tokens=100, # or use max_tokens for backward compatibility
65
68
  max_concurrent_requests=30 # number of concurrent requests with asyncIO
66
69
  )
67
70
 
@@ -99,7 +102,7 @@ async def process_files():
99
102
  config = LLMConfig(
100
103
  model_name="gpt-4o-mini",
101
104
  temperature=0.7,
102
- max_tokens=200
105
+ max_completion_tokens=200
103
106
  )
104
107
 
105
108
  # Process all .txt files in a directory
@@ -155,7 +158,8 @@ Configuration class for LLM requests.
155
158
  LLMConfig(
156
159
  model_name: str,
157
160
  temperature: float = 0.7,
158
- max_tokens: Optional[int] = None,
161
+ max_completion_tokens: Optional[int] = None, # Preferred parameter
162
+ max_tokens: Optional[int] = None, # Deprecated, kept for backward compatibility
159
163
  system_instruction: Optional[str] = None,
160
164
  max_retries: int = 10,
161
165
  max_concurrent_requests: int = 5,
@@ -171,7 +175,7 @@ Main function for batch processing of prompts.
171
175
  ```python
172
176
  async def process_prompts_batch(
173
177
  config: LLMConfig,
174
- provider: str, # "openai"
178
+ provider: str, # "openai" or "together"
175
179
  prompts: Optional[List[str]] = None,
176
180
  input_dir: Optional[str] = None,
177
181
  cache_dir: str = "llm_cache",
@@ -228,6 +232,23 @@ llm_batch_helper/
228
232
  - gpt-4
229
233
  - gpt-3.5-turbo
230
234
 
235
+ ### Together.ai
236
+ - meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo
237
+ - meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo
238
+ - mistralai/Mixtral-8x7B-Instruct-v0.1
239
+ - And many other open-source models
240
+
241
+ ## Documentation
242
+
243
+ 📖 **[Complete Documentation](https://llm-batch-helper.readthedocs.io/)** - Comprehensive docs on Read the Docs
244
+
245
+ ### Quick Links:
246
+ - [Quick Start Guide](https://llm-batch-helper.readthedocs.io/en/latest/quickstart.html) - Get started quickly
247
+ - [API Reference](https://llm-batch-helper.readthedocs.io/en/latest/api.html) - Complete API documentation
248
+ - [Examples](https://llm-batch-helper.readthedocs.io/en/latest/examples.html) - Practical usage examples
249
+ - [Tutorials](https://llm-batch-helper.readthedocs.io/en/latest/tutorials.html) - Step-by-step tutorials
250
+ - [Provider Guide](https://llm-batch-helper.readthedocs.io/en/latest/providers.html) - OpenAI & Together.ai setup
251
+
231
252
  ## Contributing
232
253
 
233
254
  1. Fork the repository
@@ -243,6 +264,12 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
243
264
 
244
265
  ## Changelog
245
266
 
267
+ ### v0.1.5
268
+ - Added Together.ai provider support
269
+ - Support for open-source models (Llama, Mixtral, etc.)
270
+ - Enhanced documentation with Read the Docs
271
+ - Updated examples and tutorials
272
+
246
273
  ### v0.1.0
247
274
  - Initial release
248
275
  - Support for OpenAI API
@@ -3,7 +3,7 @@ from .config import LLMConfig
3
3
  from .input_handlers import get_prompts, read_prompt_files, read_prompt_list
4
4
  from .providers import process_prompts_batch
5
5
 
6
- __version__ = "0.1.1"
6
+ __version__ = "0.1.5"
7
7
 
8
8
  __all__ = [
9
9
  "LLMCache",
@@ -60,6 +60,65 @@ async def _get_openai_response_direct(
60
60
  "usage_details": usage_details,
61
61
  }
62
62
 
63
+
64
+ @retry(
65
+ stop=stop_after_attempt(5),
66
+ wait=wait_exponential(multiplier=1, min=4, max=60),
67
+ retry=retry_if_exception_type(
68
+ (
69
+ ConnectionError,
70
+ TimeoutError,
71
+ httpx.HTTPStatusError,
72
+ httpx.RequestError,
73
+ )
74
+ ),
75
+ reraise=True,
76
+ )
77
+ async def _get_together_response_direct(
78
+ prompt: str, config: LLMConfig
79
+ ) -> Dict[str, Union[str, Dict]]:
80
+ api_key = os.environ.get("TOGETHER_API_KEY")
81
+ if not api_key:
82
+ raise ValueError("TOGETHER_API_KEY environment variable not set")
83
+
84
+ async with httpx.AsyncClient(timeout=1000.0) as client:
85
+ messages = [
86
+ {"role": "system", "content": config.system_instruction},
87
+ {"role": "user", "content": prompt},
88
+ ]
89
+
90
+ headers = {
91
+ "Authorization": f"Bearer {api_key}",
92
+ "Content-Type": "application/json",
93
+ }
94
+
95
+ payload = {
96
+ "model": config.model_name,
97
+ "messages": messages,
98
+ "temperature": config.temperature,
99
+ "max_tokens": config.max_completion_tokens,
100
+ }
101
+
102
+ response = await client.post(
103
+ "https://api.together.xyz/chat/completions",
104
+ json=payload,
105
+ headers=headers,
106
+ )
107
+ response.raise_for_status()
108
+
109
+ response_data = response.json()
110
+ usage = response_data.get("usage", {})
111
+ usage_details = {
112
+ "prompt_token_count": usage.get("prompt_tokens", 0),
113
+ "completion_token_count": usage.get("completion_tokens", 0),
114
+ "total_token_count": usage.get("total_tokens", 0),
115
+ }
116
+
117
+ return {
118
+ "response_text": response_data["choices"][0]["message"]["content"],
119
+ "usage_details": usage_details,
120
+ }
121
+
63
122
  async def get_llm_response_with_internal_retry(
64
123
  prompt_id: str,
65
124
  prompt: str,
@@ -77,6 +136,8 @@ async def get_llm_response_with_internal_retry(
77
136
  try:
78
137
  if provider.lower() == "openai":
79
138
  response = await _get_openai_response_direct(prompt, config)
139
+ elif provider.lower() == "together":
140
+ response = await _get_together_response_direct(prompt, config)
80
141
  else:
81
142
  raise ValueError(f"Unsupported provider: {provider}")
82
143
 
@@ -107,7 +168,7 @@ async def process_prompts_batch(
107
168
  prompts: Optional list of prompts in any supported format (string, tuple, or dict)
108
169
  input_dir: Optional path to directory containing prompt files
109
170
  config: LLM configuration
110
- provider: LLM provider to use ("openai" or "gemini")
171
+ provider: LLM provider to use ("openai", "together", or "gemini")
111
172
  desc: Description for progress bar
112
173
  cache_dir: Optional directory for caching responses
113
174
  force: If True, force regeneration even if cached response exists
@@ -1,13 +1,13 @@
1
1
  [tool.poetry]
2
2
  name = "llm_batch_helper"
3
- version = "0.1.3"
3
+ version = "0.1.5"
4
4
  description = "A Python package that enables batch submission of prompts to LLM APIs, with built-in async capabilities and response caching."
5
5
  authors = ["Tianyi Peng <tianyipeng95@gmail.com>"]
6
6
  readme = "README.md"
7
7
  license = "MIT"
8
8
  homepage = "https://github.com/TianyiPeng/LLM_batch_helper"
9
9
  repository = "https://github.com/TianyiPeng/LLM_batch_helper"
10
- keywords = ["llm", "openai", "batch", "async", "ai", "nlp", "api"]
10
+ keywords = ["llm", "openai", "together", "batch", "async", "ai", "nlp", "api"]
11
11
  classifiers = [
12
12
  "Development Status :: 4 - Beta",
13
13
  "Intended Audience :: Developers",
@@ -23,7 +23,7 @@ packages = [{include = "llm_batch_helper"}]
23
23
 
24
24
  [tool.poetry.dependencies]
25
25
  python = "^3.11"
26
- httpx = "^0.24.0"
26
+ httpx = ">=0.24.0,<2.0.0"
27
27
  openai = "^1.0.0"
28
28
  python-dotenv = "^1.0.0"
29
29
  tenacity = "^8.0.0"
@@ -39,6 +39,10 @@ jupyter = "^1.0.0"
39
39
  twine = "^6.1.0"
40
40
  ipython = "^9.4.0"
41
41
  ipykernel = "^6.29.5"
42
+ sphinx = "^7.0.0"
43
+ sphinx-rtd-theme = "^2.0.0"
44
+ myst-parser = "^2.0.0"
45
+ sphinx-autodoc-typehints = "^1.24.0"
42
46
 
43
47
  [build-system]
44
48
  requires = ["poetry-core"]