Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/scripts/verify-model.sh
Original file line number Diff line number Diff line change
@@ -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

28 changes: 28 additions & 0 deletions .github/workflows/verify-model.yml
Original file line number Diff line number Diff line change
@@ -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

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your-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.
Expand Down