Une fois les points de terminaison de modèle ajoutés et enregistrés dans la gestion des points de terminaison de modèle, vous pouvez les référencer à l'aide de l'ID de modèle pour appeler des prédictions.
Appeler des prédictions pour des modèles génériques
Utilisez la fonction SQL google_ml.predict_row() pour appeler un point de terminaison de modèle générique enregistré afin d'appeler des prédictions. Vous pouvez utiliser la fonction google_ml.predict_row() avec n'importe quel type de modèle.
MODEL_ID : ID du modèle que vous avez défini lors de l'enregistrement du point de terminaison du modèle
REQUEST_BODY : paramètres de la fonction de prédiction, au format JSON.
Exemples
Pour générer des prédictions pour un point de terminaison de modèle gemini-pro enregistré, exécutez l'instruction suivante :
SELECTjson_array_elements(google_ml.predict_row(model_id=>'gemini-pro',request_body=>'{ "contents": [ { "role": "user", "parts": [ { "text": "For TPCH database schema as mentioned here https://www.tpc.org/TPC_Documents_Current_Versions/pdf/TPC-H_v3.0.1.pdf , generate a SQL query to find all supplier names which are located in the India nation." } ] } ] }'))->'candidates'->0->'content'->'parts'->0->'text';
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Invoke predictions with model endpoint management\n\n| **Preview**\n|\n|\n| This product is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n[MySQL](/sql/docs/mysql/model-endpoint-predictions \"View this page for the MySQL database engine\") \\| PostgreSQL \\| SQL Server\n\n\u003cbr /\u003e\n\nThis page describes model endpoint management. Model endpoint management lets you experiment with registering an AI model endpoint and invoking predictions.\n\nTo use AI models in\nproduction environments, see [Build generative AI applications using\nCloud SQL](/sql/docs/postgres/ai-overview) and [Invoke online predictions from Cloud SQL instances](/sql/docs/postgres/invoke-online-predictions).\n\n\nAfter the model endpoints are added and registered in model endpoint management, you can\nreference them using the model ID to invoke predictions.\n\nBefore you begin\n----------------\n\nMake sure that you complete the following actions:\n\n- Register your model endpoint with model endpoint management. For more information, see [Register and call remote AI models using model endpoint management](/sql/docs/postgres/model-endpoint-register-model).\n- Create or update your Cloud SQL instance so that the instance can integrate with Vertex AI. For more information, see [Enable database integration with Vertex AI](/sql/docs/postgres/integrate-cloud-sql-with-vertex-ai#enable-database-integration-with-vertex-ai).\n\nInvoke predictions for generic models\n-------------------------------------\n\nUse the `google_ml.predict_row()` SQL function to call a registered generic model endpoint to invoke\npredictions. You can use `google_ml.predict_row()` function with any model type. \n\n SELECT\n google_ml.predict_row(\n model_id =\u003e '\u003cvar translate=\"no\"\u003eMODEL_ID\u003c/var\u003e',\n request_body =\u003e '\u003cvar translate=\"no\"\u003eREQUEST_BODY\u003c/var\u003e');\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eMODEL_ID\u003c/var\u003e: the model ID you defined when registering the model endpoint\n- \u003cvar translate=\"no\"\u003eREQUEST_BODY\u003c/var\u003e: the parameters to the prediction function, in JSON format\n\nExamples\n--------\n\nTo generate predictions for a registered `gemini-pro` model endpoint, run the following statement: \n\n SELECT\n json_array_elements(\n google_ml.predict_row(\n model_id =\u003e 'gemini-pro',\n request_body =\u003e '{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"For TPCH database schema as mentioned here https://www.tpc.org/TPC_Documents_Current_Versions/pdf/TPC-H_v3.0.1.pdf , generate a SQL query to find all supplier names which are located in the India nation.\"\n }\n ]\n }\n ]\n }'))-\u003e 'candidates' -\u003e 0 -\u003e 'content' -\u003e 'parts' -\u003e 0 -\u003e 'text';"]]