This example demonstrates how to deploy a simple reward function (dummy_rewards.py) to Google Cloud Run using the eval-protocol CLI.
dummy_rewards.py: Contains a basichello_world_rewardfunction.rewardkit.example.yaml: An example configuration file foreval-protocol. You should copy this to the root of your project (where you'll runeval-protocolcommands) asrewardkit.yamland customize it.
- Google Cloud Platform (GCP) Account: You need an active GCP account with billing enabled.
gcloudCLI: Ensure the Google Cloud CLI is installed and authenticated (gcloud auth login,gcloud auth application-default login).- APIs Enabled: Make sure the following APIs are enabled in your GCP project:
- Cloud Build API
- Artifact Registry API
- Cloud Run Admin API
- Secret Manager API
- Permissions: The authenticated user/service account for
gcloudneeds sufficient permissions to manage these services (e.g., roles like "Cloud Build Editor", "Artifact Registry Administrator", "Cloud Run Admin", "Secret Manager Admin"). eval-protocolinstalled: Ensureeval-protocolis installed in your Python environment.
-
Navigate to this Example Directory: Open your terminal and change to this directory:
cd path/to/eval-protocol/examples/gcp_cloud_run_deployment_example -
Configure
rewardkit.yaml:- In this directory (
examples/gcp_cloud_run_deployment_example/), copyrewardkit.example.yamlto a new file namedrewardkit.yaml.cp rewardkit.example.yaml rewardkit.yaml
- Open the new
rewardkit.yamlfile and replace placeholders likeyour-gcp-project-id-herewith your actual GCP Project ID and desired region. For example:# rewardkit.yaml (example content after customization) gcp_cloud_run: project_id: "my-actual-gcp-project-123" region: "us-west1" # artifact_registry_repository: "my-custom-eval-repo" # Optional # default_auth_mode: "api-key" # Optional, defaults to api-key evaluator_endpoint_keys: {}
- When you run
eval-protocolcommands from this directory, it will automatically find and use thisrewardkit.yaml.
Note: If you prefer not to use a
rewardkit.yamlfile here, you can skip step 2 and instead provide all necessary GCP parameters (--gcp-project,--gcp-region) directly via CLI arguments in the deployment command below. - In this directory (
Ensure you are in the examples/gcp_cloud_run_deployment_example/ directory.
Run the following command:
eval-protocol deploy \
--id my-dummy-gcp-evaluator \
--target gcp-cloud-run \
--function-ref dummy_rewards.hello_world_reward \
--gcp-auth-mode api-key \
--verbose
# --force # Add this flag if you need to overwrite an existing evaluator with the same ID
# If you didn't configure rewardkit.yaml, add:
# --gcp-project YOUR_PROJECT_ID --gcp-region YOUR_REGIONExplanation:
--id my-dummy-gcp-evaluator: A unique ID for your evaluator.--target gcp-cloud-run: Specifies deployment to GCP Cloud Run.--function-ref dummy_rewards.hello_world_reward: The Python import path to your reward function. Sincedummy_rewards.pyis in the current directory (when running from here), this simple reference should work.--gcp-auth-mode api-key: Deploys the service with API key authentication (this is the default if not specified).eval-protocolwill generate a key, store it in GCP Secret Manager, and configure the service. The key will also be saved to your localrewardkit.yaml(in this directory) underevaluator_endpoint_keys.--verbose: Shows detailed output, includinggcloudcommands being executed.--force: (Optional) If an evaluator with the same--idalready exists, adding--forcewill delete the existing one before creating the new one. Without it, you'll get a conflict error if the ID is taken.
If successful, eval-protocol will:
- Create an Artifact Registry repository (if it doesn't exist, default:
eval-protocol-evaluators). - Build a Docker container with your reward function and push it to Artifact Registry.
- Create a GCP Secret to store the generated API key for your service.
- Deploy the container to Cloud Run, configured with the API key from Secret Manager.
- Register the deployed Cloud Run service URL as a remote evaluator with the Fireworks AI platform.
You will see the Cloud Run service URL and the API key (if newly generated) in the output. The API key will also be printed by the eval_protocol.generic_server.py when it starts up inside the Cloud Run container if RK_ENDPOINT_API_KEY is set.
You can test the deployed endpoint using curl or eval-protocol preview --remote-url <your-cloud-run-url>.
If using curl with API key auth:
# Get your API key from rewardkit.yaml or the deploy command output
API_KEY="your_generated_api_key"
SERVICE_URL="your_cloud_run_service_url"
curl -X POST "$SERVICE_URL/evaluate" \
-H "Content-Type: application/json" \
-H "X-Api-Key: $API_KEY" \
-d '{
"messages": [{"role": "user", "content": "Test"}],
"kwargs": {}
}'