97e91a83f3
Ruff / Ruff (push) Waiting to run
Test / Core Tests (push) Waiting to run
Test / Offline Coverage Tests (Python 3.10) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.11) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.12) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.13) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.9) (push) Waiting to run
Test / Full Coverage (Python 3.11) (push) Waiting to run
Test / Core Provider Tests (OpenAI) (push) Blocked by required conditions
Test / Core Provider Tests (Anthropic) (push) Blocked by required conditions
Test / Core Provider Tests (Google) (push) Blocked by required conditions
Test / Core Provider Tests (Other) (push) Blocked by required conditions
Test / Anthropic Tests (push) Blocked by required conditions
Test / Gemini Tests (push) Blocked by required conditions
Test / Google GenAI Tests (push) Blocked by required conditions
Test / Vertex AI Tests (push) Blocked by required conditions
Test / OpenAI Tests (push) Blocked by required conditions
Test / Writer Tests (push) Blocked by required conditions
Test / Auto Client Tests (push) Blocked by required conditions
ty / type-check (push) Waiting to run
31 lines
1003 B
Python
31 lines
1003 B
Python
"""
|
|
Utility functions for batch processing.
|
|
|
|
This module contains helper functions for filtering, extracting, and manipulating
|
|
batch results.
|
|
"""
|
|
|
|
from typing import cast
|
|
|
|
from .models import BatchResult, BatchSuccess, BatchError, T
|
|
|
|
|
|
def filter_successful(results: list[BatchResult]) -> list[BatchSuccess[T]]:
|
|
"""Filter to only successful results"""
|
|
return cast(list[BatchSuccess[T]], [r for r in results if r.success])
|
|
|
|
|
|
def filter_errors(results: list[BatchResult]) -> list[BatchError]:
|
|
"""Filter to only error results"""
|
|
return cast(list[BatchError], [r for r in results if not r.success])
|
|
|
|
|
|
def extract_results(results: list[BatchResult]) -> list[T]:
|
|
"""Extract just the result objects from successful results"""
|
|
return [cast(BatchSuccess[T], r).result for r in results if r.success]
|
|
|
|
|
|
def get_results_by_custom_id(results: list[BatchResult]) -> dict[str, BatchResult]:
|
|
"""Create a dictionary mapping custom_id to results"""
|
|
return {r.custom_id: r for r in results}
|