API Reference
This page contains the complete API documentation for LLM Batch Helper.
Core Functions
- llm_batch_helper.process_prompts_batch(prompts=None, input_dir=None, config=None, provider='openai', desc='Processing prompts', cache_dir=None, force=False)[source]
Process a batch of prompts through the LLM (synchronous version).
This is the main user-facing function that works in both regular Python scripts and Jupyter notebooks without requiring async/await syntax.
- Parameters:
prompts (List[str | Tuple[str, str] | Dict[str, Any]] | None) – Optional list of prompts in any supported format (string, tuple, or dict)
input_dir (str | None) – Optional path to directory containing prompt files
config (LLMConfig) – LLM configuration
provider (str) – LLM provider to use (“openai”, “together”, “openrouter”, or “gemini”)
desc (str) – Description for progress bar
cache_dir (str | None) – Optional directory for caching responses
force (bool) – If True, force regeneration even if cached response exists
- Returns:
Dict mapping prompt IDs to their responses, ordered by input sequence
- Return type:
Note
Either prompts or input_dir must be provided, but not both. Results are returned in the same order as the input prompts.
Example
>>> from llm_batch_helper import LLMConfig, process_prompts_batch >>> config = LLMConfig(model_name="gpt-4o-mini") >>> results = process_prompts_batch( ... prompts=["What is 2+2?", "What is the capital of France?"], ... config=config, ... provider="openai" ... ) >>> # Results will be in the same order as input prompts
Configuration
Caching
Input Handlers
- llm_batch_helper.read_prompt_files(input_dir)[source]
Read all text files from input directory and return as (filename, content) pairs.
- llm_batch_helper.read_prompt_list(input_source)[source]
Read prompts from a list of various formats.
- Parameters:
input_source (List[str | Tuple[str, str] | Dict[str, Any]]) – List of prompts in any of these formats: - str: The prompt text (will use hash as ID) - tuple: (prompt_id, prompt_text) - dict: {“id”: prompt_id, “text”: prompt_text}
- Returns:
List of (prompt_id, prompt_text) tuples
- Return type:
Provider Functions
Internal provider functions (for advanced users):
- llm_batch_helper.providers.log_retry_attempt(retry_state)[source]
Custom logging function for retry attempts.
- async llm_batch_helper.providers.get_llm_response_with_internal_retry(prompt_id, prompt, config, provider, cache=None, force=False)[source]
- async llm_batch_helper.providers.process_prompts_batch_async(prompts=None, input_dir=None, config=None, provider='openai', desc='Processing prompts', cache_dir=None, force=False)[source]
Process a batch of prompts through the LLM.
- Parameters:
prompts (List[str | Tuple[str, str] | Dict[str, Any]] | None) – Optional list of prompts in any supported format (string, tuple, or dict)
input_dir (str | None) – Optional path to directory containing prompt files
config (LLMConfig) – LLM configuration
provider (str) – LLM provider to use (“openai”, “together”, “openrouter”, or “gemini”)
desc (str) – Description for progress bar
cache_dir (str | None) – Optional directory for caching responses
force (bool) – If True, force regeneration even if cached response exists
- Returns:
Dict mapping prompt IDs to their responses, ordered by input sequence
- Return type:
Note
Either prompts or input_dir must be provided, but not both. Results are returned in the same order as the input prompts.
- llm_batch_helper.providers.process_prompts_batch(prompts=None, input_dir=None, config=None, provider='openai', desc='Processing prompts', cache_dir=None, force=False)[source]
Process a batch of prompts through the LLM (synchronous version).
This is the main user-facing function that works in both regular Python scripts and Jupyter notebooks without requiring async/await syntax.
- Parameters:
prompts (List[str | Tuple[str, str] | Dict[str, Any]] | None) – Optional list of prompts in any supported format (string, tuple, or dict)
input_dir (str | None) – Optional path to directory containing prompt files
config (LLMConfig) – LLM configuration
provider (str) – LLM provider to use (“openai”, “together”, “openrouter”, or “gemini”)
desc (str) – Description for progress bar
cache_dir (str | None) – Optional directory for caching responses
force (bool) – If True, force regeneration even if cached response exists
- Returns:
Dict mapping prompt IDs to their responses, ordered by input sequence
- Return type:
Note
Either prompts or input_dir must be provided, but not both. Results are returned in the same order as the input prompts.
Example
>>> from llm_batch_helper import LLMConfig, process_prompts_batch >>> config = LLMConfig(model_name="gpt-4o-mini") >>> results = process_prompts_batch( ... prompts=["What is 2+2?", "What is the capital of France?"], ... config=config, ... provider="openai" ... ) >>> # Results will be in the same order as input prompts