diff --git a/.github/scripts/verify-model.sh b/.github/scripts/verify-model.sh new file mode 100755 index 0000000..fc35ba5 --- /dev/null +++ b/.github/scripts/verify-model.sh @@ -0,0 +1,78 @@ +#!/bin/bash +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo "🔍 Verifying C1 model in route.ts..." + +# Check if THESYS_API_KEY is set +if [ -z "$THESYS_API_KEY" ]; then + echo -e "${RED}❌ Error: THESYS_API_KEY environment variable is not set${NC}" + echo "Please set the THESYS_API_KEY secret in your GitHub repository settings." + exit 1 +fi + +# Extract the model from route.ts +ROUTE_FILE="src/app/api/ask/route.ts" + +if [ ! -f "$ROUTE_FILE" ]; then + echo -e "${RED}❌ Error: $ROUTE_FILE not found${NC}" + exit 1 +fi + +# Extract model using grep and sed +MODEL=$(grep -o 'model: "[^"]*"' "$ROUTE_FILE" | sed 's/model: "\(.*\)"/\1/') + +if [ -z "$MODEL" ]; then + echo -e "${RED}❌ Error: Could not extract model from $ROUTE_FILE${NC}" + exit 1 +fi + +echo -e "${YELLOW}📝 Found model: $MODEL${NC}" + +# Fetch valid models from API +echo "🌐 Fetching valid models from Thesys API..." + +API_RESPONSE=$(curl -s -X 'GET' \ + 'https://api.thesys.dev/v1/embed/models' \ + -H 'accept: application/json' \ + -H "Authorization: Bearer $THESYS_API_KEY") + +# Check if API call was successful +if [ -z "$API_RESPONSE" ]; then + echo -e "${RED}❌ Error: Failed to fetch models from API${NC}" + exit 1 +fi + +# Extract model IDs from response +VALID_MODELS=$(echo "$API_RESPONSE" | grep -o '"id":"[^"]*"' | sed 's/"id":"\(.*\)"/\1/') + +if [ -z "$VALID_MODELS" ]; then + echo -e "${RED}❌ Error: Could not parse valid models from API response${NC}" + exit 1 +fi + +# Check if the model is in the list of valid models +if echo "$VALID_MODELS" | grep -q "^${MODEL}$"; then + echo -e "${GREEN}✅ Success: Model '$MODEL' is valid!${NC}" + echo "" + echo "Valid models include:" + echo "$VALID_MODELS" | head -10 + if [ $(echo "$VALID_MODELS" | wc -l) -gt 10 ]; then + echo "... and $(($(echo "$VALID_MODELS" | wc -l) - 10)) more" + fi + exit 0 +else + echo -e "${RED}❌ Error: Model '$MODEL' is not in the list of valid models${NC}" + echo "" + echo "Available models:" + echo "$VALID_MODELS" + echo "" + echo "Please update the model in $ROUTE_FILE to one of the valid models above." + exit 1 +fi + diff --git a/.github/workflows/verify-model.yml b/.github/workflows/verify-model.yml new file mode 100644 index 0000000..4423748 --- /dev/null +++ b/.github/workflows/verify-model.yml @@ -0,0 +1,28 @@ +name: Verify C1 Model + +on: + pull_request: + types: [opened, synchronize, reopened] + branches: + - main + - master + +jobs: + verify-model: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Verify model is valid + env: + THESYS_API_KEY: ${{ secrets.THESYS_API_KEY }} + run: | + chmod +x .github/scripts/verify-model.sh + .github/scripts/verify-model.sh + diff --git a/README.md b/README.md index f3eeb4d..9f3f68e 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,42 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the You can start editing your responses by modifying the system prompt in `src/app/api/chat/route.ts`. +## Model Verification + +This template includes a GitHub Action that automatically verifies the C1 model used in `src/app/api/ask/route.ts` is valid according to the Thesys API. This workflow runs on every pull request to ensure you're using a supported model. + +### Setting up the GitHub Action + +To enable this workflow in your repository: + +1. Go to your repository's **Settings** → **Secrets and variables** → **Actions** +2. Add a new repository secret named `THESYS_API_KEY` with your Thesys API key value +3. The workflow will now run automatically on all pull requests + +The workflow will: +- Extract the model name from `src/app/api/ask/route.ts` +- Fetch the list of valid models from the Thesys API +- Verify that your model is in the list of supported models +- Block the PR from merging if an invalid model is detected + +You can view available models by running the verification script locally: + +```bash +THESYS_API_KEY= .github/scripts/verify-model.sh +``` + +### Making Model Verification Required (Recommended) + +To require this check to pass before merging PRs: + +1. Go to your repository's **Settings** → **Branches** +2. Add or edit a branch protection rule for your main branch (e.g., `main` or `master`) +3. Enable **Require status checks to pass before merging** +4. Search for and select **Verify C1 Model** in the status checks list +5. Save the protection rule + +This ensures that only valid C1 models can be merged into your main branch. + ## Learn More To learn more about Thesys C1, take a look at the [C1 Documentation](https://docs.thesys.dev) - learn about Thesys C1.