퓨샷 프롬프트 옵티마이저

퓨샷 프롬프트 옵티마이저는 모델의 응답이 기대에 미치지 못한 예시를 분석하여 시스템 안내를 개선하는 데 도움이 됩니다. 프롬프트, 모델 응답, 해당 응답에 대한 의견의 구체적인 예를 제공하면 최적화 도구가 시스템 안내를 개선합니다. 기준표 및 기준표 기반 평가 또는 타겟 응답의 두 가지 방법 중 하나로 의견을 제공할 수 있습니다.

퓨샷 최적화를 사용하려면 Pandas DataFrame에 예시를 제공해야 하며 Vertex AI SDK를 통해 사용할 수 있습니다.

기준표 기반 평가를 사용하여 최적화

이 메서드는 각 예시에 대한 루브릭 (평가 기준이라고도 함)과 모델이 해당 기준을 충족했는지에 관한 기록이 있는 시나리오에 적합합니다. DataFrame에는 다음 네 개의 열이 포함되어야 합니다.

  • prompt: 원래 사용자 프롬프트입니다.
  • model_response: 모델에서 생성된 실제 출력입니다.
  • rubrics: 문자열 목록의 문자열 표현으로, 해당 예의 구체적인 기준 목록입니다.
  • rubrics_evaluations: 각 루브릭이 충족되었는지 여부를 나타내는 불리언 목록입니다(불리언 목록의 문자열 표현).

루브릭은 모든 행에서 일관되거나 각 예시에 맞게 조정될 수 있습니다.

import pandas as pd
import vertexai
from vertexai import types

PROJECT_NAME = "YOUR_PROJECT_NAME"
LOCATION = "YOUR_LOCATION" # e.g. "us-central1"
client = vertexai.Client(project=PROJECT_NAME, location=LOCATION)

system_instructions = "You are an AI assistant skilled in analyzing articles. Your task is to extract key arguments, evaluate evidence quality, identify potential biases, and summarize core findings into a concise, actionable, and objective report. Make sure the response is less than 50 words"
df = pd.DataFrame(
    [
        {
            "prompt": "prompt1",
            "model_response": "response1",
            "rubrics": "['Response is in English', 'Under 50 words']",
            "rubrics_evaluations": "[True, True]",
        },
        {
            "prompt": "prompt2",
            "model_response": "response2",
            "rubrics": "['Response is in English', 'Under 50 words']",
            "rubrics_evaluations": "[True, False]",
        },
    ]
)

config = vertexai.types.OptimizeConfig(
    optimization_target=vertexai.types.OptimizeTarget.OPTIMIZATION_TARGET_FEW_SHOT_RUBRICS,
    examples_dataframe=df,
)

response = client.prompts.optimize(prompt=system_instructions, config=config)

print(response.parsed_response.suggested_prompt)

타겟 응답을 사용하여 최적화

구체적인 평가 기준은 없지만 각 프롬프트에 대한 이상적인 또는 '골드 스탠더드' 응답이 있는 경우 타겟 응답 기반 최적화를 사용할 수 있습니다. 최적화 프로그램은 모델의 출력을 이상적인 출력과 비교하고 격차를 해소하기 위해 지침을 조정합니다.

DataFrame에는 다음 세 열이 포함되어야 합니다.

  • prompt: 원래 사용자 명령입니다.
  • model_response: 개선이 필요한 현재 모델 출력입니다.
  • target_response: 모델에서 생성하려는 이상적인 대답입니다.
import pandas as pd
import vertexai
from vertexai import types

PROJECT_NAME = "PROJECT"
LOCATION = "YOUR_LOCATION" # e.g. "us-central1"
client = vertexai.Client(project=YOUR_PROJECT_NAME, location=LOCATION)

system_instructions = "You are an AI assistant skilled in analyzing articles. Your task is to extract key arguments, evaluate evidence quality, identify potential biases, and summarize core findings into a concise, actionable, and objective report. Make sure the response is less than 50 words"
df = pd.DataFrame(
    {
        "prompt": ["prompt1", "prompt2"],
        "model_response": ["response1", "response2"],
        "target_response": ["target1", "target2"],
    }
)
config = vertexai.types.OptimizeConfig(
    optimization_target=vertexai.types.OptimizeTarget.OPTIMIZATION_TARGET_FEW_SHOT_TARGET_RESPONSE,
    examples_dataframe=df,
)
response = client.prompts.optimize(
    prompt=system_instructions,
    config=config,
)

print(response.parsed_response.suggested_prompt)