RequestQueue Classes
langbatch.request_queues.RequestQueue
Bases: ABC
RequestQueue is an abstract class for request queues. Implementations should provide a way to add and retrieve requests.
Used in BatchDispatcher
to get requests.
Usage:
request_queue = InMemoryRequestQueue()
request_queue.add_requests([
[
{"role": "user", "content": "How can I learn Python?"}
],
[
{"role": "user", "content": "Who is the first president of the United States?"},
{"role": "assistant", "content": "George Washington"},
{"role": "user", "content": "Second?"}
]
])
batch_dispatcher = BatchDispatcher(
batch_handler=batch_handler,
queue=request_queue
)
asyncio.create_task(batch_dispatcher.run())
Source code in langbatch\request_queues.py
add_requests
abstractmethod
Info
Please make sure to pass the the correct type of requests to the queue as per the type of Batch you are going to use. For Example, if you are using ChatCompletionBatch as your batch type, then you should pass the requests in the same format as the ChatCompletionBatch.create() expects. For EmbeddingBatch, refer EmbeddingBatch.create()
langbatch.request_queues.InMemoryRequestQueue
Bases: RequestQueue
Source code in langbatch\request_queues.py
add_requests
langbatch.request_queues.RedisRequestQueue
Bases: RequestQueue
RedisRequestQueue is a request queue that uses a Redis list to store requests.
Usage:
import os
import redis
REDIS_URL = os.environ.get('REDIS_URL')
redis_client = redis.from_url(REDIS_URL)
request_queue = RedisRequestQueue(redis_client, queue_name='turbo_requests')
request_queue.add_requests([
[
{"role": "user", "content": "How can I learn Python?"}
],
[
{"role": "user", "content": "Who is the first president of the United States?"},
{"role": "assistant", "content": "George Washington"},
{"role": "user", "content": "Second?"}
]
])