Skip to content

Commit e4fcb00

Browse files
feat: [google-ai-generativelanguage] Add code execution (#12843)
- [ ] Regenerate this pull request now. feat: Add max_temperature docs: Minor fixes PiperOrigin-RevId: 646960455 Source-Link: googleapis/googleapis@cb060cb Source-Link: googleapis/googleapis-gen@64dcd13 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiNjRkY2QxMzViMzdiOTE1MjYyY2M2MTBlMGVjOWQ3YTc5NzAxMGY2MCJ9 --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Victor Chudnovsky <vchudnov@google.com>
1 parent c658971 commit e4fcb00

18 files changed

Lines changed: 223 additions & 29 deletions

File tree

packages/google-ai-generativelanguage/google/ai/generativelanguage/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181
)
8282
from google.ai.generativelanguage_v1beta.types.content import (
8383
Blob,
84+
CodeExecution,
85+
CodeExecutionResult,
8486
Content,
87+
ExecutableCode,
8588
FileData,
8689
FunctionCall,
8790
FunctionCallingConfig,
@@ -254,7 +257,10 @@
254257
"CitationMetadata",
255258
"CitationSource",
256259
"Blob",
260+
"CodeExecution",
261+
"CodeExecutionResult",
257262
"Content",
263+
"ExecutableCode",
258264
"FileData",
259265
"FunctionCall",
260266
"FunctionCallingConfig",

packages/google-ai-generativelanguage/google/ai/generativelanguage/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.6.5" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.6.5" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
from .types.citation import CitationMetadata, CitationSource
4848
from .types.content import (
4949
Blob,
50+
CodeExecution,
51+
CodeExecutionResult,
5052
Content,
53+
ExecutableCode,
5154
FileData,
5255
FunctionCall,
5356
FunctionCallingConfig,
@@ -220,6 +223,8 @@
220223
"ChunkData",
221224
"CitationMetadata",
222225
"CitationSource",
226+
"CodeExecution",
227+
"CodeExecutionResult",
223228
"Condition",
224229
"Content",
225230
"ContentEmbedding",
@@ -257,6 +262,7 @@
257262
"EmbedTextResponse",
258263
"Embedding",
259264
"Example",
265+
"ExecutableCode",
260266
"File",
261267
"FileData",
262268
"FileServiceClient",

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.6.5" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
from .citation import CitationMetadata, CitationSource
2626
from .content import (
2727
Blob,
28+
CodeExecution,
29+
CodeExecutionResult,
2830
Content,
31+
ExecutableCode,
2932
FileData,
3033
FunctionCall,
3134
FunctionCallingConfig,
@@ -182,7 +185,10 @@
182185
"CitationMetadata",
183186
"CitationSource",
184187
"Blob",
188+
"CodeExecution",
189+
"CodeExecutionResult",
185190
"Content",
191+
"ExecutableCode",
186192
"FileData",
187193
"FunctionCall",
188194
"FunctionCallingConfig",

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/content.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
"Part",
2929
"Blob",
3030
"FileData",
31+
"ExecutableCode",
32+
"CodeExecutionResult",
3133
"Tool",
34+
"CodeExecution",
3235
"ToolConfig",
3336
"FunctionCallingConfig",
3437
"FunctionDeclaration",
@@ -145,6 +148,15 @@ class Part(proto.Message):
145148
file_data (google.ai.generativelanguage_v1beta.types.FileData):
146149
URI based data.
147150
151+
This field is a member of `oneof`_ ``data``.
152+
executable_code (google.ai.generativelanguage_v1beta.types.ExecutableCode):
153+
Code generated by the model that is meant to
154+
be executed.
155+
156+
This field is a member of `oneof`_ ``data``.
157+
code_execution_result (google.ai.generativelanguage_v1beta.types.CodeExecutionResult):
158+
Result of executing the ``ExecutableCode``.
159+
148160
This field is a member of `oneof`_ ``data``.
149161
"""
150162

@@ -177,6 +189,18 @@ class Part(proto.Message):
177189
oneof="data",
178190
message="FileData",
179191
)
192+
executable_code: "ExecutableCode" = proto.Field(
193+
proto.MESSAGE,
194+
number=9,
195+
oneof="data",
196+
message="ExecutableCode",
197+
)
198+
code_execution_result: "CodeExecutionResult" = proto.Field(
199+
proto.MESSAGE,
200+
number=10,
201+
oneof="data",
202+
message="CodeExecutionResult",
203+
)
180204

181205

182206
class Blob(proto.Message):
@@ -228,6 +252,94 @@ class FileData(proto.Message):
228252
)
229253

230254

255+
class ExecutableCode(proto.Message):
256+
r"""Code generated by the model that is meant to be executed, and the
257+
result returned to the model.
258+
259+
Only generated when using the ``CodeExecution`` tool, in which the
260+
code will be automatically executed, and a corresponding
261+
``CodeExecutionResult`` will also be generated.
262+
263+
Attributes:
264+
language (google.ai.generativelanguage_v1beta.types.ExecutableCode.Language):
265+
Required. Programming language of the ``code``.
266+
code (str):
267+
Required. The code to be executed.
268+
"""
269+
270+
class Language(proto.Enum):
271+
r"""Supported programming languages for the generated code.
272+
273+
Values:
274+
LANGUAGE_UNSPECIFIED (0):
275+
Unspecified language. This value should not
276+
be used.
277+
PYTHON (1):
278+
Python >= 3.10, with numpy and simpy
279+
available.
280+
"""
281+
LANGUAGE_UNSPECIFIED = 0
282+
PYTHON = 1
283+
284+
language: Language = proto.Field(
285+
proto.ENUM,
286+
number=1,
287+
enum=Language,
288+
)
289+
code: str = proto.Field(
290+
proto.STRING,
291+
number=2,
292+
)
293+
294+
295+
class CodeExecutionResult(proto.Message):
296+
r"""Result of executing the ``ExecutableCode``.
297+
298+
Only generated when using the ``CodeExecution``, and always follows
299+
a ``part`` containing the ``ExecutableCode``.
300+
301+
Attributes:
302+
outcome (google.ai.generativelanguage_v1beta.types.CodeExecutionResult.Outcome):
303+
Required. Outcome of the code execution.
304+
output (str):
305+
Optional. Contains stdout when code execution
306+
is successful, stderr or other description
307+
otherwise.
308+
"""
309+
310+
class Outcome(proto.Enum):
311+
r"""Enumeration of possible outcomes of the code execution.
312+
313+
Values:
314+
OUTCOME_UNSPECIFIED (0):
315+
Unspecified status. This value should not be
316+
used.
317+
OUTCOME_OK (1):
318+
Code execution completed successfully.
319+
OUTCOME_FAILED (2):
320+
Code execution finished but with a failure. ``stderr``
321+
should contain the reason.
322+
OUTCOME_DEADLINE_EXCEEDED (3):
323+
Code execution ran for too long, and was
324+
cancelled. There may or may not be a partial
325+
output present.
326+
"""
327+
OUTCOME_UNSPECIFIED = 0
328+
OUTCOME_OK = 1
329+
OUTCOME_FAILED = 2
330+
OUTCOME_DEADLINE_EXCEEDED = 3
331+
332+
outcome: Outcome = proto.Field(
333+
proto.ENUM,
334+
number=1,
335+
enum=Outcome,
336+
)
337+
output: str = proto.Field(
338+
proto.STRING,
339+
number=2,
340+
)
341+
342+
231343
class Tool(proto.Message):
232344
r"""Tool details that the model may use to generate response.
233345
@@ -250,13 +362,31 @@ class Tool(proto.Message):
250362
[FunctionResponse][content.part.function_response] with the
251363
[content.role] "function" generation context for the next
252364
model turn.
365+
code_execution (google.ai.generativelanguage_v1beta.types.CodeExecution):
366+
Optional. Enables the model to execute code
367+
as part of generation.
253368
"""
254369

255370
function_declarations: MutableSequence["FunctionDeclaration"] = proto.RepeatedField(
256371
proto.MESSAGE,
257372
number=1,
258373
message="FunctionDeclaration",
259374
)
375+
code_execution: "CodeExecution" = proto.Field(
376+
proto.MESSAGE,
377+
number=3,
378+
message="CodeExecution",
379+
)
380+
381+
382+
class CodeExecution(proto.Message):
383+
r"""Tool that executes code generated by the model, and automatically
384+
returns the result to the model.
385+
386+
See also ``ExecutableCode`` and ``CodeExecutionResult`` which are
387+
only generated when using this tool.
388+
389+
"""
260390

261391

262392
class ToolConfig(proto.Message):

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/generative_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class BlockReason(proto.Enum):
431431
``safety_ratings`` to understand which safety category
432432
blocked it.
433433
OTHER (2):
434-
Prompt was blocked due to unknown reaasons.
434+
Prompt was blocked due to unknown reasons.
435435
"""
436436
BLOCK_REASON_UNSPECIFIED = 0
437437
SAFETY = 1

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/model.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,18 @@ class Model(proto.Message):
7676
temperature (float):
7777
Controls the randomness of the output.
7878
79-
Values can range over ``[0.0,2.0]``, inclusive. A higher
80-
value will produce responses that are more varied, while a
81-
value closer to ``0.0`` will typically result in less
82-
surprising responses from the model. This value specifies
83-
default to be used by the backend while making the call to
84-
the model.
79+
Values can range over ``[0.0,max_temperature]``, inclusive.
80+
A higher value will produce responses that are more varied,
81+
while a value closer to ``0.0`` will typically result in
82+
less surprising responses from the model. This value
83+
specifies default to be used by the backend while making the
84+
call to the model.
8585
8686
This field is a member of `oneof`_ ``_temperature``.
87+
max_temperature (float):
88+
The maximum temperature this model can use.
89+
90+
This field is a member of `oneof`_ ``_max_temperature``.
8791
top_p (float):
8892
For Nucleus sampling.
8993
@@ -142,6 +146,11 @@ class Model(proto.Message):
142146
number=9,
143147
optional=True,
144148
)
149+
max_temperature: float = proto.Field(
150+
proto.FLOAT,
151+
number=13,
152+
optional=True,
153+
)
145154
top_p: float = proto.Field(
146155
proto.FLOAT,
147156
number=10,

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta2/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.6.5" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

0 commit comments

Comments
 (0)