Skip to content

Commit

Permalink
Add code execution feature (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 authored Jun 27, 2024
1 parent fb1c0f2 commit 06216be
Show file tree
Hide file tree
Showing 101 changed files with 1,432 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-rivers-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@google/generative-ai": minor
---

Add code execution feature.
96 changes: 88 additions & 8 deletions common/api-review/generative-ai-server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,45 @@ export interface CachedContentUpdateParams {
updateMask?: string[];
}

// Warning: (ae-internal-missing-underscore) The name "CachedContentUpdateRequest" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export interface CachedContentUpdateRequest {
export interface _CachedContentUpdateRequest {
// (undocumented)
cachedContent: CachedContentUpdateRequestFields;
cachedContent: _CachedContentUpdateRequestFields;
updateMask?: string[];
}

// Warning: (ae-internal-missing-underscore) The name "CachedContentUpdateRequestFields" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export interface CachedContentUpdateRequestFields {
export interface _CachedContentUpdateRequestFields {
// (undocumented)
expireTime?: string;
// (undocumented)
ttl?: string;
}

// @public
export interface CodeExecutionResult {
outcome: Outcome;
output: string;
}

// @public
export interface CodeExecutionResultPart {
// (undocumented)
codeExecutionResult: CodeExecutionResult;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
functionCall?: never;
// (undocumented)
functionResponse?: never;
// (undocumented)
inlineData?: never;
// (undocumented)
text?: never;
}

// @public
export interface Content {
// (undocumented)
Expand All @@ -91,6 +111,38 @@ export interface ErrorDetails {
reason?: string;
}

// @public
export interface ExecutableCode {
code: string;
language: ExecutableCodeLanguage;
}

// @public (undocumented)
export enum ExecutableCodeLanguage {
// (undocumented)
LANGUAGE_UNSPECIFIED = "language_unspecified",
// (undocumented)
PYTHON = "python"
}

// @public
export interface ExecutableCodePart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode: ExecutableCode;
// (undocumented)
fileData?: never;
// (undocumented)
functionCall?: never;
// (undocumented)
functionResponse?: never;
// (undocumented)
inlineData?: never;
// (undocumented)
text?: never;
}

// @public
export interface FileData {
// (undocumented)
Expand All @@ -101,6 +153,10 @@ export interface FileData {

// @public
export interface FileDataPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData: FileData;
// (undocumented)
Expand Down Expand Up @@ -191,6 +247,10 @@ export enum FunctionCallingMode {

// @public
export interface FunctionCallPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down Expand Up @@ -249,6 +309,10 @@ export interface FunctionResponse {

// @public
export interface FunctionResponsePart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down Expand Up @@ -293,6 +357,10 @@ export class GoogleAIFileManager {

// @public
export interface InlineDataPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down Expand Up @@ -330,7 +398,15 @@ export interface ListParams {
}

// @public
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
export enum Outcome {
OUTCOME_DEADLINE_EXCEEDED = "outcome_deadline_exceeded",
OUTCOME_FAILED = "outcome_failed",
OUTCOME_OK = "outcome_ok",
OUTCOME_UNSPECIFIED = "outcome_unspecified"
}

// @public
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart;

// @public
export interface RequestOptions {
Expand Down Expand Up @@ -369,6 +445,10 @@ export interface Schema {

// @public
export interface TextPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down
101 changes: 93 additions & 8 deletions common/api-review/generative-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ export interface CitationSource {
uri?: string;
}

// @public
export interface CodeExecutionResult {
outcome: Outcome;
output: string;
}

// @public
export interface CodeExecutionResultPart {
// (undocumented)
codeExecutionResult: CodeExecutionResult;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
functionCall?: never;
// (undocumented)
functionResponse?: never;
// (undocumented)
inlineData?: never;
// (undocumented)
text?: never;
}

// @public
export interface CodeExecutionTool {
codeExecution: {};
}

// @public
export interface Content {
// (undocumented)
Expand All @@ -114,14 +143,12 @@ export interface CountTokensRequest {
generateContentRequest?: GenerateContentRequest;
}

// Warning: (ae-internal-missing-underscore) The name "CountTokensRequestInternal" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export interface CountTokensRequestInternal {
export interface _CountTokensRequestInternal {
// (undocumented)
contents?: Content[];
// (undocumented)
generateContentRequest?: GenerateContentRequestInternal;
generateContentRequest?: _GenerateContentRequestInternal;
}

// @public
Expand Down Expand Up @@ -168,6 +195,38 @@ export interface ErrorDetails {
reason?: string;
}

// @public
export interface ExecutableCode {
code: string;
language: ExecutableCodeLanguage;
}

// @public (undocumented)
export enum ExecutableCodeLanguage {
// (undocumented)
LANGUAGE_UNSPECIFIED = "language_unspecified",
// (undocumented)
PYTHON = "python"
}

// @public
export interface ExecutableCodePart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode: ExecutableCode;
// (undocumented)
fileData?: never;
// (undocumented)
functionCall?: never;
// (undocumented)
functionResponse?: never;
// (undocumented)
inlineData?: never;
// (undocumented)
text?: never;
}

// @public
export interface FileData {
// (undocumented)
Expand All @@ -178,6 +237,10 @@ export interface FileData {

// @public
export interface FileDataPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData: FileData;
// (undocumented)
Expand Down Expand Up @@ -236,6 +299,10 @@ export enum FunctionCallingMode {

// @public
export interface FunctionCallPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down Expand Up @@ -294,6 +361,10 @@ export interface FunctionResponse {

// @public
export interface FunctionResponsePart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down Expand Up @@ -335,10 +406,8 @@ export interface GenerateContentRequest extends BaseParams {
tools?: Tool[];
}

// Warning: (ae-internal-missing-underscore) The name "GenerateContentRequestInternal" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export interface GenerateContentRequestInternal extends GenerateContentRequest {
export interface _GenerateContentRequestInternal extends GenerateContentRequest {
// (undocumented)
model?: string;
}
Expand Down Expand Up @@ -498,6 +567,10 @@ export enum HarmProbability {

// @public
export interface InlineDataPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down Expand Up @@ -525,7 +598,15 @@ export interface ModelParams extends BaseParams {
}

// @public
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
export enum Outcome {
OUTCOME_DEADLINE_EXCEEDED = "outcome_deadline_exceeded",
OUTCOME_FAILED = "outcome_failed",
OUTCOME_OK = "outcome_ok",
OUTCOME_UNSPECIFIED = "outcome_unspecified"
}

// @public
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart;

// @public
export const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"];
Expand Down Expand Up @@ -615,6 +696,10 @@ export enum TaskType {

// @public
export interface TextPart {
// (undocumented)
codeExecutionResult?: never;
// (undocumented)
executableCode?: never;
// (undocumented)
fileData?: never;
// (undocumented)
Expand Down
1 change: 1 addition & 0 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ module.exports = {
regex: "^I[A-Z]",
match: false,
},
leadingUnderscore: 'allow'
},
],
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
Expand Down
21 changes: 21 additions & 0 deletions docs/reference/main/generative-ai.codeexecutionresult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [CodeExecutionResult](./generative-ai.codeexecutionresult.md)

## CodeExecutionResult interface

Result of executing the `ExecutableCode`<!-- -->. Only generated when using code execution, and always follows a `Part` containing the `ExecutableCode`<!-- -->.

**Signature:**

```typescript
export interface CodeExecutionResult
```

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [outcome](./generative-ai.codeexecutionresult.outcome.md) | | [Outcome](./generative-ai.outcome.md) | Outcome of the code execution. |
| [output](./generative-ai.codeexecutionresult.output.md) | | string | Contains stdout when code execution is successful, stderr or other description otherwise. |

13 changes: 13 additions & 0 deletions docs/reference/main/generative-ai.codeexecutionresult.outcome.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [CodeExecutionResult](./generative-ai.codeexecutionresult.md) &gt; [outcome](./generative-ai.codeexecutionresult.outcome.md)

## CodeExecutionResult.outcome property

Outcome of the code execution.

**Signature:**

```typescript
outcome: Outcome;
```
Loading

0 comments on commit 06216be

Please sign in to comment.