From a49c70389e7564b62125fde377b70418faed6688 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 11:44:22 +0100 Subject: [PATCH 01/11] [CI] Run examples in the CI to look for regressions --- .github/workflows/run_example_scripts.yaml | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/run_example_scripts.yaml diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml new file mode 100644 index 00000000..b2ff6af9 --- /dev/null +++ b/.github/workflows/run_example_scripts.yaml @@ -0,0 +1,50 @@ +name: Running the examples + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + run_examples: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8, 3.9, 3.10, 3.11, 3.12, 3.13] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Poetry + uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + virtualenvs-path: .venv + installer-parallel: true + + - name: Build and install client + run: | + poetry build + python3 -m pip install dist/mistralai-*.whl + + - name: Run the example scripts + run: | + for file in examples/*.py; do + if [ -f "$file" ] && [ "$file" != "examples/chatbot_with_streaming.py" ]; then + echo "Running $file" + MISTRAL_AGENT_ID="..." python3 "$file" > /dev/null + fi + done + env: + MISTRAL_AGENT_ID: ${{ secrets.CI_AGENT_ID }} + MISTRAL_API_KEY: ${{ secrets.CI_MISTRAL_API_KEY }} From 6cc7ca748e596a724648851d12408222680d6a32 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 11:50:58 +0100 Subject: [PATCH 02/11] Escape Python version and set fail-fast to false --- .github/workflows/run_example_scripts.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index b2ff6af9..e971b723 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -12,8 +12,9 @@ jobs: run_examples: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - python-version: [3.8, 3.9, 3.10, 3.11, 3.12, 3.13] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] steps: - name: Checkout code From b111e77ebda8d3ecb9243954037b6405c47212d4 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 11:59:57 +0100 Subject: [PATCH 03/11] Fix --- .github/workflows/run_example_scripts.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index e971b723..e6f46e3b 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -27,14 +27,10 @@ jobs: - name: Install Poetry uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1 - with: - virtualenvs-create: true - virtualenvs-in-project: true - virtualenvs-path: .venv - installer-parallel: true - name: Build and install client run: | + touch README-PYPI.md # Create this file since the client is not built from Speakeasy poetry build python3 -m pip install dist/mistralai-*.whl From 73b9df4c95737b318f888ef0866e44dcf72064ce Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 12:05:41 +0100 Subject: [PATCH 04/11] Pin poetry version --- .github/workflows/run_example_scripts.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index e6f46e3b..12836916 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -27,6 +27,8 @@ jobs: - name: Install Poetry uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1 + with: + version: ${{ matrix.python-version == '3.8' && '1.8.5' || '2.1.1' }} - name: Build and install client run: | From 4bbcd42235c0622d9093dc445b515c94d5ae8c58 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 12:20:56 +0100 Subject: [PATCH 05/11] Fix typo --- .github/workflows/run_example_scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index 12836916..bb048224 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -41,7 +41,7 @@ jobs: for file in examples/*.py; do if [ -f "$file" ] && [ "$file" != "examples/chatbot_with_streaming.py" ]; then echo "Running $file" - MISTRAL_AGENT_ID="..." python3 "$file" > /dev/null + python3 "$file" > /dev/null fi done env: From 2f147aa5befce6bd425c736385e35d104a8a10ad Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 12:23:30 +0100 Subject: [PATCH 06/11] Run all the examples scripts even if one fails --- .github/workflows/run_example_scripts.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index bb048224..a548361a 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -44,6 +44,8 @@ jobs: python3 "$file" > /dev/null fi done + # Run all the example scripts even if one fails + continue-on-error: true env: MISTRAL_AGENT_ID: ${{ secrets.CI_AGENT_ID }} MISTRAL_API_KEY: ${{ secrets.CI_MISTRAL_API_KEY }} From 6de1950f766c8eec9671c5e4f09e319cc494534d Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 12:36:35 +0100 Subject: [PATCH 07/11] Fail only at the end of the step --- .github/workflows/run_example_scripts.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index a548361a..aa0b7115 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -38,14 +38,21 @@ jobs: - name: Run the example scripts run: | + failed=0 for file in examples/*.py; do if [ -f "$file" ] && [ "$file" != "examples/chatbot_with_streaming.py" ]; then echo "Running $file" - python3 "$file" > /dev/null + # Do not fail if the script fails, but save it in the failed variable + python3 "$file" > /dev/null || true + if [ ${PIPESTATUS[0]} -ne 0 ]; then + failed=1 + fi fi done - # Run all the example scripts even if one fails - continue-on-error: true + # If one of the example script failed then exit + if [ $failed -ne 0 ]; then + exit 1 + fi env: MISTRAL_AGENT_ID: ${{ secrets.CI_AGENT_ID }} MISTRAL_API_KEY: ${{ secrets.CI_MISTRAL_API_KEY }} From 667e7ce427d4f92cee225cd8e5f877e583db88e9 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 13:50:45 +0100 Subject: [PATCH 08/11] Big brain time --- .github/workflows/run_example_scripts.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index aa0b7115..6d8780ef 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -43,10 +43,7 @@ jobs: if [ -f "$file" ] && [ "$file" != "examples/chatbot_with_streaming.py" ]; then echo "Running $file" # Do not fail if the script fails, but save it in the failed variable - python3 "$file" > /dev/null || true - if [ ${PIPESTATUS[0]} -ne 0 ]; then - failed=1 - fi + python3 "$file" > /dev/null || failed=1 fi done # If one of the example script failed then exit From 421a5300fbb3b5a1c1ab579a098644ce7c6addcd Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 14:57:42 +0100 Subject: [PATCH 09/11] Use several keys instead --- .github/workflows/run_example_scripts.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index 6d8780ef..af63b735 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -35,7 +35,12 @@ jobs: touch README-PYPI.md # Create this file since the client is not built from Speakeasy poetry build python3 -m pip install dist/mistralai-*.whl - + + - name: Set MISTRAL_API_KEY + run: | + VERSION=$(echo ${{ matrix.python-version }} | tr -d .) + echo "MISTRAL_API_KEY=${{ secrets[format('CI_MISTRAL_API_KEY_PYTHON_{0}', $VERSION)] }}" >> $GITHUB_ENV + - name: Run the example scripts run: | failed=0 @@ -52,4 +57,4 @@ jobs: fi env: MISTRAL_AGENT_ID: ${{ secrets.CI_AGENT_ID }} - MISTRAL_API_KEY: ${{ secrets.CI_MISTRAL_API_KEY }} + MISTRAL_API_KEY: ${{ env.MISTRAL_API_KEY }} From 0dc148b25b49f0f404079f23c58c5a1b50f0ff06 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 15:01:17 +0100 Subject: [PATCH 10/11] Fix typo --- .github/workflows/run_example_scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index af63b735..e2acc42d 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -39,7 +39,7 @@ jobs: - name: Set MISTRAL_API_KEY run: | VERSION=$(echo ${{ matrix.python-version }} | tr -d .) - echo "MISTRAL_API_KEY=${{ secrets[format('CI_MISTRAL_API_KEY_PYTHON_{0}', $VERSION)] }}" >> $GITHUB_ENV + echo "MISTRAL_API_KEY=${{ secrets[format('CI_MISTRAL_API_KEY_PYTHON_{0}', VERSION)] }}" >> $GITHUB_ENV - name: Run the example scripts run: | From bc6ded0521e9ff040aa70409663fc82cb20903f6 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Fri, 7 Mar 2025 15:10:19 +0100 Subject: [PATCH 11/11] Working script --- .github/workflows/run_example_scripts.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index e2acc42d..db0a30aa 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -36,10 +36,14 @@ jobs: poetry build python3 -m pip install dist/mistralai-*.whl - - name: Set MISTRAL_API_KEY + - name: Set VERSION run: | VERSION=$(echo ${{ matrix.python-version }} | tr -d .) - echo "MISTRAL_API_KEY=${{ secrets[format('CI_MISTRAL_API_KEY_PYTHON_{0}', VERSION)] }}" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Set MISTRAL_API_KEY using VERSION + run: | + echo "MISTRAL_API_KEY=${{ secrets[format('CI_MISTRAL_API_KEY_PYTHON_{0}', env.VERSION)] }}" >> $GITHUB_ENV - name: Run the example scripts run: |