@@ -133,6 +133,7 @@ def __init__(
133
133
generation_config : Optional [GenerationConfigType ] = None ,
134
134
safety_settings : Optional [SafetySettingsType ] = None ,
135
135
tools : Optional [List ["Tool" ]] = None ,
136
+ system_instruction : Optional [PartsType ] = None ,
136
137
):
137
138
r"""Initializes GenerativeModel.
138
139
@@ -147,6 +148,9 @@ def __init__(
147
148
generation_config: Default generation config to use in generate_content.
148
149
safety_settings: Default safety settings to use in generate_content.
149
150
tools: Default tools to use in generate_content.
151
+ system_instruction: Default system instruction to use in generate_content.
152
+ Note: Only text should be used in parts.
153
+ Content of each part will become a separate paragraph.
150
154
"""
151
155
if "/" not in model_name :
152
156
model_name = "publishers/google/models/" + model_name
@@ -163,13 +167,15 @@ def __init__(
163
167
self ._generation_config = generation_config
164
168
self ._safety_settings = safety_settings
165
169
self ._tools = tools
170
+ self ._system_instruction = system_instruction
166
171
167
172
# Validating the parameters
168
173
self ._prepare_request (
169
174
contents = "test" ,
170
175
generation_config = generation_config ,
171
176
safety_settings = safety_settings ,
172
177
tools = tools ,
178
+ system_instruction = system_instruction ,
173
179
)
174
180
175
181
@property
@@ -205,6 +211,7 @@ def _prepare_request(
205
211
generation_config : Optional [GenerationConfigType ] = None ,
206
212
safety_settings : Optional [SafetySettingsType ] = None ,
207
213
tools : Optional [List ["Tool" ]] = None ,
214
+ system_instruction : Optional [PartsType ] = None ,
208
215
) -> gapic_prediction_service_types .GenerateContentRequest :
209
216
"""Prepares a GAPIC GenerateContentRequest."""
210
217
if not contents :
@@ -213,6 +220,7 @@ def _prepare_request(
213
220
generation_config = generation_config or self ._generation_config
214
221
safety_settings = safety_settings or self ._safety_settings
215
222
tools = tools or self ._tools
223
+ system_instruction = system_instruction or self ._system_instruction
216
224
217
225
# contents can either be a list of Content objects (most generic case)
218
226
if isinstance (contents , Sequence ) and any (
@@ -244,6 +252,10 @@ def _prepare_request(
244
252
else :
245
253
contents = [_to_content (contents )]
246
254
255
+ gapic_system_instruction : Optional [gapic_content_types .Content ] = None
256
+ if system_instruction :
257
+ gapic_system_instruction = _to_content (system_instruction )
258
+
247
259
gapic_generation_config : Optional [gapic_content_types .GenerationConfig ] = None
248
260
if generation_config :
249
261
if isinstance (generation_config , gapic_content_types .GenerationConfig ):
@@ -307,6 +319,7 @@ def _prepare_request(
307
319
generation_config = gapic_generation_config ,
308
320
safety_settings = gapic_safety_settings ,
309
321
tools = gapic_tools ,
322
+ system_instruction = gapic_system_instruction ,
310
323
)
311
324
312
325
def _parse_response (
0 commit comments