Vertex AI와 Model Armor의 통합

Model Armor는 최소 기준 설정을 사용하거나 템플릿을 사용하여 Vertex AI에 직접 통합할 수 있습니다. Model Armor는 Vertex AI와 통합되어 Gemini 모델로 전송된 요청과 Gemini 모델에서 수신된 응답을 모두 검사합니다. 최저가 설정을 위반하는 트래픽을 검사하거나 차단합니다.

Model Armor는 Vertex AI의 Gemini API 내에서 generateContent 메서드에 대해 프롬프트 및 응답 보호를 제공합니다. 프롬프트 및 대답의 정리 결과를 확인하려면 Cloud Logging을 사용 설정해야 합니다.

시작하기 전에

Model Armor 사용자에게 Vertex AI 서비스 계정에 대한 권한을 부여합니다.

gcloud projects add-iam-policy-binding PROJECT_ID --member='serviceAccount:service-PROJECT_NUMBER@gcp-sa-aiplatform.iam.gserviceaccount.com' --role='roles/modelarmor.user'
  

다음을 바꿉니다.

  • PROJECT_ID: Google Cloud 프로젝트 ID입니다.
  • PROJECT_NUMBER: Google Cloud 프로젝트 번호입니다.

최소 기준 설정 구성

최소 기준 설정을 사용하여 Model Armor 템플릿의 최소 탐지 기준점을 구성합니다. 이 설정은 모든 새 템플릿과 수정된 템플릿이 최소 기준 설정 요구사항을 충족하는지 확인합니다.

Model Armor 및 Vertex AI 통합을 사용 설정하려면 API 또는 Google Cloud 콘솔을 사용하여 프로젝트 수준에서만 최소 기준 설정을 설정하면 됩니다.

최소 기준 설정을 구성하려면 최소 기준 설정 구성을 참고하세요.

Vertex AI 통합으로 최소 기준 설정을 구성하려면 다음 명령어를 실행하세요.

  curl -X PATCH \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -d '{"filterConfig" : {}, "integratedServices": "AI_PLATFORM", "aiPlatformFloorSetting":{"inspect_only":true, "enableCloudLogging":true}}' \
      "https://modelarmor.googleapis.com/v1/projects/PROJECT_ID/locations/global/floorSetting"

PROJECT_ID를 최소 기준 설정 프로젝트의 ID로 바꿉니다.

Vertex AI 삭제를 사용하도록 최소 기준 설정을 구성하면 Model Armor에서 지정된 필터 설정을 사용하여 프로젝트의 Gemini 엔드포인트에 대한 모든 generateContent API 호출을 삭제합니다.

다음 코드 샘플은 generateContent 메서드를 사용하는 방법을 보여줍니다.

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/gemini-2.0-flash-001:generateContent" -d '{
"contents": [
    {
        "role": "user",
        "parts": [
            {
                "text": ""
            }
        ]
    }
]
, "generationConfig": {
    "responseModalities": ["TEXT"]
    ,"temperature": 0.2
    ,"maxOutputTokens": 1024
    ,"topP": 0.8
}
}'

다음을 바꿉니다.

  • PROJECT_ID: Google Cloud 프로젝트 ID입니다.
  • LOCATION: Gemini 엔드포인트의 Google Cloud 위치입니다. 지원되는 위치는 Model Armor API의 위치를 참조하세요.

다음 코드 샘플은 generateContent 메서드의 응답을 보여줍니다.

{
  "promptFeedback": {
    "blockReason": "MODEL_ARMOR",
    "blockReasonMessage": "Blocked by Floor Setting. The prompt violated Responsible AI Safety settings (Harassment, Dangerous), Prompt Injection and Jailbreak filters."
  },
  "usageMetadata": {
    "trafficType": "ON_DEMAND"
  },
  "modelVersion": "gemini-2.0-flash-001",
  "createTime": "2025-03-26T13:14:36.961184Z",
  "responseId": "vP3jZ6DVOqLKnvgPqZL-8Ao"
}

최소 기준 설정의 시행 유형 정의

Model Armor가 감지를 처리하는 방식을 구성하려면 시행 유형을 설정하세요. 다음 예시는 Inspect and block 시행 유형이 있는 바닥 설정 구성을 보여줍니다.

