@@ -73,6 +73,8 @@ def __init__(
73
73
safety_settings : safety_types .SafetySettingOptions | None = None ,
74
74
generation_config : generation_types .GenerationConfigType | None = None ,
75
75
tools : content_types .FunctionLibraryType | None = None ,
76
+ tool_config : content_types .ToolConfigType | None = None ,
77
+ system_instructions : content_types .ContentType | None = None ,
76
78
):
77
79
if "/" not in model_name :
78
80
model_name = "models/" + model_name
@@ -83,6 +85,16 @@ def __init__(
83
85
self ._generation_config = generation_types .to_generation_config_dict (generation_config )
84
86
self ._tools = content_types .to_function_library (tools )
85
87
88
+ if tool_config is None :
89
+ self ._tool_config = None
90
+ else :
91
+ self ._tool_config = content_types .to_tool_config (tool_config )
92
+
93
+ if system_instructions is None :
94
+ self ._system_instructions = None
95
+ else :
96
+ self ._system_instructions = content_types .to_content (system_instructions )
97
+
86
98
self ._client = None
87
99
self ._async_client = None
88
100
@@ -110,6 +122,7 @@ def _prepare_request(
110
122
generation_config : generation_types .GenerationConfigType | None = None ,
111
123
safety_settings : safety_types .SafetySettingOptions | None = None ,
112
124
tools : content_types .FunctionLibraryType | None ,
125
+ tool_config : content_types .ToolConfigType | None ,
113
126
) -> glm .GenerateContentRequest :
114
127
"""Creates a `glm.GenerateContentRequest` from raw inputs."""
115
128
if not contents :
@@ -119,6 +132,11 @@ def _prepare_request(
119
132
if tools_lib is not None :
120
133
tools_lib = tools_lib .to_proto ()
121
134
135
+ if tool_config is None :
136
+ tool_config = self ._tool_config
137
+ else :
138
+ tool_config = content_types .to_tool_config (tool_config )
139
+
122
140
contents = content_types .to_contents (contents )
123
141
124
142
generation_config = generation_types .to_generation_config_dict (generation_config )
@@ -136,6 +154,8 @@ def _prepare_request(
136
154
generation_config = merged_gc ,
137
155
safety_settings = merged_ss ,
138
156
tools = tools_lib ,
157
+ tool_config = tool_config ,
158
+ system_instructions = self ._system_instructions ,
139
159
)
140
160
141
161
def _get_tools_lib (
@@ -154,6 +174,7 @@ def generate_content(
154
174
safety_settings : safety_types .SafetySettingOptions | None = None ,
155
175
stream : bool = False ,
156
176
tools : content_types .FunctionLibraryType | None = None ,
177
+ tool_config : content_types .ToolConfigType | None = None ,
157
178
request_options : dict [str , Any ] | None = None ,
158
179
) -> generation_types .GenerateContentResponse :
159
180
"""A multipurpose function to generate responses from the model.
@@ -215,6 +236,7 @@ def generate_content(
215
236
generation_config = generation_config ,
216
237
safety_settings = safety_settings ,
217
238
tools = tools ,
239
+ tool_config = tool_config ,
218
240
)
219
241
if self ._client is None :
220
242
self ._client = client .get_default_generative_client ()
@@ -252,6 +274,7 @@ async def generate_content_async(
252
274
safety_settings : safety_types .SafetySettingOptions | None = None ,
253
275
stream : bool = False ,
254
276
tools : content_types .FunctionLibraryType | None = None ,
277
+ tool_config : content_types .ToolConfigType | None = None ,
255
278
request_options : dict [str , Any ] | None = None ,
256
279
) -> generation_types .AsyncGenerateContentResponse :
257
280
"""The async version of `GenerativeModel.generate_content`."""
@@ -260,6 +283,7 @@ async def generate_content_async(
260
283
generation_config = generation_config ,
261
284
safety_settings = safety_settings ,
262
285
tools = tools ,
286
+ tool_config = tool_config ,
263
287
)
264
288
if self ._async_client is None :
265
289
self ._async_client = client .get_default_generative_async_client ()
@@ -388,6 +412,7 @@ def send_message(
388
412
safety_settings : safety_types .SafetySettingOptions = None ,
389
413
stream : bool = False ,
390
414
tools : content_types .FunctionLibraryType | None = None ,
415
+ tool_config : content_types .ToolConfigType | None = None ,
391
416
) -> generation_types .GenerateContentResponse :
392
417
"""Sends the conversation history with the added message and returns the model's response.
393
418
@@ -446,6 +471,7 @@ def send_message(
446
471
safety_settings = safety_settings ,
447
472
stream = stream ,
448
473
tools = tools_lib ,
474
+ tool_config = tool_config ,
449
475
)
450
476
451
477
self ._check_response (response = response , stream = stream )
@@ -529,6 +555,7 @@ async def send_message_async(
529
555
safety_settings : safety_types .SafetySettingOptions = None ,
530
556
stream : bool = False ,
531
557
tools : content_types .FunctionLibraryType | None = None ,
558
+ tool_config : content_types .ToolConfigType | None = None ,
532
559
) -> generation_types .AsyncGenerateContentResponse :
533
560
"""The async version of `ChatSession.send_message`."""
534
561
if self .enable_automatic_function_calling and stream :
@@ -557,6 +584,7 @@ async def send_message_async(
557
584
safety_settings = safety_settings ,
558
585
stream = stream ,
559
586
tools = tools_lib ,
587
+ tool_config = tool_config ,
560
588
)
561
589
562
590
self ._check_response (response = response , stream = stream )
0 commit comments