Skip to content

Install Codeflash Github action #2195

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
48 changes: 48 additions & 0 deletions .github/workflows/codeflash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Codeflash Optimization
on:
pull_request:
paths:
- 'pydantic_ai_slim/pydantic_ai/**'
workflow_dispatch:
concurrency:
# Any new push to the PR will cancel the previous run, so that only the latest code is optimized
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
optimize:
name: Optimize new Python code
# Don't run codeflash on codeflash-ai[bot] commits, prevent duplicate optimizations
if: ${{ github.actor != 'codeflash-ai[bot]' }}
runs-on: ubuntu-latest
env:
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🐍 Setup UV
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: 📦 Install Dependencies
run: uv sync --frozen --all-extras --all-packages --group lint --group docs
- name: Functions to Optimize
id: discover_step
run: |
uv run python -c "
from codeflash.cli_cmds.cli import parse_args, process_pyproject_config
from codeflash.verification.verification_utils import TestConfig
from codeflash.discovery.functions_to_optimize import get_functions_to_optimize
import os
args = process_pyproject_config(parse_args())
t = TestConfig(tests_root=args.tests_root, tests_project_rootdir=args.test_project_root, project_root_path=args.project_root, test_framework=args.test_framework, pytest_cmd=args.pytest_cmd,)
f = get_functions_to_optimize(test_cfg=t, ignore_paths=args.ignore_paths, project_root=args.project_root, module_root=args.module_root,optimize_all=None, replay_test=None, file=None, only_get_this_function=None)
functions = ' '.join([fto.function_name for ftol in f[0].values() for fto in ftol])
open(os.environ.get('GITHUB_OUTPUT'), 'a').write(f'functions_to_optimize={functions}')
"
- name: ⚡️Codeflash Optimization
run: uv run codeflash optimize --only-functions ${{ steps.discover_step.outputs.functions_to_optimize }} -m pytest --inline-snapshot=disable tests/test_examples.py
2 changes: 2 additions & 0 deletions pydantic_ai_slim/pydantic_ai/profiles/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

def google_model_profile(model_name: str) -> ModelProfile | None:
"""Get the model profile for a Google model."""
import time
time.sleep(0.001)
return ModelProfile(
json_schema_transformer=GoogleJsonSchemaTransformer,
supports_json_schema_output=True,
Expand Down
1 change: 1 addition & 0 deletions pydantic_ai_slim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ dev = [
"boto3-stubs[bedrock-runtime]",
"strict-no-cover>=0.1.1",
"pytest-xdist>=3.6.1",
"codeflash>=0.15.5"
]

[tool.hatch.metadata]
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,10 @@ check-hidden = true
# Ignore "formatting" like **L**anguage
ignore-regex = '\*\*[A-Z]\*\*[a-z]+\b'
ignore-words-list = 'asend,aci'

[tool.codeflash]
module-root = "pydantic_ai_slim/pydantic_ai"
tests-root = "tests"
test-framework = "pytest"
ignore-paths = []
formatter-cmds = ["ruff check --exit-zero --fix $file", "ruff format $file"]
Loading
Loading