export FLOOR_SETTING='{
  "filter_config": {
    "rai_settings": {
      "rai_filters": {
        "filter_type": "HATE_SPEECH",
        "confidence_level": "LOW_AND_ABOVE"
      },
      "rai_filters": {
        "filter_type": "DANGEROUS",
        "confidence_level": "LOW_AND_ABOVE"
      },
    "rai_filters": {
        "filter_type": "SEXUALLY_EXPLICIT",
        "confidence_level": "LOW_AND_ABOVE"
      },
      "rai_filters": {
        "filter_type": "HARASSMENT",
        "confidence_level": "LOW_AND_ABOVE"
      }
    },
    "sdpSettings": {
      "basicConfig": {
        "filterEnforcement": "ENABLED"
      }
    },
    "piAndJailbreakFilterSettings": {
       "filterEnforcement": "ENABLED",
       "confidenceLevel": "LOW_AND_ABOVE"
     },
     "maliciousUriFilterSettings": {
       "filterEnforcement": "ENABLED"
     }
  },
  "integratedServices": [
      "AI_PLATFORM"
   ],
  "aiPlatformFloorSetting": {
    "inspectAndBlock": true,
    "enableCloudLogging": true
  },
  "enable_floor_setting_enforcement": "true"
}'

curl -X POST \
    -d "$FLOOR_SETTING"  \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    "https://modelarmor.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/floorSetting"

다음을 바꿉니다.

  • PROJECT_ID: 최소 기준 설정의 프로젝트 ID입니다.
  • LOCATION: 최소 기준 설정의 위치입니다.

Model Armor 템플릿 구성

Model Armor 템플릿을 사용하여 Model Armor를 Vertex AI와 통합할 수도 있습니다. 템플릿을 사용하면 Model Armor가 프롬프트와 응답을 검사하는 방식을 구성하고 보안 필터 구성을 정의할 수 있습니다.

먼저 템플릿을 만든 다음 이러한 템플릿을 Gemini의 generateContent 메서드와 함께 사용해야 합니다. 템플릿에 대한 자세한 내용은 Model Armor 템플릿 만들기 및 관리를 참조하세요.

Model Armor 템플릿을 구성한 후 generateContent 메서드를 사용하여 Gemini API를 호출할 때 템플릿 ID를 파라미터로 전달합니다. Vertex AI는 처리를 위해 Model Armor로 요청을 라우팅합니다.

다음 코드 샘플은 generateContent 메서드에 대한 요청을 보여줍니다.

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/publishers/google/models/gemini-2.0-flash-001:generateContent" -d '{
"contents": [
    {
        "role": "user",
        "parts": [
            {
                "text": ""
            }
        ]
    }
]
, "generationConfig": {
    "responseModalities": ["TEXT"]
    ,"temperature": 0.2
    ,"maxOutputTokens": 1024
    ,"topP": 0.8
},
 "model_armor_config": {
        "prompt_template_name": "projects/PROJECT_ID/locations/LOCATION/templates/TEMPLATE_ID",
"response_template_name": "projects/PROJECT_ID/locations/LOCATION/templates/TEMPLATE_ID"
    }
}'

다음을 바꿉니다.

  • PROJECT_ID: Google Cloud 프로젝트 ID
  • LOCATION: Gemini 엔드포인트의 Google Cloud 위치입니다. 지원되는 위치는 us-central1, us-east4, us-west1, europe-west4입니다.
  • TEMPLATE_ID: Model Armor 템플릿 ID입니다.

다음 코드 샘플은 generateContent 메서드의 응답을 보여줍니다.

{
  "promptFeedback": {
    "blockReason": "MODEL_ARMOR",
    "blockReasonMessage": "Blocked by Floor Setting. The prompt violated Responsible AI Safety settings (Harassment, Dangerous), Prompt Injection and Jailbreak filters."
  },
  "usageMetadata": {
    "trafficType": "ON_DEMAND"
  },
  "modelVersion": "gemini-2.0-flash-001",
  "createTime": "2025-03-26T13:14:36.961184Z",
  "responseId": "vP3jZ6DVOqLKnvgPqZL-8Ao"
}

고려사항

Vertex AI와 Model Armor를 통합할 때는 다음 사항을 고려하세요.

  • 익명화 템플릿의 Sensitive Data Protection 수정은 지원되지 않습니다.
  • 문서가 포함된 프롬프트와 대답의 삭제는 지원되지 않습니다.
  • Vertex AI는 다음 조건에서 Model Armor 삭제 단계를 건너뛰고 요청 처리를 계속합니다.

    • Vertex AI가 있는 리전에서는 Model Armor를 사용할 수 없습니다.
    • Model Armor에 일시적으로 연결할 수 없습니다.
    • Model Armor 내에서 오류가 발생합니다.

    이러한 모든 인스턴스는 프롬프트 및 응답 정리 없이 요청이 계속되므로 때때로 스크린되지 않은 프롬프트나 응답을 노출할 수 있습니다.