Skip to content

Commit 9b8ab02

Browse files
authored
feat(ai): Add code execution (#9249)
1 parent 120a308 commit 9b8ab02

22 files changed

+804
-19
lines changed

.changeset/lucky-socks-roll.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/ai': minor
3+
'firebase': minor
4+
---
5+
6+
Added Code Execution feature.

common/api-review/ai.api.md

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,39 @@ export interface CitationMetadata {
174174
citations: Citation[];
175175
}
176176

177+
// @public
178+
export interface CodeExecutionResult {
179+
outcome?: Outcome;
180+
output?: string;
181+
}
182+
183+
// @public
184+
export interface CodeExecutionResultPart {
185+
// (undocumented)
186+
codeExecutionResult?: CodeExecutionResult;
187+
// (undocumented)
188+
executableCode?: never;
189+
// (undocumented)
190+
fileData: never;
191+
// (undocumented)
192+
functionCall?: never;
193+
// (undocumented)
194+
functionResponse?: never;
195+
// (undocumented)
196+
inlineData?: never;
197+
// (undocumented)
198+
text?: never;
199+
// (undocumented)
200+
thought?: never;
201+
// @internal (undocumented)
202+
thoughtSignature?: never;
203+
}
204+
205+
// @public
206+
export interface CodeExecutionTool {
207+
codeExecution: {};
208+
}
209+
177210
// @public
178211
export interface Content {
179212
// (undocumented)
@@ -237,6 +270,34 @@ export interface ErrorDetails {
237270
reason?: string;
238271
}
239272

273+
// @public
274+
export interface ExecutableCode {
275+
code?: string;
276+
language?: Language;
277+
}
278+
279+
// @public
280+
export interface ExecutableCodePart {
281+
// (undocumented)
282+
codeExecutionResult?: never;
283+
// (undocumented)
284+
executableCode?: ExecutableCode;
285+
// (undocumented)
286+
fileData: never;
287+
// (undocumented)
288+
functionCall?: never;
289+
// (undocumented)
290+
functionResponse?: never;
291+
// (undocumented)
292+
inlineData?: never;
293+
// (undocumented)
294+
text?: never;
295+
// (undocumented)
296+
thought?: never;
297+
// @internal (undocumented)
298+
thoughtSignature?: never;
299+
}
300+
240301
// @public
241302
export interface FileData {
242303
// (undocumented)
@@ -247,6 +308,10 @@ export interface FileData {
247308

248309
// @public
249310
export interface FileDataPart {
311+
// (undocumented)
312+
codeExecutionResult?: never;
313+
// (undocumented)
314+
executableCode?: never;
250315
// (undocumented)
251316
fileData: FileData;
252317
// (undocumented)
@@ -308,6 +373,10 @@ export type FunctionCallingMode = (typeof FunctionCallingMode)[keyof typeof Func
308373

309374
// @public
310375
export interface FunctionCallPart {
376+
// (undocumented)
377+
codeExecutionResult?: never;
378+
// (undocumented)
379+
executableCode?: never;
311380
// (undocumented)
312381
functionCall: FunctionCall;
313382
// (undocumented)
@@ -345,6 +414,10 @@ export interface FunctionResponse {
345414

346415
// @public
347416
export interface FunctionResponsePart {
417+
// (undocumented)
418+
codeExecutionResult?: never;
419+
// (undocumented)
420+
executableCode?: never;
348421
// (undocumented)
349422
functionCall?: never;
350423
// (undocumented)
@@ -735,6 +808,10 @@ export type InferenceMode = (typeof InferenceMode)[keyof typeof InferenceMode];
735808

736809
// @public
737810
export interface InlineDataPart {
811+
// (undocumented)
812+
codeExecutionResult?: never;
813+
// (undocumented)
814+
executableCode?: never;
738815
// (undocumented)
739816
functionCall?: never;
740817
// (undocumented)
@@ -755,6 +832,15 @@ export class IntegerSchema extends Schema {
755832
constructor(schemaParams?: SchemaParams);
756833
}
757834

835+
// @public
836+
export const Language: {
837+
UNSPECIFIED: string;
838+
PYTHON: string;
839+
};
840+
841+
// @public
842+
export type Language = (typeof Language)[keyof typeof Language];
843+
758844
// @public
759845
export interface LanguageModelCreateCoreOptions {
760846
// (undocumented)
@@ -969,7 +1055,18 @@ export interface OnDeviceParams {
9691055
}
9701056

9711057
// @public
972-
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
1058+
export const Outcome: {
1059+
UNSPECIFIED: string;
1060+
OK: string;
1061+
FAILED: string;
1062+
DEADLINE_EXCEEDED: string;
1063+
};
1064+
1065+
// @public
1066+
export type Outcome = (typeof Outcome)[keyof typeof Outcome];
1067+
1068+
// @public
1069+
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart;
9731070

9741071
// @public
9751072
export const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"];
@@ -1179,6 +1276,10 @@ export class StringSchema extends Schema {
11791276

11801277
// @public
11811278
export interface TextPart {
1279+
// (undocumented)
1280+
codeExecutionResult?: never;
1281+
// (undocumented)
1282+
executableCode?: never;
11821283
// (undocumented)
11831284
functionCall?: never;
11841285
// (undocumented)
@@ -1200,7 +1301,7 @@ export interface ThinkingConfig {
12001301
}
12011302

12021303
// @public
1203-
export type Tool = FunctionDeclarationsTool | GoogleSearchTool;
1304+
export type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool;
12041305

12051306
// @public
12061307
export interface ToolConfig {

docs-devsite/_toc.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ toc:
3232
path: /docs/reference/js/ai.citation.md
3333
- title: CitationMetadata
3434
path: /docs/reference/js/ai.citationmetadata.md
35+
- title: CodeExecutionResult
36+
path: /docs/reference/js/ai.codeexecutionresult.md
37+
- title: CodeExecutionResultPart
38+
path: /docs/reference/js/ai.codeexecutionresultpart.md
39+
- title: CodeExecutionTool
40+
path: /docs/reference/js/ai.codeexecutiontool.md
3541
- title: Content
3642
path: /docs/reference/js/ai.content.md
3743
- title: CountTokensRequest
@@ -46,6 +52,10 @@ toc:
4652
path: /docs/reference/js/ai.enhancedgeneratecontentresponse.md
4753
- title: ErrorDetails
4854
path: /docs/reference/js/ai.errordetails.md
55+
- title: ExecutableCode
56+
path: /docs/reference/js/ai.executablecode.md
57+
- title: ExecutableCodePart
58+
path: /docs/reference/js/ai.executablecodepart.md
4959
- title: FileData
5060
path: /docs/reference/js/ai.filedata.md
5161
- title: FileDataPart
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# CodeExecutionResult interface
13+
The results of code execution run by the model.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface CodeExecutionResult
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [outcome](./ai.codeexecutionresult.md#codeexecutionresultoutcome) | [Outcome](./ai.md#outcome) | The result of the code execution. |
26+
| [output](./ai.codeexecutionresult.md#codeexecutionresultoutput) | string | The output from the code execution, or an error message if it failed. |
27+
28+
## CodeExecutionResult.outcome
29+
30+
The result of the code execution.
31+
32+
<b>Signature:</b>
33+
34+
```typescript
35+
outcome?: Outcome;
36+
```
37+
38+
## CodeExecutionResult.output
39+
40+
The output from the code execution, or an error message if it failed.
41+
42+
<b>Signature:</b>
43+
44+
```typescript
45+
output?: string;
46+
```
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# CodeExecutionResultPart interface
13+
Represents the code execution result from the model.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface CodeExecutionResultPart
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [codeExecutionResult](./ai.codeexecutionresultpart.md#codeexecutionresultpartcodeexecutionresult) | [CodeExecutionResult](./ai.codeexecutionresult.md#codeexecutionresult_interface) | |
26+
| [executableCode](./ai.codeexecutionresultpart.md#codeexecutionresultpartexecutablecode) | never | |
27+
| [fileData](./ai.codeexecutionresultpart.md#codeexecutionresultpartfiledata) | never | |
28+
| [functionCall](./ai.codeexecutionresultpart.md#codeexecutionresultpartfunctioncall) | never | |
29+
| [functionResponse](./ai.codeexecutionresultpart.md#codeexecutionresultpartfunctionresponse) | never | |
30+
| [inlineData](./ai.codeexecutionresultpart.md#codeexecutionresultpartinlinedata) | never | |
31+
| [text](./ai.codeexecutionresultpart.md#codeexecutionresultparttext) | never | |
32+
| [thought](./ai.codeexecutionresultpart.md#codeexecutionresultpartthought) | never | |
33+
34+
## CodeExecutionResultPart.codeExecutionResult
35+
36+
<b>Signature:</b>
37+
38+
```typescript
39+
codeExecutionResult?: CodeExecutionResult;
40+
```
41+
42+
## CodeExecutionResultPart.executableCode
43+
44+
<b>Signature:</b>
45+
46+
```typescript
47+
executableCode?: never;
48+
```
49+
50+
## CodeExecutionResultPart.fileData
51+
52+
<b>Signature:</b>
53+
54+
```typescript
55+
fileData: never;
56+
```
57+
58+
## CodeExecutionResultPart.functionCall
59+
60+
<b>Signature:</b>
61+
62+
```typescript
63+
functionCall?: never;
64+
```
65+
66+
## CodeExecutionResultPart.functionResponse
67+
68+
<b>Signature:</b>
69+
70+
```typescript
71+
functionResponse?: never;
72+
```
73+
74+
## CodeExecutionResultPart.inlineData
75+
76+
<b>Signature:</b>
77+
78+
```typescript
79+
inlineData?: never;
80+
```
81+
82+
## CodeExecutionResultPart.text
83+
84+
<b>Signature:</b>
85+
86+
```typescript
87+
text?: never;
88+
```
89+
90+
## CodeExecutionResultPart.thought
91+
92+
<b>Signature:</b>
93+
94+
```typescript
95+
thought?: never;
96+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# CodeExecutionTool interface
13+
A tool that enables the model to use code execution.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface CodeExecutionTool
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [codeExecution](./ai.codeexecutiontool.md#codeexecutiontoolcodeexecution) | {} | Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options. |
26+
27+
## CodeExecutionTool.codeExecution
28+
29+
Specifies the Google Search configuration. Currently, this is an empty object, but it's reserved for future configuration options.
30+
31+
<b>Signature:</b>
32+
33+
```typescript
34+
codeExecution: {};
35+
```

0 commit comments

Comments
 (0)