AI 프롬프트 템플릿 플러그인
AI 프롬프트 템플릿 플러그인 (AI Prompt Template Plugin)
AI Prompt Template 플러그인은 관리자가 미리 다듬어 둔 AI 프롬프트를 템플릿 형태로 제공해요. 사용자는 {{variable}} 형식의 빈칸만 채우면 되기 때문에, 조직의 누구나 같은 프롬프트를 손쉽게 재사용하거나 LLM을 하나의 API처럼 활용할 수 있어요. 또한 문자열 입력을 정화해 JSON 제어 문자를 이스케이프 처리해서 임의의 프롬프트 인젝션도 막아 줘요. 이 플러그인은 AI Proxy 플러그인의 기능을 확장한 것이므로, AI Proxy나 AI Proxy Advanced가 먼저 구성되어 있어야 한다는 점을 기억해 주세요
출처: 문서
본문
AI Gateway 2.0을 찾고 계신가요? 현재 버전의 정책 보기.
AI Prompt Template 플러그인을 사용하면 사용자에게 튜닝된 AI 프롬프트를 제공할 수 있어요.
사용자는 다음 형식의 변수 플레이스홀더로 빈칸만 채우면 돼요: {{variable}}.
이를 통해 관리자는 템플릿을 설정해 둘 수 있고, 설정된 템플릿은 조직의 누구나 사용할 수 있어요. 또한 관리자가 LLM을 그 자체로 하나의 API처럼 제공할 수도 있어요 - 예를 들어, 소프트웨어 수업 예제 및/또는 제안을 제공하는 봇이 있을 수 있죠.
이 플러그인은 문자열 입력을 정제(sanitize)해서 JSON 제어 문자가 이스케이프되도록 보장하며, 임의적인 프롬프트 인젝션을 방지해요.
이 플러그인은 AI Proxy 플러그인의 기능을 확장하며, AI Proxy 또는 AI Proxy Advanced 중 하나가 먼저 구성되어 있어야 해요. AI Proxy를 빠르게 설정하려면 AI Gateway 시작하기를 확인하세요.
작동 방식
활성화하면 템플릿이 LLM 사용을 사전 정의된 템플릿으로 제한해요. 템플릿은 다음 형식으로 정의돼요:
decK
_format_version: "3.0"
plugins:
- name: ai-prompt-template
config:
templates:
name: sample-template
template: |-
{
"messages": [
{
"role": "user",
"content": "Explain to me what {{thing}} is."
}
]
}
{: data-file="kong.yaml" data-tool="deck" }
Admin API
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-prompt-template",
"config": {
"templates": {
"name": "sample-template",
"template": "{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain to me what {{thing}} is.\"\n }\n ]\n}"
}
}
}
'
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-prompt-template",
"config": {
"templates": {
"name": "sample-template",
"template": "{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"Explain to me what {{thing}} is.\"\n }\n ]\n}"
}
}
}
'
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: ai-prompt-template
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
templates:
name: sample-template
template: |-
{
'messages': [
{
'role': 'user',
'content': 'Explain to me what {{thing}} is.'
}
]
}
plugin: ai-prompt-template
" | kubectl apply -f -
Terraform
resource "konnect_gateway_plugin_ai_prompt_template" "my_ai_prompt_template" {
enabled = true
config = {
templates = {
name = "sample-template"
template = <<EOF
{
"messages": [
{
"role": "user",
"content": "Explain to me what {{thing}} is."
}
]
}
EOF
}
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
템플릿을 호출할 때는 messages (llm/v1/chat) 또는 prompt (llm/v1/completions)의 내용을 다음 형식의 템플릿 참조로 바꾸세요:
{
"messages": "{template://sample-template}",
"properties": {
"thing": "gravity"
}
}
기본적으로 템플릿을 사용하지 않는 요청도 여전히 LLM으로 전달돼요. 하지만 이는 config.allow_untemplated_requests 파라미터로 설정할 수 있어요. 이 파라미터를 false로 설정하면 템플릿을 사용하지 않는 요청은 400 Bad Request 응답을 반환해요.
더 알아보기 (Learn more)
- AI Gateway 2.0을 찾고 있다면 현재 버전의 정책 문서를 확인해 보세요 — See the policy for the current version
- 이 플러그인이 기능을 확장하는 대상이자 필수 선행 조건인 AI Proxy 플러그인을 살펴봐요 — AI Proxy plugin
- 더 풍부한 AI 게이트웨이 기능이 필요할 때 함께 활용할 수 있는 AI Proxy Advanced를 확인해 봐요 — AI Proxy Advanced
- AI Gateway를 빠르게 시작하는 방법을 단계별로 안내받아 봐요 — Get started with AI Gateway
- 템플릿이 없는 요청의 허용 여부를 제어하는 설정 항목을 참고해 봐요 —
config.allow_untemplated_requests