LiteLLM 프롬프트 관리

LiteLLM 프롬프트 관리 (GitOps)

프롬프트를 저장소의 .prompt 파일로 저장하고 LiteLLM에서 직접 사용해요. 외부 서비스가 필요 없어요.

파일 시스템(로컬), BitBucket(팀 기반 접근 제어), Gitlab(팀 기반 접근 제어) 세 가지 통합을 지원해요.

출처: 문서

본문

프롬프트를 저장소의 .prompt 파일로 저장하고 LiteLLM에서 직접 사용해요. 외부 서비스가 필요 없어요.

지원 통합 (Supported Integrations)

  • 파일 시스템 : .prompt 파일을 로컬에 저장
  • BitBucket : 팀 기반 접근 제어와 함께 .prompt 파일을 BitBucket 저장소에 저장
  • Gitlab : 팀 기반 접근 제어와 함께 .prompt 파일을 Gitlab 저장소에 저장

빠른 시작 (Quick Start)

  • SDK
  • BITBUCKET
  • GITLAB
  • PROXY

1. .prompt 파일 만들기

prompts/hello.prompt를 만들어요:

    ---
    model: gpt-5.6-terra
    temperature: 0.7
    ---
    System: You are a helpful assistant.

    User: {{user_message}}

2. LiteLLM에서 사용하기

    import litellm

    # Set the global prompt directory
    litellm.global_prompt_directory = "prompts/"

    response = litellm.completion(
        model="dotprompt/gpt-5.6-terra",
        prompt_id="hello",
        prompt_variables={"user_message": "What is the capital of France?"}
    )

1. BitBucket에 .prompt 파일 만들기

BitBucket 저장소에 prompts/hello.prompt를 만들어요:

    ---
    model: gpt-5.6-terra
    temperature: 0.7
    ---
    System: You are a helpful assistant.

    User: {{user_message}}

2. BitBucket 접근 구성하기

    import litellm

    # Configure BitBucket access
    bitbucket_config = {
        "workspace": "your-workspace",
        "repository": "your-repo",
        "access_token": "your-access-token",
        "branch": "main"
    }

    # Set global BitBucket configuration
    litellm.set_global_bitbucket_config(bitbucket_config)

3. LiteLLM에서 사용하기

    response = litellm.completion(
        model="bitbucket/gpt-5.6-terra",
        prompt_id="hello",
        prompt_variables={"user_message": "What is the capital of France?"}
    )

1. gitlab 저장소에 .prompt 파일 만들기

gitlab 저장소에 prompts/hello.prompt를 만들어요:

    ---
    model: gpt-5.6-terra
    temperature: 0.7
    ---
    System: You are a helpful assistant.

    User: {{user_message}}

2. Gitlab 접근 구성하기

    import litellm

    # Configure gitlab access
    gitlab_config = {
        "project": "your-group/your-repo",  # project path or numeric project id
        "access_token": "your-access-token",
        "branch": "main"
    }

    # Set global gitlab configuration
    litellm.set_global_gitlab_config(gitlab_config)

3. LiteLLM에서 사용하기

    response = litellm.completion(
        model="gitlab/gpt-5.6-terra",
        prompt_id="hello",
        prompt_variables={"user_message": "What is the capital of France?"}
    )

1. .prompt 파일 만들기

prompts/hello.prompt를 만들어요:

    ---
    model: gpt-5.6-terra
    temperature: 0.7
    ---
    System: You are a helpful assistant.

    User: {{user_message}}

2. config.yaml 설정하기

    model_list:
      - model_name: my-dotprompt-model
        litellm_params:
          model: dotprompt/gpt-5.6-terra
          prompt_id: "hello"
          api_key: os.environ/OPENAI_API_KEY

    litellm_settings:
      global_prompt_directory: "./prompts"
      # Or use BitBucket for team-based prompt management
      global_bitbucket_config:
        workspace: "your-workspace"
        repository: "your-repo"
        access_token: "your-access-token"
        branch: "main"
      # Or use Gitlab for team-based prompt management
      global_gitlab_config:
        project: "your-group/your-repo"  # project path or numeric project id
        access_token: "your-access-token"
        branch: "main"

3. 프록시 시작하기

    litellm --config config.yaml --detailed_debug

4. 테스트하기!

    curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer ***" \
    -d '{
        "model": "my-dotprompt-model",
        "messages": [{"role": "user", "content": "IGNORED"}],
        "prompt_variables": {
            "user_message": "What is the capital of France?"
        }
    }'

.prompt 파일 형식

.prompt 파일은 YAML frontmatter를 메타데이터로 사용하고 Jinja2 템플릿을 지원해요:

    ---
    model: gpt-5.6-terra                    # Model to use
    temperature: 0.7                # Optional parameters
    max_tokens: 1000
    input:
      schema:
        user_message: string        # Input validation (optional)
    ---
    System: You are a helpful {{role}} assistant.

    User: {{user_message}}

고급 기능 (Advanced Features)

멀티 롤 대화:

    ---
    model: gpt-5.6-terra
    temperature: 0.3
    ---
    System: You are a helpful coding assistant.

    User: {{user_question}}

동적 모델 선택:

    ---
    model: "{{preferred_model}}"  # Model can be a variable
    temperature: 0.7
    ---
    System: You are a helpful assistant specialized in {{domain}}.

    User: {{user_message}}

API 레퍼런스 (API Reference)

프롬프트 통합에는 다음 파라미터를 사용해요:

파일 시스템 (dotprompt):

    model: dotprompt/<base_model>     # required (e.g., dotprompt/gpt-5.6-terra)
    prompt_id: str                    # required - the .prompt filename without extension
    prompt_variables: Optional[dict]  # optional - variables for template rendering

BitBucket:

    model: bitbucket/<base_model>     # required (e.g., bitbucket/gpt-5.6-terra)
    prompt_id: str                    # required - the .prompt filename without extension
    prompt_variables: Optional[dict]  # optional - variables for template rendering
    bitbucket_config: Optional[dict]  # optional - BitBucket configuration (if not set globally)

Gitlab:

    model: gitlab/<base_model>        # required (e.g., gitlab/gpt-5.6-terra)
    prompt_id: str                    # required - the .prompt filename without extension
    prompt_variables: Optional[dict]  # optional - variables for template rendering
    gitlab_config: Optional[dict]     # optional - Gitlab configuration (if not set globally)

예시 API 호출:

    # File system integration
    response = litellm.completion(
        model="dotprompt/gpt-5.6-terra",
        prompt_id="hello",
        prompt_variables={"user_message": "Hello world"},
        messages=[{"role": "user", "content": "This will be ignored"}]
    )

    # BitBucket integration
    response = litellm.completion(
        model="bitbucket/gpt-5.6-terra",
        prompt_id="hello",
        prompt_variables={"user_message": "Hello world"},
        bitbucket_config={
            "workspace": "your-workspace",
            "repository": "your-repo",
            "access_token": "your-token"
        }
    )

    # Gitlab integration
    response = litellm.completion(
        model="gitlab/gpt-5.6-terra",
        prompt_id="hello",
        prompt_variables={"user_message": "Hello world"},
        gitlab_config={
            "project": "a/b/<repo_name>",
            "access_token": "your-access-token",
            "base_url": "gitlab url",
            "prompts_path": "src/prompts", # folder to point to, defaults to root
            "branch":"main"  # optional, defaults to main
        }
    )

더 알아보기 (Learn more)