Skip to content

Populate safety attributes on Anthropic output

Tan Le requested to merge 319-safety-attributes-anthropic into main

What does this merge request do and why?

This fixes an issue with attempting to extract nullable safety attributes for code generations. safety_attributes is now a required field for TextGenModelOutput and can't not be None. This helps to ensure a consistent interface for the caller and avoid multiple layers of None value checks.

How to set up and validate locally

  1. Check out to this merge request's branch.
  2. Configure ANTHROPIC_API_KEY in the .env file.
  3. Ensure a local Docker image built successfully.
    docker buildx build --platform linux/amd64 -t ai-gateway:test .
  4. Run a local service on Docker.
    docker run --platform linux/amd64 --rm \
      -p 5052:5052 \
      -e AUTH_BYPASS_EXTERNAL=true \
      -v $PWD:/app -it ai-gateway:test
  5. Execute the following cURL.
    curl --request POST \
      --url http://codesuggestions.gdk.test:5052/v2/code/generations \
      --header 'Content-Type: application/json' \
      --data '{
      "current_file": {
        "file_name": "snippets/python/censor.py",
        "content_above_cursor": "# Hello world",
        "content_below_cursor": "\n"
      },
      "prompt_version": 2,
      "prompt": "Human: Write a wonderful function\n",
      "model_provider": "anthropic"
    }
    '
  6. Confirm 200 HTTP response and no error in the logs.

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.

Closes #319 (closed)

Edited by Tan Le

Merge request reports