제로샷 옵티마이저를 사용하면 사용자가 작성한 프롬프트를 자동으로 개선할 수 있습니다. 모호한 언어, 누락된 컨텍스트 또는 관련 없는 정보의 포함으로 인해 프롬프트가 원하는 모델 응답을 생성하지 못하는 경우가 많습니다. 이 최적화 도구는 기존 프롬프트를 분석하고 다시 작성하여 더 명확하고 효과적이며 모델의 기능에 더 잘 부합하도록 하여 궁극적으로 더 높은 품질의 응답을 제공합니다.
제로샷 최적화 도구는 특히 다음 경우에 유용합니다.
모델 업데이트에 적응: 모델의 최신 버전으로 업그레이드하면 기존 프롬프트가 더 이상 최적으로 작동하지 않을 수 있습니다.
프롬프트 이해도 향상: 프롬프트의 문구가 복잡하거나 오해의 소지가 있는 경우 이 도구는 명확성과 정확성을 극대화하기 위해 문구를 다시 작성하여 원치 않는 결과가 나올 가능성을 줄입니다.
최적화 도구를 사용하는 방법에는 두 가지가 있습니다.
요청 사항 생성: 복잡한 시스템 요청 사항을 처음부터 작성하는 대신 목표나 작업을 일반 언어로 설명할 수 있습니다. 그러면 최적화 도구가 목표를 달성하기 위해 설계된 완전하고 잘 구조화된 시스템 명령어를 생성합니다.
프롬프트 개선: 작동하는 프롬프트가 있지만 모델의 출력이 일관되지 않거나, 주제에서 약간 벗어나거나, 원하는 세부정보가 누락되어 있습니다. 최적화 도구를 사용하면 더 나은 출력을 위해 프롬프트를 개선할 수 있습니다.
최적화 도구는 Gemini에서 지원하는 모든 언어로 프롬프트 최적화를 지원하며 Vertex AI SDK를 통해 사용할 수 있습니다.
# Import librariesimportvertexaiimportlogging# Google Colab authenticationfromgoogle.colabimportauthPROJECT_NAME="PROJECT"auth.authenticate_user(project_id=PROJECT_NAME)# Initialize the Vertex AI clientclient=vertexai.Client(project=PROJECT_NAME,location='us-central1')# Input original prompt to optimizeprompt="""You are a professional chef. Your goal is teaching how to cook healthy cooking recipes to your apprentice.Given a question from your apprentice and some context, provide the correct answer to the question.Use the context to return a single and correct answer with some explanation."""# Optimize promptoutput=client.prompt_optimizer.optimize_prompt(prompt=prompt)# View optimized promptprint(output.model_dump_json(indent=2))
이 output 객체는 OptimizeResponse 유형이며 최적화 프로세스에 관한 정보를 제공합니다. 가장 중요한 부분은 모델에서 더 나은 결과를 얻는 데 사용할 수 있는 최적화된 프롬프트가 포함된 suggested_prompt입니다. 다른 필드, 특히 applicable_guidelines는 프롬프트가 개선된 이유와 방법을 이해하는 데 유용하며, 이를 통해 향후 더 나은 프롬프트를 작성할 수 있습니다. 다음은 출력의 예시입니다.
{"optimization_mode":"zero_shot","applicable_guidelines":[{"applicable_guideline":"Structure","suggested_improvement":"Add role definition.","text_before_change":"...","text_after_change":"Role: You are an AI assistant...\n\nTask Context:\n..."},{"applicable_guideline":"RedundancyInstructions","suggested_improvement":"Remove redundant explanation.","text_before_change":"...","text_after_change":""}],"original_prompt":"...","suggested_prompt":"Role: You are an AI assistant...\n\nTask Context:\n..."}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Zero-shot optimizer\n\nThe **zero-shot optimizer** lets you automatically refine and improve\nuser-written prompts. Often, a prompt may not produce the model response you\nwant due to ambiguous language, missing context, or the inclusion of irrelevant\ninformation. This optimizer analyzes and rewrites an existing prompt to be\nclearer, more effective, and better aligned with the model's capabilities,\nultimately leading to higher-quality responses.\n\nThe zero-shot optimizer is particularly useful for:\n\n- **Adapting to Model Updates:** When you upgrade to a newer version of a\n model, your existing prompts might no longer perform optimally.\n\n- **Enhancing Prompt Comprehension:** When the phrasing of a prompt is complex\n or could be misinterpreted, the tool can rephrase it for maximum clarity and\n precision, reducing the chance of an undesirable outcome.\n\nThere are two ways to use the optimizer:\n\n- **Instruction Generation**: Instead of writing complex system instructions\n from scratch, you can describe your goal or task in plain language. The\n optimizer will then generate a complete and well-structured set of system\n instructions designed to achieve your objective.\n\n- **Prompt Refinement**: You have a working prompt, but the model's output is\n inconsistent, slightly off-topic, or lacks the detail you want. The\n optimizer can help improve the prompt for a better output.\n\nThe optimizer supports prompt optimization in all languages supported by\nGemini and is available through the [Vertex AI\nSDK](/vertex-ai/generative-ai/docs/reference/libraries)\n\nBefore you begin\n----------------\n\n\nTo ensure that the [Compute Engine default service account](/iam/docs/service-account-types#default) has the necessary\npermissions to optimize prompts,\n\nask your administrator to grant the [Compute Engine default service account](/iam/docs/service-account-types#default) the\nfollowing IAM roles on the project:\n\n| **Important:** You must grant these roles to the [Compute Engine default service account](/iam/docs/service-account-types#default), *not* to your user account. Failure to grant the roles to the correct principal might result in permission errors.\n\n- [Vertex AI User](/iam/docs/roles-permissions/aiplatform#aiplatform.user) (`roles/aiplatform.user`)\n- [Vertex AI Service Agent](/iam/docs/roles-permissions/aiplatform#aiplatform.serviceAgent) (`roles/aiplatform.serviceAgent`)\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYour administrator might also be able to give the [Compute Engine default service account](/iam/docs/service-account-types#default)\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nOptimize a prompt\n-----------------\n\n # Import libraries\n import https://cloud.google.com/python/docs/reference/vertexai/latest/\n import logging\n\n # Google Colab authentication\n from google.colab import auth\n PROJECT_NAME = \"PROJECT\"\n auth.authenticate_user(project_id=PROJECT_NAME)\n\n # Initialize the Vertex AI client\n client = https://cloud.google.com/python/docs/reference/vertexai/latest/.Client(project=PROJECT_NAME, location='us-central1')\n\n # Input original prompt to optimize\n prompt = \"\"\"You are a professional chef. Your goal is teaching how to cook healthy cooking recipes to your apprentice.\n\n Given a question from your apprentice and some context, provide the correct answer to the question.\n Use the context to return a single and correct answer with some explanation.\n \"\"\"\n\n # Optimize prompt\n output = client.prompt_optimizer.optimize_prompt(prompt=prompt)\n\n # View optimized prompt\n print(output.model_dump_json(indent=2))\n\nThis `output` object is of type `OptimizeResponse` and provides information\nabout the optimization process. The most important part is the\n`suggested_prompt` which contains the optimized prompt that you can use to get\nbetter results from your model. The other fields, especially\n`applicable_guidelines`, are useful for understanding why and how your prompt\nwas improved, which can help you write better prompts in the future. Here's an\nexample of the output: \n\n {\n \"optimization_mode\": \"zero_shot\",\n \"applicable_guidelines\": [\n {\n \"applicable_guideline\": \"Structure\",\n \"suggested_improvement\": \"Add role definition.\",\n \"text_before_change\": \"...\",\n \"text_after_change\": \"Role: You are an AI assistant...\\n\\nTask Context:\\n...\"\n },\n {\n \"applicable_guideline\": \"RedundancyInstructions\",\n \"suggested_improvement\": \"Remove redundant explanation.\",\n \"text_before_change\": \"...\",\n \"text_after_change\": \"\"\n }\n ],\n \"original_prompt\": \"...\",\n \"suggested_prompt\": \"Role: You are an AI assistant...\\n\\nTask Context:\\n...\"\n }"]]