Prompts für die Textgenerierung mit Vertex AI optimieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Beispiel wird gezeigt, wie Sie mit dem Vertex AI Prompt Optimizer Prompts für ein Modell zur Textgenerierung optimieren.
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","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)."]]