-
Notifications
You must be signed in to change notification settings - Fork 235
feat | LAY-907 Updated docs and examples. Pagination now set min page… #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/usr/bin/env -S poetry run python | ||
|
|
||
| import asyncio | ||
|
|
||
| from atlas import AsyncAtlas | ||
|
|
||
|
|
||
| async def main(): | ||
| # Construct async client | ||
| client = AsyncAtlas() | ||
|
|
||
| # --- Models | ||
| models = await client.models.get() | ||
| print(f"Found {len(models)} models") | ||
|
|
||
| # --- Benchmarks | ||
| benchmarks = await client.benchmarks.get() | ||
| print(f"Found {len(benchmarks)} benchmarks") | ||
|
|
||
| # --- Create evaluation | ||
| evaluation = await client.evaluations.create( | ||
| model=models[0], | ||
| benchmark=benchmarks[0], | ||
| ) | ||
| print(f"Created evaluation {evaluation.id}, status={evaluation.status}") | ||
|
|
||
| # --- Wait for completion | ||
| evaluation = await client.evaluations.wait_for_completion( | ||
| evaluation, | ||
| interval_seconds=10, | ||
| # Keep in mind that the evaluation will take a while to complete, so you may want to increase the timeout | ||
| # or grab the evaluation id and check the status later | ||
| timeout_seconds=600, # 10 minutes | ||
| ) | ||
| print(f"Evaluation {evaluation.id} finished with status={evaluation.status}") | ||
|
|
||
| # --- All results at once without pagination | ||
| results = await client.results.get_all(evaluation=evaluation) | ||
| print(f"Found {len(results)} results") | ||
| print(results) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/usr/bin/env -S poetry run python | ||
|
|
||
| import asyncio | ||
|
|
||
| from atlas import AsyncAtlas | ||
|
|
||
|
|
||
| async def main(): | ||
| # Construct async client | ||
| client = AsyncAtlas() | ||
|
|
||
| # --- Get benchmarks by name | ||
| benchmark_name = "mmlu" | ||
| benchmarks = await client.benchmarks.get(name=benchmark_name) | ||
| print(f"Found {len(benchmarks)} benchmarks with name {benchmark_name}") | ||
| print(benchmarks) | ||
|
|
||
| # --- Get benchmarks by type | ||
| benchmark_type = "public" | ||
| benchmarks = await client.benchmarks.get(type=benchmark_type) | ||
| print(f"Found {len(benchmarks)} benchmarks with type {benchmark_type}") | ||
| print(benchmarks) | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env -S poetry run python | ||
|
|
||
| import asyncio | ||
|
|
||
| from atlas import AsyncAtlas | ||
|
|
||
|
|
||
| async def main(): | ||
| # Construct async client | ||
| client = AsyncAtlas() | ||
|
|
||
| # --- Get evaluation by id | ||
| evaluation_id = "eval_123" | ||
| evaluation = await client.evaluations.get(evaluation_id) | ||
| print(f"Found evaluation {evaluation.id}") | ||
| print(evaluation) | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env -S poetry run python | ||
|
|
||
| import asyncio | ||
|
|
||
| from atlas import AsyncAtlas | ||
|
|
||
|
|
||
| async def main(): | ||
| # Construct async client | ||
| client = AsyncAtlas() | ||
|
|
||
| # --- Get models by name | ||
| model_name = "gpt-4o" | ||
| models = await client.models.get(name=model_name) | ||
| print(f"Found {len(models)} models with name {model_name}") | ||
| print(models) | ||
|
|
||
| # --- Get models by company | ||
| company_names = ["openai", "anthropic"] | ||
| models = await client.models.get(companies=company_names) | ||
| print(f"Found {len(models)} models with companies {company_names}") | ||
| print(models) | ||
|
|
||
| # --- Get models by region | ||
| region_names = ["usa"] | ||
| models = await client.models.get(regions=region_names) | ||
| print(f"Found {len(models)} models with regions {region_names}") | ||
| print(models) | ||
|
|
||
| # --- Get models by type | ||
| model_type = "public" | ||
| models = await client.models.get(type=model_type) | ||
| print(f"Found {len(models)} models with type {model_type}") | ||
| print(models) | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have another example To show users they don't have to handle pagination for results themselves if they just want to fetch all results. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/usr/bin/env -S poetry run python | ||
|
|
||
| import asyncio | ||
|
|
||
| from atlas import AsyncAtlas | ||
|
|
||
|
|
||
| async def main(): | ||
| # Construct async client | ||
| client = AsyncAtlas() | ||
|
|
||
| # --- Models | ||
| models = await client.models.get() | ||
| print(f"Found {len(models)} models") | ||
|
|
||
| # --- Benchmarks | ||
| benchmarks = await client.benchmarks.get() | ||
| print(f"Found {len(benchmarks)} benchmarks") | ||
|
|
||
| # --- Create evaluation | ||
| evaluation = await client.evaluations.create( | ||
| model=models[0], | ||
| benchmark=benchmarks[0], | ||
| ) | ||
| print(f"Created evaluation {evaluation.id}, status={evaluation.status}") | ||
|
|
||
| # --- Wait for completion | ||
| evaluation = await client.evaluations.wait_for_completion( | ||
| evaluation, | ||
| interval_seconds=10, | ||
| # Keep in mind that the evaluation will take a while to complete, so you may want to increase the timeout | ||
| # or grab the evaluation id and check the status later | ||
| timeout_seconds=600, # 10 minutes | ||
| ) | ||
| print(f"Evaluation {evaluation.id} finished with status={evaluation.status}") | ||
|
|
||
| # --- Results with pagination | ||
| if evaluation.is_success: | ||
| print("Fetching all results with pagination...") | ||
|
|
||
| all_results = [] | ||
| page = 1 | ||
| page_size = 50 | ||
|
|
||
| while True: | ||
| print(f"Fetching page {page} (page size: {page_size})...") | ||
|
|
||
| # Get results for current page | ||
| results_data = await client.results.get_by_id( | ||
| evaluation_id=evaluation.id, | ||
| page=page, | ||
| page_size=page_size | ||
| ) | ||
|
|
||
| if not results_data or not results_data.results: | ||
| print("No more results to fetch") | ||
| break | ||
|
|
||
| # Add current page results to our collection | ||
| all_results.extend(results_data.results) | ||
|
|
||
| # Show progress | ||
| if page == 1: | ||
| total_count = results_data.pagination.total_count | ||
| total_pages = results_data.pagination.total_pages | ||
| print(f"Total results: {total_count:,}") | ||
| print(f"Total pages: {total_pages}") | ||
|
|
||
| print(f"Page {page}: Retrieved {len(results_data.results)} results") | ||
| print(f"Running total: {len(all_results):,} results") | ||
|
|
||
| # Check if we've reached the last page | ||
| if page >= results_data.pagination.total_pages: | ||
| print("Reached last page") | ||
| break | ||
|
|
||
| page += 1 | ||
|
|
||
| # Summary of all results | ||
| print(f"\n=== PAGINATION COMPLETE ===") | ||
| print(f"Total results collected: {len(all_results):,}") | ||
|
|
||
| if all_results: | ||
| # Calculate some basic statistics | ||
| correct_answers = sum(1 for r in all_results if r.score > 0.5) | ||
| accuracy = correct_answers / len(all_results) | ||
| avg_score = sum(r.score for r in all_results) / len(all_results) | ||
|
|
||
| print(f"Overall accuracy: {accuracy:.1%} ({correct_answers:,}/{len(all_results):,})") | ||
| print(f"Average score: {avg_score:.3f}") | ||
|
|
||
| # Show a few example results | ||
| print(f"\nFirst 3 results:") | ||
| for i, result in enumerate(all_results[:3], 1): | ||
| print(f" {i}. Score: {result.score:.3f}, Subset: {result.subset}") | ||
| print(f" Prompt: {result.prompt[:100]}...") | ||
| print(f" Response: {result.result[:100]}...") | ||
| print() | ||
|
|
||
| else: | ||
| print("Evaluation did not succeed, no results to show.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an example using the
get_all_results_asyncmethod showing how to async fetch all results (without them having to pagniate)?I think this would be more helpful than having multiple pagination examples.