Model Armor 로깅 구성

이 문서에서는 다음 작업을 로깅하도록 Model Armor를 구성하는 방법을 설명합니다.

  • 템플릿을 생성, 업데이트 또는 삭제하는 작업
  • 사용자 프롬프트 또는 모델 응답을 정리하는 작업

Model Armor는 감사 로그를 사용하여 관리 및 리소스 관리 활동을 기록합니다. 자세한 내용은 Model Armor 감사 로깅 개요를 참고하세요.

시작하기 전에

이 페이지의 남은 태스크를 수행하기 전에 먼저 다음 태스크를 수행하세요.

필수 권한 얻기

Model Armor의 로깅을 구성하는 데 필요한 권한을 얻으려면 관리자에게 Model Armor 템플릿에 대한 Model Armor 관리자 (roles/modelarmor.admin) IAM 역할을 부여해 달라고 요청하세요. 역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.

API 사용 설정

Model Armor를 사용하려면 먼저 Model Armor API를 사용 설정해야 합니다.

콘솔

  1. Enable the Model Armor API.

    Enable the API

  2. Model Armor를 활성화할 프로젝트를 선택합니다.

gcloud

시작하기 전에 Model Armor API와 함께 Google Cloud CLI를 사용하여 다음 단계를 따르세요.

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 다음 명령어를 실행하여 Model Armor 서비스의 API 엔드포인트를 설정합니다.

    gcloud config set api_endpoint_overrides/modelarmor "https://modelarmor.LOCATION.rep.googleapis.com/"

    LOCATION을 Model Armor를 사용하려는 리전으로 바꿉니다.

  3. 다음 명령어를 실행하여 Model Armor를 사용 설정합니다.

      gcloud services enable modelarmor.googleapis.com --project=PROJECT_ID
       

    PROJECT_ID를 프로젝트의 ID로 바꿉니다.

    템플릿에서 로깅 구성

    템플릿은 다양한 안전 및 보안 카테고리의 필터와 기준점을 정의합니다. Model Armor 템플릿을 만들거나 업데이트할 때 Model Armor가 특정 작업을 로깅할지 여부를 지정할 수 있습니다. 템플릿 메타데이터에서 다음 플래그를 사용합니다.

    • log_template_operations: 템플릿 생성, 업데이트, 읽기, 삭제 작업의 로깅을 사용 설정하는 불리언 값입니다.
    • log_sanitize_operations: 정리 작업의 로깅을 사용 설정하는 불리언 값입니다. 로그에는 프롬프트와 응답, Model Armor의 평가 결과, 추가 메타데이터 필드가 포함됩니다.

    콘솔

    1. Google Cloud 콘솔에서 Model Armor 페이지로 이동합니다.

      Model Armor로 이동

    2. Model Armor를 활성화한 프로젝트가 표시되었는지 확인합니다.

    3. Model Armor 페이지에서 템플릿 만들기를 클릭합니다. 템플릿 만들기에 대한 자세한 내용은 Model Armor 템플릿 만들기를 참고하세요.

    4. 로깅 구성 섹션에서 로깅을 구성할 작업을 선택합니다.

    5. 만들기를 클릭합니다.

    REST

      curl -X POST \
          -d '{ "filterConfig": {}, "templateMetadata": { "logTemplateOperations": true, "logSanitizeOperations": true } }' \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $(gcloud auth print-access-token)" \
          "https://modelarmor.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/templates?template_id=TEMPLATE_ID"
    

    다음을 바꿉니다.

    • PROJECT_ID: 템플릿이 속한 프로젝트의 ID입니다.
    • LOCATION: 템플릿의 위치입니다.
    • TEMPLATE_ID: 템플릿의 ID입니다.

    Python

    이 코드를 실행하려면 먼저 Python 개발 환경을 설정하고 Model Armor Python SDK를 설치합니다.

       request = modelarmor_v1.CreateTemplateRequest(
         parent="projects/PROJECT_ID/locations/LOCATION",
         template_id="TEMPLATE_ID",
         template={
            "name": "projects/PROJECT_ID/locations/LOCATION/templates/TEMPLATE_ID",
            "filter_config": {},
            "template_metadata": {
               "log_template_operations": True,
               "log_sanitize_operations": True
            }
         }
       )
       response = client.create_template(request=request)
       

    다음을 바꿉니다.

    • PROJECT_ID: 템플릿이 속한 프로젝트의 ID입니다.
    • LOCATION: 템플릿의 위치입니다.
    • TEMPLATE_ID: 템플릿의 ID입니다.

    로그 보기

    Cloud Logging의 로그 탐색기를 사용하여 Model Armor 로그에 액세스합니다. 자세한 내용은 로그 탐색기를 사용하여 로그 보기를 참조하세요. 서비스 이름 modelarmor.googleapis.com으로 필터링합니다. 템플릿에서 사용 설정한 작업과 관련된 항목을 찾습니다. 모든 서비스 이름과 모니터링 리소스 유형의 목록은 모니터링 리소스 및 서비스를 참고하세요.

    Model Armor 로그 필터링

    로그 라벨을 사용하여 삭제 작업 및 템플릿 로깅에 대한 Model Armor 로그를 필터링합니다.

    로그 탐색기에서 다음 쿼리를 실행하여 삭제 작업 로그를 필터링합니다.

    jsonPayload.@type="type.googleapis.com/google.cloud.modelarmor.logging.v1.SanitizeOperationLogEntry"
    

    삭제 작업 로그를 더 세부적으로 조정하려면 쿼리에서 프로젝트 ID, 클라이언트 이름 또는 상관관계 ID를 지정하면 됩니다.

    • 프로젝트 ID 사용:

      jsonPayload.@type="type.googleapis.com%2Fgoogle.cloud.modelarmor.logging.v1.SanitizeOperationLogEntry";project=PROJECT_ID
      
    • 클라이언트 이름을 사용하는 경우:

      jsonPayload.@type="type.googleapis.com/google.cloud.modelarmor.logging.v1.SanitizeOperationLogEntry"
      labels."modelarmor.googleapis.com/client_name"="CLIENT_NAME"
      
    • 연관 ID 사용:

      labels."modelarmor.googleapis.com/client_correlation_id"="CORRELATION_ID"
      

    다음을 바꿉니다.

    • PROJECT_ID: Google Cloud 프로젝트 ID
    • CLIENT_NAME: 클라이언트 이름입니다.
    • CORRELATION_ID: 특정 요청에 대해 생성하는 고유 식별자입니다.

    로그 및 관련 이벤트의 상관관계 지정

    특정 상호작용과 관련된 로그와 이벤트를 연결하려면 클라이언트 상관관계 ID가 필요합니다. 시스템 전반에서 특정 요청을 추적하기 위해 생성하는 고유 식별자(예: UUID)입니다. curl 헤더에서 클라이언트 상관 ID를 설정하려면 -H 옵션을 사용하여 요청에 맞춤 헤더를 포함하세요. 다음은 샘플 형식입니다.

    curl -X POST -d  '{"userPromptData": { "text": 'USER_PROMPT' } }' \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "MA-Client-Correlation-Id: $uuid" \
        "https://modelarmor.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/templates/TEMPLATE_ID:sanitizeUserPrompt"
    
    curl -X POST \
        -d  '{"modelResponseData": { "text": 'MODEL_RESPONSE' }, "userPrompt": 'USER_PROMPT' }' \
        -H "Content-Type: application/json" \
        -H "MA-Client-Correlation-Id: $uuid" \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        "https://modelarmor.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/templates/TEMPLATE_ID:sanitizeModelResponse"
    

    다음을 바꿉니다.

    • PROJECT_ID: 템플릿이 속한 프로젝트의 ID입니다.
    • LOCATION: 템플릿의 위치입니다.
    • TEMPLATE_ID: 템플릿의 ID입니다.
    • USER_PROMPT: 모델에 제공된 프롬프트
    • MODEL_RESPONSE: 모델에서 수신된 응답입니다.