From df0330b97fdfda5b8eccbe6c836692bd1eca1593 Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Sun, 18 May 2025 15:15:14 -0600 Subject: [PATCH] Flask API --- .github/workflows/llmsecops-cicd.llm.yml | 21 +++++++------ .github/workflows/run_server.sh | 39 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 9 deletions(-) create mode 100755 .github/workflows/run_server.sh diff --git a/.github/workflows/llmsecops-cicd.llm.yml b/.github/workflows/llmsecops-cicd.llm.yml index be9ece60d..3cf4218cf 100644 --- a/.github/workflows/llmsecops-cicd.llm.yml +++ b/.github/workflows/llmsecops-cicd.llm.yml @@ -27,20 +27,23 @@ jobs: pip install huggingface-hub[cli] huggingface-cli download microsoft/Phi-3-mini-4k-instruct-onnx --include cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/* --local-dir ${{ github.workspace }}/tests/llm + - name: 'run HTTP server and test REST API' + working-directory: ${{ github.workspace }}/.github/workflows + shell: bash + run: | + ./run_server.sh + - name: 'set up garak' run: | pip install garak - - name: 'run HTTP server and call REST API' - run: | - python -m src.api.controller - sleep 2 - curl -X POST -i localhost:9998/api/conversations -d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' -H "Content-Type: application/json" || exit 1 - echo - + - name: 'run garak tests' + working-directory: ${{ github.workspace }}/src/tools + shell: bash + run: | garak -v \ - --config ${{ github.workspace }}/tests/tools/garak.config.yml \ - --generator_option_file ${{ github.workspace }}/tests/tools/garak.rest.llm.json \ + --config garak.config.yml \ + --generator_option_file garak.rest.llm.json \ --model_type=rest \ --parallel_attempts 32 diff --git a/.github/workflows/run_server.sh b/.github/workflows/run_server.sh new file mode 100755 index 000000000..a7cbf6709 --- /dev/null +++ b/.github/workflows/run_server.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Start Flask server in the background +python -m src.api.controller & +SERVER_PID=$! + +# Function to check if server is up +wait_for_server() { + echo "Waiting for Flask server to start..." + local max_attempts=30 + local attempt=0 + + while [ $attempt -lt $max_attempts ]; do + if curl -s http://localhost:9998/ > /dev/null 2>&1; then + echo "Server is up!" + return 0 + fi + + attempt=$((attempt + 1)) + echo "Attempt $attempt/$max_attempts - Server not ready yet, waiting..." + sleep 1 + done + + echo "Server failed to start after $max_attempts attempts" + kill $SERVER_PID + return 1 +} + +# Wait for server to be ready +wait_for_server || exit 1 + +# Make the actual request once server is ready +echo "Making API request..." +curl -X POST -i localhost:9998/api/conversations \ + -d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' \ + -H "Content-Type: application/json" || exit 1 +echo + +exit 0 \ No newline at end of file