ในการเรียกใช้แต่ละครั้ง คุณสามารถส่งการกำหนดค่ารูปแบบไปด้วยเพื่อควบคุมวิธีที่รูปแบบสร้างคำตอบ โดยแต่ละรุ่นจะมีตัวเลือกการกำหนดค่าที่แตกต่างกัน
นอกจากนี้ คุณยังทดสอบพรอมต์และการกําหนดค่ารูปแบบได้โดยใช้ Google AI StudioGemini ข้ามไปยังตัวเลือกการกําหนดค่า Imagen ข้ามไปยังตัวเลือกการกําหนดค่า
กำหนดค่าโมเดล Gemini
คลิกผู้ให้บริการ Gemini API เพื่อดูเนื้อหาและโค้ดเฉพาะผู้ให้บริการในหน้านี้ |
ส่วนนี้จะแสดงวิธีตั้งค่าการกําหนดค่าเพื่อใช้กับรูปแบบ Gemini และอธิบายพารามิเตอร์แต่ละรายการ
ตั้งค่าการกําหนดค่ารูปแบบ (Gemini)
การกําหนดค่าสําหรับกรณีการใช้งานทั่วไป
การกำหนดค่าจะคงอยู่ตลอดอายุการใช้งานของอินสแตนซ์ หากต้องการใช้การกําหนดค่าอื่น ให้สร้างอินสแตนซ์ GenerativeModel
ใหม่โดยใช้การกําหนดค่านั้น
Swift
ตั้งค่าพารามิเตอร์ใน GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
import FirebaseAI
// Set parameter values in a `GenerationConfig` (example values shown here)
let config = GenerationConfig(
temperature: 0.9,
topP: 0.1,
topK: 16,
maxOutputTokens: 200,
stopSequences: ["red"]
)
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `GenerativeModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
ตั้งค่าพารามิเตอร์ใน GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
val config = generationConfig {
maxOutputTokens = 200
stopSequences = listOf("red")
temperature = 0.9f
topK = 16
topP = 0.1f
}
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
generationConfig = config
)
// ...
Java
ตั้งค่าพารามิเตอร์ใน GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = List.of("red");
configBuilder.temperature = 0.9f;
configBuilder.topK = 16;
configBuilder.topP = 0.1f;
GenerationConfig config = configBuilder.build();
// Specify the config as part of creating the `GenerativeModel` instance
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
"GEMINI_MODEL_NAME",
config
);
);
// ...
Web
ตั้งค่าพารามิเตอร์ใน GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set parameter values in a `GenerationConfig` (example values shown here)
const generationConfig = {
max_output_tokens: 200,
stop_sequences: ["red"],
temperature: 0.9,
top_p: 0.1,
top_k: 16,
};
// Specify the config as part of creating the `GenerativeModel` instance
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });
// ...
Dart
ตั้งค่าพารามิเตอร์ใน GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
final generationConfig = GenerationConfig(
maxOutputTokens: 200,
stopSequences: ["red"],
temperature: 0.9,
topP: 0.1,
topK: 16,
);
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `GenerativeModel` instance
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
config: generationConfig,
);
// ...
Unity
ตั้งค่าพารามิเตอร์ใน GenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ GenerativeModel
// ...
// Set parameter values in a `GenerationConfig` (example values shown here)
var generationConfig = new GenerationConfig(
maxOutputTokens: 200,
stopSequences: new string[] { "red" },
temperature: 0.9f,
topK: 16,
topP: 0.1f
);
// Specify the config as part of creating the `GenerativeModel` instance
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
);
ดูคําอธิบายของพารามิเตอร์แต่ละรายการได้ในส่วนถัดไปของหน้านี้
การกำหนดค่าสำหรับ Gemini Live API
คำอธิบายพารามิเตอร์ (Gemini)
ต่อไปนี้เป็นภาพรวมระดับสูงของพารามิเตอร์ที่ใช้ได้ (หากมี) ดูรายการพารามิเตอร์และค่าที่ครอบคลุมได้ในเอกสารประกอบของ Gemini Developer API
พารามิเตอร์ | คำอธิบาย | ค่าเริ่มต้น |
---|---|---|
การประทับเวลาของเสียง
audioTimestamp
|
บูลีนที่ช่วยในการทําความเข้าใจการประทับเวลาสําหรับไฟล์อินพุตที่เป็นเสียงเท่านั้น ใช้ได้เฉพาะเมื่อใช้การเรียกใช้ |
false |
การปรับลดความถี่
frequencyPenalty
|
ควบคุมความน่าจะเป็นที่จะรวมโทเค็นที่ปรากฏซ้ำๆ ในคำตอบที่สร้างขึ้น ค่าบวกจะลงโทษโทเค็นที่ปรากฏซ้ำๆ ในเนื้อหาที่สร้างขึ้น ซึ่งจะลดโอกาสที่จะมีเนื้อหาซ้ำ |
--- |
โทเค็นเอาต์พุตสูงสุด
maxOutputTokens
|
ระบุจำนวนโทเค็นสูงสุดที่สามารถสร้างในการตอบกลับ | --- |
ค่าปรับการปรากฏ
presencePenalty
|
ควบคุมความน่าจะเป็นที่จะรวมโทเค็นที่ปรากฏอยู่ในคำตอบที่สร้างขึ้นแล้ว ค่าบวกจะลงโทษโทเค็นที่ปรากฏอยู่ในเนื้อหาที่สร้างขึ้นแล้ว ซึ่งจะเพิ่มโอกาสในการสร้างเนื้อหาที่หลากหลายมากขึ้น |
--- |
หยุดลำดับ
stopSequences
|
ระบุรายการสตริงที่จะบอกให้โมเดลหยุดสร้างเนื้อหาหากพบสตริงใดสตริงหนึ่งในคำตอบ ใช้ได้เฉพาะเมื่อใช้การกำหนดค่า |
--- |
อุณหภูมิ
temperature
|
ควบคุมระดับความสุ่มในการตอบ อุณหภูมิที่ต่ำลงส่งผลให้คำตอบมีรูปแบบตายตัวมากขึ้น และอุณหภูมิที่สูงขึ้นส่งผลให้คำตอบมีความหลากหลายหรือสร้างสรรค์มากขึ้น |
ขึ้นอยู่กับรุ่น |
Top-K
topK
|
จำกัดจำนวนคำที่มีความเป็นไปได้สูงสุดซึ่งใช้ในเนื้อหาที่สร้างขึ้น ค่า Top-K เท่ากับ 1 หมายความว่าโทเค็นที่เลือกถัดไปควรเป็นโทเค็นที่มีแนวโน้มมากที่สุดในบรรดาโทเค็นทั้งหมดในคลังคำของโมเดล ส่วนค่า Top-K เท่ากับ n หมายความว่าควรเลือกโทเค็นถัดไปจากโทเค็นที่มีแนวโน้มมากที่สุด n รายการ (ทั้งหมดขึ้นอยู่กับอุณหภูมิที่ตั้งไว้)
|
ขึ้นอยู่กับรุ่น |
Top-P
topP
|
ควบคุมความหลากหลายของเนื้อหาที่สร้างขึ้น ระบบจะเลือกโทเค็นจากที่มีแนวโน้มมากที่สุด (ดูที่ top-K ด้านบน) ไปจนถึงมีแนวโน้มน้อยที่สุดจนกว่าผลรวมของแนวโน้มจะเท่ากับค่า top-P |
ขึ้นอยู่กับรุ่น |
รูปแบบคำตอบ
responseModality
|
ระบุประเภทของเอาต์พุตที่สตรีมเมื่อใช้ Live API เช่น ข้อความหรือเสียง ใช้ได้เฉพาะเมื่อใช้การกำหนดค่า Live API และ |
--- |
เสียงพูด (เสียง)
speechConfig
|
ระบุเสียงที่ใช้สำหรับเอาต์พุตเสียงที่สตรีมเมื่อใช้ Live API ใช้ได้เฉพาะเมื่อใช้การกำหนดค่า Live API และ |
Puck |
กำหนดค่าโมเดล Imagen
คลิกผู้ให้บริการ Imagen API เพื่อดูเนื้อหาและโค้ดเฉพาะผู้ให้บริการในหน้านี้ |
ส่วนนี้จะแสดงวิธีตั้งค่าการกําหนดค่าเพื่อใช้กับรูปแบบ Imagen และอธิบายพารามิเตอร์แต่ละรายการ
ตั้งค่าการกําหนดค่ารูปแบบ (Imagen)
การกำหนดค่าจะคงอยู่ตลอดอายุการใช้งานของอินสแตนซ์ หากต้องการใช้การกําหนดค่าอื่น ให้สร้างอินสแตนซ์ ImagenModel
ใหม่โดยใช้การกําหนดค่านั้น
Swift
ตั้งค่าพารามิเตอร์ใน ImagenGenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ ImagenModel
import FirebaseAI
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
let config = ImagenGenerationConfig(
negativePrompt: "frogs",
numberOfImages: 2,
aspectRatio: .landscape16x9,
imageFormat: .jpeg(compressionQuality: 100),
addWatermark: false
)
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `ImagenModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).imagenModel(
modelName: "IMAGEN_MODEL_NAME",
generationConfig: config
)
// ...
Kotlin
ตั้งค่าพารามิเตอร์ใน ImagenGenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ ImagenModel
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
val config = ImagenGenerationConfig {
negativePrompt = "frogs",
numberOfImages = 2,
aspectRatio = ImagenAspectRatio.LANDSCAPE_16x9,
imageFormat = ImagenImageFormat.jpeg(compressionQuality = 100),
addWatermark = false
}
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel(
modelName = "IMAGEN_MODEL_NAME",
generationConfig = config
)
// ...
Java
ตั้งค่าพารามิเตอร์ใน ImagenGenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ ImagenModel
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
ImagenGenerationConfig config = new ImagenGenerationConfig.Builder()
.setNegativePrompt("frogs")
.setNumberOfImages(2)
.setAspectRatio(ImagenAspectRatio.LANDSCAPE_16x9)
.setImageFormat(ImagenImageFormat.jpeg(100))
.setAddWatermark(false)
.build();
// Specify the config as part of creating the `ImagenModel` instance
ImagenModelFutures model = ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.imagenModel(
"IMAGEN_MODEL_NAME",
config
);
);
// ...
Web
ตั้งค่าพารามิเตอร์ใน ImagenGenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ ImagenModel
// ...
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
const generationConfig = {
negativePrompt: "frogs",
numberOfImages: 2,
aspectRatio: ImagenAspectRatio.LANDSCAPE_16x9,
imageFormat: ImagenImageFormat.jpeg(100),
addWatermark: false
};
// Specify the config as part of creating the `ImagenModel` instance
const model = getImagenModel(ai, { model: "IMAGEN_MODEL_NAME", generationConfig });
// ...
Dart
ตั้งค่าพารามิเตอร์ใน ImagenGenerationConfig
เป็นส่วนหนึ่งของการสร้างอินสแตนซ์ ImagenModel
// ...
// Set parameter values in a `ImagenGenerationConfig` (example values shown here)
final generationConfig = ImagenGenerationConfig(
negativePrompt: 'frogs',
numberOfImages: 2,
aspectRatio: ImagenAspectRatio.landscape16x9,
imageFormat: ImagenImageFormat.jpeg(compressionQuality: 100)
addWatermark: false
);
// Initialize the Gemini Developer API backend service
// Specify the config as part of creating the `ImagenModel` instance
final model = FirebaseAI.googleAI().imagenModel(
model: 'IMAGEN_MODEL_NAME',
config: generationConfig,
);
// ...
Unity
Unity ยังไม่รองรับการใช้ Imagen แต่โปรดกลับมาตรวจสอบอีกครั้งในเร็วๆ นี้
ดูคําอธิบายของพารามิเตอร์แต่ละรายการได้ในส่วนถัดไปของหน้านี้
คำอธิบายพารามิเตอร์ (Imagen)
ต่อไปนี้เป็นภาพรวมระดับสูงของพารามิเตอร์ที่ใช้ได้ (หากมี) ดูรายการพารามิเตอร์และค่าที่ครอบคลุมได้ในเอกสารประกอบของ Google Cloud
พารามิเตอร์ | คำอธิบาย | ค่าเริ่มต้น |
---|---|---|
พรอมต์เชิงลบ
negativePrompt
|
คําอธิบายสิ่งที่คุณต้องการละเว้นในรูปภาพที่สร้างขึ้น
|
--- |
จํานวนผลลัพธ์
numberOfImages
|
จํานวนรูปภาพที่สร้างขึ้นซึ่งแสดงสําหรับคําขอแต่ละรายการ | ค่าเริ่มต้นคือรูปภาพ 1 รูปสำหรับรุ่น Imagen 3 |
สัดส่วนภาพ
aspectRatio
|
อัตราส่วนความกว้างต่อความสูงของรูปภาพที่สร้างขึ้น | ค่าเริ่มต้นคือสี่เหลี่ยมจัตุรัส (1:1) |
รูปแบบรูปภาพ
imageFormat
|
ตัวเลือกเอาต์พุต เช่น รูปแบบรูปภาพ (ประเภท MIME) และระดับการบีบอัดรูปภาพที่สร้างขึ้น | ประเภท MIME เริ่มต้นคือ PNG การบีบอัดเริ่มต้นคือ 75 (หากตั้งค่าประเภท MIME เป็น JPEG) |
ลายน้ำ
addWatermark
|
เลือกว่าจะเพิ่มลายน้ำดิจิทัลที่มองไม่เห็น (เรียกว่า SynthID) ลงในรูปภาพที่สร้างขึ้นหรือไม่ | ค่าเริ่มต้นคือ true สำหรับรุ่น Imagen 3
|
การสร้างบุคคล
personGeneration
|
อนุญาตให้สร้างผู้คนตามโมเดลหรือไม่ | ค่าเริ่มต้นขึ้นอยู่กับรุ่น |
ตัวเลือกอื่นๆ ในการควบคุมการสร้างเนื้อหา
- ดูข้อมูลเพิ่มเติมเกี่ยวกับการออกแบบพรอมต์เพื่อให้คุณควบคุมโมเดลให้สร้างเอาต์พุตที่ตรงกับความต้องการของคุณได้
- ใช้การตั้งค่าความปลอดภัยเพื่อปรับความเป็นไปได้ที่จะได้รับคำตอบที่อาจถือว่ามีอันตราย ซึ่งรวมถึงวาจาสร้างความเกลียดชังและเนื้อหาเกี่ยวกับเรื่องเพศอย่างโจ่งแจ้ง
- ตั้งค่าคำสั่งของระบบเพื่อกำหนดลักษณะการทำงานของโมเดล ฟีเจอร์นี้เปรียบเสมือนคํานําที่คุณเพิ่มก่อนให้โมเดลแสดงคําสั่งเพิ่มเติมจากผู้ใช้ปลายทาง
- ส่งสคีมาคำตอบ wraz zพรอมต์เพื่อระบุสคีมาเอาต์พุตที่เฉพาะเจาะจง ฟีเจอร์นี้มักใช้เมื่อสร้างเอาต์พุต JSON แต่สามารถใช้กับงานการจัดประเภทได้ด้วย (เช่น เมื่อคุณต้องการให้โมเดลใช้ป้ายกำกับหรือแท็กที่เฉพาะเจาะจง)