Cloud Run 함수를 사용하면 Vertex AI 맞춤 학습 모델 및 BigQuery 앱 노드의 출력 데이터를 추가로 처리할 수 있습니다. 다음과 같은 방법으로 앱 노드와 이러한 통합을 사용할 수 있습니다.
- Vertex AI 맞춤 모델 노드: Cloud Run 함수를 사용하여 원래 Vertex AI 맞춤 모델의 예측 결과를 후처리합니다.
- BigQuery 노드: Cloud Run 함수를 사용하여 원본 주석이 포함된 맞춤설정된 BigQuery 행을 생성합니다.
App Platform과 함께 사용하는 모든 Cloud Run 함수는 다음 요구사항을 충족해야 합니다.
- Cloud Run 함수는 Http 트리거를 제공해야 합니다.
- Cloud Run 함수는
AppPlatformCloudFunctionRequest
JSON 문자열을 수신하고AppPlatformCloudFunctionResponse
JSON 문자열을 다시 반환해야 합니다. - 요청 및 응답에 저장된 주석 페이로드 스키마는 대상 모델의 사양을 따라야 합니다.
API 정의: AppPlatformMetadata
, AppPlatformCloudFunctionRequest
, AppPlatformCloudFunctionResponse
// Message of essential metadata of App Platform. // This message is usually attached to a certain model output annotation for // customer to identify the source of the data. message AppPlatformMetadata { // The application resource name. string application = 1; // The instance resource id. Instance is the nested resource of application // under collection 'instances'. string instance_id = 2; // The node name of the application graph. string node = 3; // The referred model resource name of the application node. string processor = 4; } // For any Cloud Run function based customer processing logic, customer's cloud // function is expected to receive AppPlatformCloudFunctionRequest as request // and send back AppPlatformCloudFunctionResponse as response. // Message of request from AppPlatform to Cloud Run functions. message AppPlatformCloudFunctionRequest { // The metadata of the AppPlatform for customer to identify the source of the // payload. AppPlatformMetadata app_platform_metadata = 1; // A general annotation message that uses struct format to represent different // concrete annotation protobufs. message StructedInputAnnotation { // The ingestion time of the current annotation. int64 ingestion_time_micros = 1; // The struct format of the actual annotation. protobuf.Struct annotation = 2; } // The actual annotations to be processed by the customized Cloud Run function. repeated StructedInputAnnotation annotations = 2; } // Message of the response from customer's Cloud Run function to AppPlatform. message AppPlatformCloudFunctionResponse { // A general annotation message that uses struct format to represent different // concrete annotation protobufs. message StructedOutputAnnotation { // The struct format of the actual annotation. protobuf.Struct annotation = 1; } // The modified annotations that is returned back to AppPlatform. // If the annotations fields are empty, then those annotations will be dropped // by AppPlatform. repeated StructedOutputAnnotation annotations = 2; }
사용 예시
다음 코드를 사용하여 Vertex AI 커스텀 학습 모델 주석을 후처리하고 주석을 상수 키-값 쌍으로 대체합니다.
Python
import functions_framework
from flask import jsonify
@functions_framework.http
def hello_http(request):
request_json = request.get_json(silent=True)
request_args = request.args
if request_json and 'annotations' in request_json:
annotations = []
for ele in request_json['annotations']:
for k, v in ele.items():
if k == "annotation":
if "predictions" in v:
# Replace the annotation.
v["predictions"][0] = {"user": "googler"}
annotations.append({"annotation" : v})
else:
annotations = 'Failure'
return jsonify(annotations=annotations)