A small demo showing how to batch multiple queries into a single LLM request to save cost and reduce latency.
The script assigns a unique ID to each query, sends them in a single request, and expects the model to respond with ID:answer lines.
- Install dependencies:
pip install -r requirements.txt- Configure the LLM endpoint URL in
.env(or via theURLenv var):
URL=
If your endpoint requires an API key, set it via one of:
OPENAI_API_KEYAPI_KEY
Run the script with one or more --query arguments:
python main.py --query "What is the capital of France?" --query "What is the largest mammal?"Or run the built-in example:
python main.py --exampleOr load queries from a file (one query per line):
python main.py --file queries.txt- The script assumes the endpoint supports an OpenAI-compatible chat completions API (
/chat/completions). - The output is printed twice: raw model output first, then parsed
ID:answerpairs.