用于控制回答生成的选项
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以根据自己的使用情形和所需的控制程度,通过多种方式控制回答的生成。
提示设计
了解提示设计,以便影响模型生成符合您需求的输出内容。
例如,了解如何以结构化方式提供与任务相关的相关信息。
模型配置
设置模型配置以控制模型如何生成回答。配置选项取决于您使用的模型和功能。
对于 Gemini 模型,您可以配置输出 token 数量上限、温度、Top-K 和 Top-P 等参数。如果您使用的是 Gemini Live API 或能够生成多模态输出的 Gemini 模型,还可以配置回答类型(音频、文本或图片)以及音频回答中使用的语音。对于 Gemini 2.5 模型,您还可以配置思考预算。
对于 Imagen 模型,您可以配置要生成的图片数量、宽高比、添加水印等参数。
安全设置
使用安全设置可调整获得可能被视为有害的回答的可能性。这些设置有助于您控制输出,避免出现可能的仇恨言论、骚扰内容、露骨色情内容和危险内容。
例如,您可以屏蔽宣传或允许访问有害商品、服务和活动的回答。
系统指令
设置系统指令以引导模型的行为。此功能就像一段“序言”,在模型接收到最终用户的进一步指令之前添加。
例如,您可以指示模型以海盗的身份返回回答,或者以特定格式返回回答。
使用回答架构的结构化输出
传递回答架构以及提示,以指定特定的输出架构。此功能最常用于生成 JSON 输出,但也可用于分类任务(例如,当您希望模型使用特定标签时)。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-19。
[null,null,["最后更新时间 (UTC):2025-08-19。"],[],[],null,["\u003cbr /\u003e\n\nYou can control the generation of responses in a variety of ways depending on\nyour use case and the level of control that you need.\n\nPrompt design\n\nLearn about [prompt design](/docs/ai-logic/prompt-design) so that you can\ninfluence the model to generate output specific to your needs.\n\nFor example, learn how to provide relevant information associated with the task\nin a structured way.\n\nModel configuration\n\nSet a [model configuration](/docs/ai-logic/model-parameters) to control how\nthe model generates a response. The configuration options depend on the model\nand capability that you're using.\n\nFor Gemini models, you can configure parameters like\nmax output tokens, temperature, top-K, and top-P. And if you're using the\nGemini Live API or a Gemini model capable of multimodal output, you can\nadditionally configure the type of response (audio, text, or images)\nand the voice used in audio responses. For Gemini 2.5 models, you can\nalso configure the [thinking budget](/docs/ai-logic/thinking).\n\nFor Imagen models, you can configure parameters like\nnumber of images to generate, aspect ratio, adding a watermark, etc.\n\nSafety settings\n\nUse [safety settings](/docs/ai-logic/safety-settings) to adjust the likelihood\nof getting responses that may be considered harmful. These settings can help you\nwith controlling output for possible hate speech, harassment,\nsexual explicitness, and dangerous content.\n\nFor example, you can block responses that promote or enable access to harmful\ngoods, services, and activities.\n\nSystem instructions\n\nSet [system instructions](/docs/ai-logic/system-instructions) to steer the\nbehavior of the model. This feature is like a \"preamble\" that you add before\nthe model gets exposed to any further instructions from the end user.\n\nFor example, you can tell the model to return responses as if it were a pirate\nor to return responses in a specific format.\n\nStructured output using response schema\n\nPass a [*response schema*](/docs/ai-logic/generate-structured-output)\nalong with the prompt to specify a specific output schema. This feature is\nmost commonly used when\n[generating JSON output](/docs/ai-logic/generate-structured-output#generate-json-basic),\nbut it can also be used for\n[classification tasks](/docs/ai-logic/generate-structured-output#generate-enum-basic)\n(like when you want the model to use specific labels or tags)."]]