BatchQueue Classes
langbatch.batch_queues.BatchQueue
Bases: ABC
Abstract class for batch queue. Implementations should provide a way to save and load batch queues.
Used in BatchHandler to save and load the batch queues.
Usage:
import asyncio
# Using default FileBatchQueue
file_batch_queue = FileBatchQueue("batch_queue.json")
batch_handler = BatchHandler(
batch_process_func=process_batch,
batch_type=OpenAIChatCompletionBatch,
batch_queue=file_batch_queue
)
asyncio.create_task(batch_handler.run())
# With custom batch queue
class MyCustomBatchQueue(BatchQueue):
def save(self, queue: Dict[str, List[str]]):
# Custom save logic
def load(self) -> Dict[str, List[str]]:
# Custom load logic
custom_batch_queue = MyCustomBatchQueue()
batch_handler = BatchHandler(
batch_process_func=process_batch,
batch_type=OpenAIChatCompletionBatch,
batch_queue=custom_batch_queue
)
asyncio.create_task(batch_handler.run())
Source code in langbatch\batch_queues.py
save
abstractmethod
langbatch.batch_queues.FileBatchQueue
Bases: BatchQueue
Batch queue that saves the queue to a file.
Usage:
queue = FileBatchQueue("batch_queue.json")
batch_handler = BatchHandler(
batch_process_func=process_batch,
batch_type=OpenAIChatCompletionBatch,
batch_queue=queue
)
asyncio.create_task(batch_handler.run())