@@ -191,6 +191,95 @@ def _generate_target_table_id(dataset_id: str):
191
191
return f"{ dataset_id } .{ _DEFAULT_BQ_TABLE_PREFIX } _{ str (uuid .uuid4 ())} "
192
192
193
193
194
+ def construct_single_turn_template (
195
+ * ,
196
+ prompt : str = None ,
197
+ response : Optional [str ] = None ,
198
+ system_instruction : Optional [str ] = None ,
199
+ model : Optional [str ] = None ,
200
+ cached_content : Optional [str ] = None ,
201
+ tools : Optional [List [generative_models .Tool ]] = None ,
202
+ tool_config : Optional [generative_models .ToolConfig ] = None ,
203
+ safety_settings : Optional [List [generative_models .SafetySetting ]] = None ,
204
+ generation_config : Optional [generative_models .GenerationConfig ] = None ,
205
+ field_mapping : List [Dict [str , str ]] = None ,
206
+ ) -> "GeminiTemplateConfig" :
207
+ """Constructs a GeminiTemplateConfig object for single-turn cases.
208
+
209
+ Example:
210
+ template_config = dataset.construct_single_turn_template(
211
+ prompt = "Which flower is this {flower_image} ?",
212
+ response="This is a {label}.",
213
+ system_instruction="You are a botanical classifier."
214
+ )
215
+
216
+ Args:
217
+
218
+ prompt (str):
219
+ Required. User input.
220
+ response (str):
221
+ Optional. Model response to user input.
222
+ system_instruction (str):
223
+ Optional. System instructions for the model.
224
+ model (str):
225
+ Optional. The model to use for the GeminiExample.
226
+ cached_content (str):
227
+ Optional. The cached content to use for the GeminiExample.
228
+ tools (List[Tool]):
229
+ Optional. The tools to use for the GeminiExample.
230
+ tool_config (ToolConfig):
231
+ Optional. The tool config to use for the GeminiExample.
232
+ safety_settings (List[SafetySetting]):
233
+ Optional. The safety settings to use for the GeminiExample.
234
+ generation_config (GenerationConfig):
235
+ Optional. The generation config to use for the GeminiExample.
236
+ field_mapping (List[Dict[str, str]]):
237
+ Optional. Mapping of placeholders to dataset columns.
238
+
239
+ Returns:
240
+ A GeminiTemplateConfig object.
241
+ """
242
+ contents = []
243
+ contents .append (
244
+ generative_models .Content (
245
+ role = "user" ,
246
+ parts = [
247
+ generative_models .Part .from_text (prompt ),
248
+ ],
249
+ )
250
+ )
251
+ if response :
252
+ contents .append (
253
+ generative_models .Content (
254
+ role = "model" ,
255
+ parts = [
256
+ generative_models .Part .from_text (response ),
257
+ ],
258
+ )
259
+ )
260
+ if system_instruction :
261
+ system_instruction = generative_models .Content (
262
+ parts = [
263
+ generative_models .Part .from_text (system_instruction ),
264
+ ],
265
+ )
266
+
267
+ # Set up GeminiExample.
268
+ gemini_example = GeminiExample (
269
+ model = model ,
270
+ contents = contents ,
271
+ system_instruction = system_instruction ,
272
+ cached_content = cached_content ,
273
+ tools = tools ,
274
+ tool_config = tool_config ,
275
+ safety_settings = safety_settings ,
276
+ generation_config = generation_config ,
277
+ )
278
+ return GeminiTemplateConfig (
279
+ gemini_example = gemini_example , field_mapping = field_mapping
280
+ )
281
+
282
+
194
283
class GeminiExample :
195
284
"""A class representing a Gemini example."""
196
285
0 commit comments