Optimiza las instrucciones para la generación de texto con Vertex AI
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta muestra, se indica cómo usar el optimizador de instrucciones de Vertex AI para optimizar instrucciones para un modelo de generación de texto.
Explora más
Para obtener documentación en la que se incluye esta muestra de código, consulta lo siguiente:
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],[],[],[],null,["# Optimize prompts for text generation with Vertex AI\n\nThis sample demonstrates how to use the Vertex AI Prompt Optimizer to optimize prompts for a text generation model.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Optimize prompts](/vertex-ai/generative-ai/docs/learn/prompts/prompt-optimizer)\n\nCode sample\n-----------\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Vertex AI quickstart using\nclient libraries](/vertex-ai/docs/start/client-libraries).\n\n\nFor more information, see the\n[Vertex AI Python API\nreference documentation](/python/docs/reference/aiplatform/latest).\n\n\nTo authenticate to Vertex AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import aiplatform\n\n # Initialize Vertex AI platform\n aiplatform.https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform.html(project=PROJECT_ID, location=\"us-central1\")\n\n # TODO(Developer): Check and update lines below\n # cloud_bucket = \"gs://cloud-samples-data\"\n # config_path = f\"{cloud_bucket}/instructions/sample_configuration.json\"\n # output_path = \"custom_job/output/\"\n\n custom_job = aiplatform.https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform_v1.types.CustomJob.html(\n display_name=\"Prompt Optimizer example\",\n worker_pool_specs=[\n {\n \"replica_count\": 1,\n \"container_spec\": {\n \"image_uri\": \"us-docker.pkg.dev/vertex-ai-restricted/builtin-algorithm/apd:preview_v1_0\",\n \"args\": [f\"--config={cloud_bucket}/{config_path}\"],\n },\n \"machine_spec\": {\n \"machine_type\": \"n1-standard-4\",\n },\n }\n ],\n staging_bucket=cloud_bucket,\n base_output_dir=f\"{cloud_bucket}/{output_path}\",\n )\n\n custom_job.submit()\n print(f\"Job resource name: {custom_job.resource_name}\")\n # Example response:\n # 'projects/123412341234/locations/us-central1/customJobs/12341234123412341234'\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=generativeaionvertexai)."]]