Firebase AI Logic의 경우 Firebase 콘솔은 템플릿의 콘텐츠를 지정할 수 있는 안내 UI를 제공합니다.
서버 프롬프트 템플릿은 Dotprompt 기반 문법과 형식을 사용합니다. 이 페이지에서는 템플릿 형식과 구문에 대한 자세한 설명과 Gemini 및 Imagen의 예시를 확인할 수 있습니다.
다음은 Gemini 모델에 대한 요청의 가장 중요한 구성요소입니다.
---
model: 'gemini-2.5-flash'
---
{{role "system"}}
All output must be a clearly structured invoice document.
Use a tabular or clearly delineated list format for line items.
{{role "user"}}
Create an example customer invoice for a customer named {{customerName}}.
세 개의 대시로 구분된 상단 섹션에는 모델 이름과 요청에 보낼 모델 구성, 입력 유효성 검사, 스키마가 선택적으로 포함됩니다. 키-값 쌍으로 작성되며 일반적으로 YAML 프런트매터라고 합니다.
템플릿의 본문에는 프롬프트가 포함됩니다. 선택적으로 시스템 안내와 입력 값 (Handlebars 문법 사용)을 포함할 수도 있습니다.
이 페이지에서는 다음 항목에 대한 템플릿 형식과 구문을 예시와 함께 자세히 설명합니다.
Gemini
이 섹션의 모든 예시에서는 gemini-2.5-flash를 사용하는 템플릿을 보여주지만, Firebase AI Logic에서 지원하는 Gemini 모델(Gemini Live 모델 제외)을 사용할 수 있습니다.
Hello World
다음은 서버 프롬프트 템플릿의 최소 예시입니다.
구성 (프런트매터)
---
model: 'gemini-2.5-flash'
---
프롬프트 및 (해당하는 경우) 시스템 안내
Write a story about a magic backpack.
모델 구성
모델 구성을 설정하여 모델이 응답을 생성하는 방식을 제어합니다(예: 최대 출력 토큰, 온도, 최상위 K, 최상위 P).
구성 (프런트매터)
---
model: 'gemini-2.5-flash'
config:
candidateCount: 1
temperature: 0.9
topP: 0.1
topK: 16
maxOutputTokens: 200
stopSequences: ["red"]
---
프롬프트 및 (해당하는 경우) 시스템 안내
Write a story about a magic backpack.
시스템 안내
시스템 요청 사항을 설정하여 모델의 동작을 조정합니다. 프롬프트의 일부로 포함합니다.
{{role "system"}}구문을 사용하여 시스템 지침을 지정합니다.{{role "user"}}구문을 사용하여 텍스트 프롬프트를 지정합니다.
구성 (프런트매터)
---
model: 'gemini-2.5-flash'
---
프롬프트 및 (해당하는 경우) 시스템 안내
{{role "system"}}
All output must be a clearly structured invoice document.
Use a tabular or clearly delineated list format for line items.
{{role "user"}}
Create an example customer invoice for a customer.
입력 변수
일부 프롬프트는 정적이지만 프롬프트의 일부로 사용자의 데이터를 포함해야 하는 경우가 많습니다.
{{variableName}} 또는 {{object.propertyName}} 형식의 {{ }} 태그 내에 포함된 Handlebars 표현식을 사용하여 프롬프트에 동적 입력 변수를 포함할 수 있습니다 (예: Hello, {{name}} from {{address.city}}).
구성 (프런트매터)
---
model: 'gemini-2.5-flash'
---
프롬프트 및 (해당하는 경우) 시스템 안내
Create an example customer invoice for a customer named {{customerName}}.
템플릿에 기본값을 제공할 수 있지만 입력 변수의 값은 일반적으로 클라이언트가 요청의 일부로 제공합니다.
제어 흐름 (루프 및 조건문)
더 복잡한 프롬프트를 작성하려면 조건 블록 (예: #if, else, #unless)과 반복 (#each)을 사용하면 됩니다.
특수 @ 접두사가 있는 변수로 추가 컨텍스트 정보를 제공할 수 있습니다.
@first:#each블록의 첫 번째 항목을 반복할 때 true입니다.@last:#each블록의 마지막 항목을 반복할 때 true입니다.@index: 현재 요소의 (0부터 시작하는) 색인 위치를 제공합니다.
모든 기본 제공 논리 도우미에 관한 자세한 내용은 Handlebars 문서를 참고하세요.
구성 (프런트매터)
---
model: 'gemini-2.5-flash'
---
프롬프트 및 (해당하는 경우) 시스템 안내
Create an example customer invoice for a customer named {{customerName}}.
Include entries for each of the following products
{{#each productNames}}
{{#if @first}}
Include line items for the following purchases
{{/if}}
- {{this}}
{{/each}}
{{#if isVipCustomer}}
Give the customer a 5% discount.
{{/if}}
조건문은 변수 참조만 허용하며, 다음과 같은 표현식은 허용하지 않습니다.
- 다음은 작동합니다.
{{#if isVipCustomer}} ... {{/if}} - 다음은 작동하지 않습니다.
{{#if customer.type == 'vip'}} ... {{/if}}
변수가 불리언인 경우 조건이 예상대로 작동합니다. 변수가 불리언이 아닌 경우 조건은 사실상 'is-not-null' 검사입니다. 이는 선택적 입력을 처리하는 데 유용합니다(예:
{{#if customerName}}
Hello {{customerName}}
{{else}}
Hello Guest
{{/if}}
입력 유효성 검사 및 스키마
클라이언트에서 제공되는 데이터가 있는 경우 입력 스키마를 사용하여 프롬프트 삽입을 방지하고 요청에 전달된 데이터가 예상과 일치하도록 하는 것이 좋습니다.
클라이언트가 값을 제공하지 않는 경우를 대비해 기본값을 제공할 수 있습니다.
스키마는 스칼라 유형
string,integer,number,boolean,object를 지원합니다. 객체, 배열, enum은 필드 이름 뒤에 괄호가 표시됩니다.?로 선택사항임을 표시하지 않는 한 모든 속성은 필수 속성으로 간주됩니다. 속성이 선택사항으로 표시되면 LLM이 필드를 생략하는 대신 null을 반환하도록 편의를 제공하기 위해 null을 허용하도록 설정됩니다.
다음은 입력 스키마를 제공하는 기본 예시입니다. 아래에서 더 고급 스키마를 확인할 수 있습니다.
구성 (프런트매터)
---
model: 'gemini-2.5-flash'
input:
default:
isVipCustomer: false
schema:
customerName: string, the customers name # string, number, and boolean types are defined like this
productNames?(array, list of products to include in the invoice): string # optional fields are marked with a ?
isVipCustomer?: boolean, whether or not the customer is a VIP
---
프롬프트 및 (해당하는 경우) 시스템 안내
Create an example customer invoice for a customer named {{customerName}}.
Include entries for each of the following products
{{#each productNames}}
{{#if @first}}
Include line items for the following purchases
{{/if}}
- {{this}}
{{/each}}
{{#if isVipCustomer}}
Give the customer a 5% discount.
{{/if}}
출력 스키마
모델이 구조화된 JSON 출력을 생성하도록 하려면 출력 스키마를 지정하면 됩니다. format: json를 지정하면 모델이 항상 지정된 스키마를 따르는 JSON 응답을 반환하도록 제한됩니다.
스키마는 스칼라 유형
string,integer,number,boolean,object를 지원합니다. 객체, 배열, enum은 필드 이름 뒤에 괄호가 표시됩니다.?로 선택사항임을 표시하지 않는 한 모든 속성은 필수 속성으로 간주됩니다. 속성이 선택사항으로 표시되면 LLM이 필드를 생략하는 대신 null을 반환하도록 편의를 제공하기 위해 null을 허용하도록 설정됩니다.
구조화된 JSON 출력을 생성하는 기본 예시는 다음과 같습니다. 아래에서 더 고급 스키마를 확인할 수 있습니다.
구성 (프런트매터)
---
model: gemini-2.5-flash
output:
format: json
schema:
invoiceId: string
invoiceFile(object, an invoice file):
url?: string
contents: string
mimeType: string
---
프롬프트 및 (해당하는 경우) 시스템 안내
Create an example customer invoice.
멀티모달 입력하기
Gemini 모델에 전송되는 멀티모달 프롬프트에는 파일(이미지, PDF, 일반 텍스트 파일, 오디오, 동영상과 함께 텍스트 등)을 비롯한 여러 유형의 입력이 포함될 수 있습니다.
{{media url}}구문을 사용하여 URL과 함께 파일을 제공합니다.{{media type="mime_type" data="contents"}}구문을 사용하여 인라인 파일을 제공합니다.
다음은 멀티모달 입력을 제공하는 기본 예시입니다. 아래에서 더 복잡한 예를 확인할 수 있습니다.
구성 (프런트매터)
---
model: 'gemini-2.5-flash'
---
프롬프트 및 (해당하는 경우) 시스템 안내
Describe this image
{{media type="mimeType" data="imageData"}}
Imagen (이미지 생성)
초기 출시에서 서버 프롬프트 템플릿은 Imagen 모델과 텍스트 전용 프롬프트를 사용한 이미지 생성을 지원합니다. Imagen로 이미지 수정(Vertex AI Gemini API 사용 시)을 비롯한 더 많은 지원이 곧 제공될 예정입니다.
기본
이 예에서는 Gemini과 유사한 입력 변수와 입력 유효성 검사를 사용하여 Imagen로 이미지를 생성하는 기본 템플릿을 보여줍니다.
구성 (프런트매터)
---
model: 'imagen-4.0-generate-001'
input:
schema:
prompt: 'string'
---
프롬프트 및 (해당하는 경우) 시스템 안내
Create an image containing {{prompt}}
고급
이 예시에서는 모델 구성을 추가하고 Gemini과 유사한 입력 변수, 입력 유효성 검사, 흐름 제어와 같은 프롬프트의 고급 기능을 사용하는 방법을 보여줍니다.
구성 (프런트매터)
---
model: 'imagen-4.0-fast-generate-001'
config:
sampleCount: 1
aspectRatio: "16:9"
personGeneration: dont_allow
includeRaiReason: true
input:
schema:
style(enum, The style of image): [photo, sketch, painting]
subject: string, The object or animal or scenery to generate.
context?: string, Optional background or context description.
default:
style: photo
---
프롬프트 및 (해당하는 경우) 시스템 안내
A {{style}} of {{subject}}{{#if context}}{{context}}{{/if}}.