Mulai 29 April 2025, model Gemini 1.5 Pro dan Gemini 1.5 Flash tidak tersedia di project yang belum pernah menggunakan model ini, termasuk project baru. Untuk mengetahui detailnya, lihat
Versi dan siklus proses model.
Mengoptimalkan perintah untuk pembuatan teks dengan Vertex AI
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Contoh ini menunjukkan cara menggunakan Pengoptimal Perintah Vertex AI untuk mengoptimalkan perintah untuk model pembuatan teks.
Mempelajari lebih lanjut
Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["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"]],[],[],[],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)."]]