Skip to content
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

multi-line prints in async def main are sometimes mis-indented #59

Open
dmontagu opened this issue Mar 25, 2025 · 0 comments
Open

multi-line prints in async def main are sometimes mis-indented #59

dmontagu opened this issue Mar 25, 2025 · 0 comments

Comments

@dmontagu
Copy link
Contributor

import asyncio
import time

from pydantic_evals import Case, Dataset

# Create a dataset with multiple test cases
dataset = Dataset(
    cases=[
        Case(
            name=f'case_{i}',
            inputs=i,
            expected_output=i * 2,
        )
        for i in range(5)
    ]
)


async def double_number(input_value: int) -> int:
    """Function that simulates work by sleeping for a second before returning double the input."""
    await asyncio.sleep(0.1)  # Simulate work
    return input_value * 2

async def main():
    # Run evaluation with unlimited concurrency
    t0 = time.time()
    report_default = await dataset.evaluate(double_number)
    print(f'Evaluation took less than 0.2s: {time.time() - t0 < 0.2}')
    #> Evaluation took less than 0.2s: True
    report_default.print()
"""
  Evaluation Summary:
     double_number
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID  ┃ Duration ┃
┡━━━━━━━━━━╇━━━━━━━━━━┩
│ case_0   │  101.0ms │
├──────────┼──────────┤
│ case_1   │  101.0ms │
├──────────┼──────────┤
│ case_2   │  101.0ms │
├──────────┼──────────┤
│ case_3   │  101.0ms │
├──────────┼──────────┤
│ case_4   │  101.0ms │
├──────────┼──────────┤
│ Averages │  101.0ms │
└──────────┴──────────┘
"""

    # Run evaluation with limited concurrency
    t0 = time.time()
    report_limited = await dataset.evaluate(double_number, max_concurrency=1)
    print(f'Evaluation took more than 0.5s: {time.time() - t0 > 0.5}')
    #> Evaluation took more than 0.5s: True
    report_limited.print()
"""
  Evaluation Summary:
     double_number
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ Case ID  ┃ Duration ┃
┡━━━━━━━━━━╇━━━━━━━━━━┩
│ case_0   │  101.0ms │
├──────────┼──────────┤
│ case_1   │  101.0ms │
├──────────┼──────────┤
│ case_2   │  101.0ms │
├──────────┼──────────┤
│ case_3   │  101.0ms │
├──────────┼──────────┤
│ case_4   │  101.0ms │
├──────────┼──────────┤
│ Averages │  101.0ms │
└──────────┴──────────┘
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant