Prompt API Reference

Prompt API Reference (프롬프트 API 문서)

Ragas의 프롬프트 시스템은 LLM 기반 지표와 다른 컴포넌트를 위한 프롬프트를 유연하고 타입 안전하게 정의할 수 있게 해줘요. 이 페이지에서는 핵심 프롬프트 클래스와 사용법을 다룬답니다.

출처: 문서

본문

개요

Ragas는 BasePrompt 클래스를 기반으로 한 모듈형 프롬프트 구조를 사용해요. 프롬프트는 다음처럼 나뉠 수 있어요.

  • 입력/출력 모델 (Input/Output Models): 프롬프트 입력과 출력의 구조를 정의하는 Pydantic BaseModel 클래스
  • 프롬프트 클래스 (Prompt Classes): BasePrompt를 상속해 지시문·예시·프롬프트 생성 로직을 정의
  • 문자열 프롬프트 (String Prompts): 하위 호환을 위한 단순 텍스트 기반 프롬프트

코어 클래스

InputModel = TypeVar('InputModel', bound=BaseModel)

지표 컬렉션 프롬프트 (Metrics Collections Prompts)

Ragas의 최신 지표는 전용 프롬프트 클래스를 사용해요. 각 지표 모듈에는 다음이 포함돼요.

  • 입력 모델 (Input Model): 프롬프트가 필요한 데이터를 정의 (예: FaithfulnessInput)
  • 출력 모델 (Output Model): 기대하는 LLM 응답 구조를 정의 (예: FaithfulnessOutput)
  • 프롬프트 클래스 (Prompt Class): BasePrompt를 상속해 예시와 지시문이 담긴 프롬프트 문자열 생성

예제: Faithfulness 지표 프롬프트

from ragas.metrics.collections.faithfulness.util import (
    FaithfulnessPrompt,
    FaithfulnessInput,
    FaithfulnessOutput,
)

# The prompt class combines input/output models with instructions and examples
prompt = FaithfulnessPrompt()

# Create input data
input_data = FaithfulnessInput(
    response="The capital of France is Paris.",
    context="Paris is the capital and most populous city of France."
)

# Generate the prompt string for the LLM
prompt_string = prompt.to_string(input_data)

# The output will be structured according to FaithfulnessOutput model

사용 가능한 지표 프롬프트

각 지표의 프롬프트에 대한 자세한 내용은 해당 지표 문서를 참고해요.

커스터마이징

지표의 프롬프트를 커스터마이징하는 자세한 방법은 지표의 프롬프트 수정하기를 참고해요.

더 알아보기 (Learn more)