Module _prompts (1.117.0)
 
 
 
 
 
 
 Stay organized with collections
 
 
 
 Save and categorize content based on your preferences.
 
   
 
 
 
 
 - 1.122.0 (latest)
 - 1.121.0
 - 1.120.0
 - 1.119.0
 - 1.118.0
 - 1.117.0
 - 1.95.1
 - 1.94.0
 - 1.93.1
 - 1.92.0
 - 1.91.0
 - 1.90.0
 - 1.89.0
 - 1.88.0
 - 1.87.0
 - 1.86.0
 - 1.85.0
 - 1.84.0
 - 1.83.0
 - 1.82.0
 - 1.81.0
 - 1.80.0
 - 1.79.0
 - 1.78.0
 - 1.77.0
 - 1.76.0
 - 1.75.0
 - 1.74.0
 - 1.73.0
 - 1.72.0
 - 1.71.1
 - 1.70.0
 - 1.69.0
 - 1.68.0
 - 1.67.1
 - 1.66.0
 - 1.65.0
 - 1.63.0
 - 1.62.0
 - 1.60.0
 - 1.59.0
 
API documentation for _prompts module.
Classes
Prompt
Prompt(
 prompt_data: typing.Optional[PartsType] = None,
 *,
 variables: typing.Optional[typing.List[typing.Dict[str, PartsType]]] = None,
 prompt_name: typing.Optional[str] = None,
 generation_config: typing.Optional[
 vertexai.generative_models._generative_models.GenerationConfig
 ] = None,
 model_name: typing.Optional[str] = None,
 safety_settings: typing.Optional[
 vertexai.generative_models._generative_models.SafetySetting
 ] = None,
 system_instruction: typing.Optional[PartsType] = None,
 tools: typing.Optional[
 typing.List[vertexai.generative_models._generative_models.Tool]
 ] = None,
 tool_config: typing.Optional[
 vertexai.generative_models._generative_models.ToolConfig
 ] = None
)A prompt which may be a template with variables.
The Prompt class allows users to define a template string with
variables represented in curly braces {variable}. The variable
name must be a valid Python variable name (no spaces, must start with a
letter). These placeholders can be replaced with specific values using the
assemble_contents method, providing flexibility in generating dynamic prompts.
Usage: Generate content from a single set of variables:
prompt = Prompt(
 prompt_data="Hello, {name}! Today is {day}. How are you?",
 variables=[{"name": "Alice", "day": "Monday"}]
 generation_config=GenerationConfig(
 temperature=0.1,
 top_p=0.95,
 top_k=20,
 candidate_count=1,
 max_output_tokens=100,
 ),
 model_name="gemini-1.0-pro-002",
 safety_settings=[SafetySetting(
 category=SafetySetting.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
 threshold=SafetySetting.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
 method=SafetySetting.HarmBlockMethod.SEVERITY,
 )],
 system_instruction="Please answer in a short sentence.",
)
# Generate content using the assembled prompt.
prompt.generate_content(
 contents=prompt.assemble_contents(**prompt.variables)
)
```
Generate content with multiple sets of variables:
```
prompt = Prompt(
 prompt_data="Hello, {name}! Today is {day}. How are you?",
 variables=[
 {"name": "Alice", "day": "Monday"},
 {"name": "Bob", "day": "Tuesday"},
 ],
 generation_config=GenerationConfig(
 temperature=0.1,
 top_p=0.95,
 top_k=20,
 candidate_count=1,
 max_output_tokens=100,
 ),
 model_name="gemini-1.0-pro-002",
 safety_settings=[SafetySetting(
 category=SafetySetting.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
 threshold=SafetySetting.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
 method=SafetySetting.HarmBlockMethod.SEVERITY,
 )],
 system_instruction="Please answer in a short sentence.",
)
# Generate content using the assembled prompt for each variable set.
for i in range(len(prompt.variables)):
 prompt.generate_content(
 contents=prompt.assemble_contents(**prompt.variables[i])
 )
```