Query multiple models in parallel. Args: models: List of OpenRouter model identifiers messages: List of message dicts to send to each model Returns: Dict mapping model identifier to response dict (or None if failed)
(
models: List[str],
messages: List[Dict[str, str]]
)
| 54 | |
| 55 | |
| 56 | async def query_models_parallel( |
| 57 | models: List[str], |
| 58 | messages: List[Dict[str, str]] |
| 59 | ) -> Dict[str, Optional[Dict[str, Any]]]: |
| 60 | """ |
| 61 | Query multiple models in parallel. |
| 62 | |
| 63 | Args: |
| 64 | models: List of OpenRouter model identifiers |
| 65 | messages: List of message dicts to send to each model |
| 66 | |
| 67 | Returns: |
| 68 | Dict mapping model identifier to response dict (or None if failed) |
| 69 | """ |
| 70 | import asyncio |
| 71 | |
| 72 | # Create tasks for all models |
| 73 | tasks = [query_model(model, messages) for model in models] |
| 74 | |
| 75 | # Wait for all to complete |
| 76 | responses = await asyncio.gather(*tasks) |
| 77 | |
| 78 | # Map models to their responses |
| 79 | return {model: response for model, response in zip(models, responses)} |
no test coverage detected