Menambahkan logika pemrosesan menggunakan fungsi Cloud Run
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dengan fungsi Cloud Run, Anda dapat memproses lebih lanjut data output dari
model yang dilatih khusus Vertex AI dan node aplikasi BigQuery.
Anda dapat menggunakan integrasi ini dengan node aplikasi dengan cara berikut:
Node model kustom Vertex AI: Gunakan fungsi Cloud Run untuk
memproses hasil prediksi dari model kustom Vertex AI
asli.
Node BigQuery: Gunakan fungsi Cloud Run untuk membuat baris BigQuery yang disesuaikan dengan anotasi asli.
Semua fungsi Cloud Run yang Anda gunakan dengan App Platform harus memenuhi persyaratan berikut:
//MessageofessentialmetadataofAppPlatform.//Thismessageisusuallyattachedtoacertainmodeloutputannotationfor//customertoidentifythesourceofthedata.messageAppPlatformMetadata{//Theapplicationresourcename.stringapplication=1;//Theinstanceresourceid.Instanceisthenestedresourceofapplication//undercollection'instances'.stringinstance_id=2;//Thenodenameoftheapplicationgraph.stringnode=3;//Thereferredmodelresourcenameoftheapplicationnode.stringprocessor=4;}//ForanyCloudRunfunctionbasedcustomerprocessinglogic,customer's cloud//functionisexpectedtoreceiveAppPlatformCloudFunctionRequestasrequest//andsendbackAppPlatformCloudFunctionResponseasresponse.//MessageofrequestfromAppPlatformtoCloudRunfunctions.messageAppPlatformCloudFunctionRequest{//ThemetadataoftheAppPlatformforcustomertoidentifythesourceofthe//payload.AppPlatformMetadataapp_platform_metadata=1;//Ageneralannotationmessagethatusesstructformattorepresentdifferent//concreteannotationprotobufs.messageStructedInputAnnotation{//Theingestiontimeofthecurrentannotation.int64ingestion_time_micros=1;//Thestructformatoftheactualannotation.protobuf.Structannotation=2;}//TheactualannotationstobeprocessedbythecustomizedCloudRunfunction.repeatedStructedInputAnnotationannotations=2;}//Messageoftheresponsefromcustomer's Cloud Run function to AppPlatform.messageAppPlatformCloudFunctionResponse{//Ageneralannotationmessagethatusesstructformattorepresentdifferent//concreteannotationprotobufs.messageStructedOutputAnnotation{//Thestructformatoftheactualannotation.protobuf.Structannotation=1;}//ThemodifiedannotationsthatisreturnedbacktoAppPlatform.//Iftheannotationsfieldsareempty,thenthoseannotationswillbedropped//byAppPlatform.repeatedStructedOutputAnnotationannotations=2;}
Contoh penggunaan
Gunakan kode berikut untuk memproses pasca-anotasi model Vertex AI yang dilatih secara khusus
dan mengganti anotasi dengan pasangan nilai kunci konstan.
Python
importfunctions_frameworkfromflaskimportjsonify@functions_framework.httpdefhello_http(request):request_json=request.get_json(silent=True)request_args=request.argsifrequest_jsonand'annotations'inrequest_json:annotations=[]foreleinrequest_json['annotations']:fork,vinele.items():ifk=="annotation":if"predictions"inv:# Replace the annotation.v["predictions"][0]={"user":"googler"}annotations.append({"annotation":v})else:annotations='Failure'returnjsonify(annotations=annotations)
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-04 UTC."],[],[],null,["# Add processing logic using Cloud Run functions\n\nWith Cloud Run functions you can further process output data from\nVertex AI custom-trained model and BigQuery app nodes.\nYou can use these integrations with app nodes in the following ways:\n\n- **Vertex AI custom model** node: Use Cloud Run functions to post-process prediction results from the original Vertex AI custom model.\n- **BigQuery** node: Use Cloud Run functions to generate customized BigQuery rows with the original annotations.\n\nAll the Cloud Run functions you use with App Platform must meet the following\nrequirements:\n\n- Cloud Run functions must provide the [Http trigger](/functions/docs/calling/http).\n- Cloud Run functions must receive a [`AppPlatformCloudFunctionRequest`](/vision-ai/docs/reference/rpc/google.cloud.visionai.v1alpha1#appplatformcloudfunctionrequest) JSON string, and must return a [`AppPlatformCloudFunctionResponse`](/vision-ai/docs/reference/rpc/google.cloud.visionai.v1alpha1#appplatformcloudfunctionresponse) JSON string back.\n- The annotation payload schema stored in the request *and* the response must follow the specification of the target model.\n\n#### API definitions: `AppPlatformMetadata`, `AppPlatformCloudFunctionRequest`, `AppPlatformCloudFunctionResponse`\n\n```gdscript\n// Message of essential metadata of App Platform.\n// This message is usually attached to a certain model output annotation for\n// customer to identify the source of the data.\nmessage AppPlatformMetadata {\n // The application resource name.\n string application = 1;\n // The instance resource id. Instance is the nested resource of application\n // under collection 'instances'.\n string instance_id = 2;\n // The node name of the application graph.\n string node = 3;\n // The referred model resource name of the application node.\n string processor = 4;\n}\n\n// For any Cloud Run function based customer processing logic, customer's cloud\n// function is expected to receive AppPlatformCloudFunctionRequest as request\n// and send back AppPlatformCloudFunctionResponse as response.\n// Message of request from AppPlatform to Cloud Run functions.\nmessage AppPlatformCloudFunctionRequest {\n // The metadata of the AppPlatform for customer to identify the source of the\n // payload.\n AppPlatformMetadata app_platform_metadata = 1;\n // A general annotation message that uses struct format to represent different\n // concrete annotation protobufs.\n message StructedInputAnnotation {\n // The ingestion time of the current annotation.\n int64 ingestion_time_micros = 1;\n // The struct format of the actual annotation.\n protobuf.Struct annotation = 2;\n }\n // The actual annotations to be processed by the customized Cloud Run function.\n repeated StructedInputAnnotation annotations = 2;\n}\n\n// Message of the response from customer's Cloud Run function to AppPlatform.\nmessage AppPlatformCloudFunctionResponse {\n // A general annotation message that uses struct format to represent different\n // concrete annotation protobufs.\n message StructedOutputAnnotation {\n // The struct format of the actual annotation.\n protobuf.Struct annotation = 1;\n }\n\n // The modified annotations that is returned back to AppPlatform.\n // If the annotations fields are empty, then those annotations will be dropped\n // by AppPlatform.\n repeated StructedOutputAnnotation annotations = 2;\n}\n```\n\n### Sample usage\n\nUse the following code to post-process Vertex AI custom-trained model\nannotations and replace annotations with a constant key-value pair. \n\n### Python\n\n import functions_framework\n from flask import jsonify\n\n @functions_framework.http\n def hello_http(request):\n request_json = request.get_json(silent=True)\n request_args = request.args\n\n if request_json and 'annotations' in request_json:\n annotations = []\n for ele in request_json['annotations']:\n for k, v in ele.items():\n if k == \"annotation\":\n if \"predictions\" in v:\n # Replace the annotation.\n v[\"predictions\"][0] = {\"user\": \"googler\"}\n annotations.append({\"annotation\" : v})\n else:\n annotations = 'Failure'\n return jsonify(annotations=annotations)"]]