@google/generative-ai
Advanced tools
Comparing version 0.13.0 to 0.14.0
# @google/generative-ai | ||
## 0.14.0 | ||
### Minor Changes | ||
- fb1c0f2: Add a `cachedContentTokenCount` field to the `UsageMetadata` interface returned by `generateContent` responses. | ||
- 06216be: Add code execution feature. | ||
## 0.13.0 | ||
@@ -4,0 +11,0 @@ |
@@ -127,2 +127,46 @@ /** | ||
/** | ||
* Result of executing the `ExecutableCode`. | ||
* Only generated when using code execution, and always follows a `Part` | ||
* containing the `ExecutableCode`. | ||
* @public | ||
*/ | ||
export declare interface CodeExecutionResult { | ||
/** | ||
* Outcome of the code execution. | ||
*/ | ||
outcome: Outcome; | ||
/** | ||
* Contains stdout when code execution is successful, stderr or other | ||
* description otherwise. | ||
*/ | ||
output: string; | ||
} | ||
/** | ||
* Content part containing the result of executed code. | ||
* @public | ||
*/ | ||
export declare interface CodeExecutionResultPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult: CodeExecutionResult; | ||
} | ||
/** | ||
* Enables the model to execute code as part of generation. | ||
* @public | ||
*/ | ||
export declare interface CodeExecutionTool { | ||
/** | ||
* Provide an empty object to enable code execution. This field may have | ||
* subfields added in the future. | ||
*/ | ||
codeExecution: {}; | ||
} | ||
/** | ||
* Content type for both prompts and response candidates. | ||
@@ -162,4 +206,4 @@ * @public | ||
*/ | ||
export declare interface CountTokensRequestInternal { | ||
generateContentRequest?: GenerateContentRequestInternal; | ||
export declare interface _CountTokensRequestInternal { | ||
generateContentRequest?: _GenerateContentRequestInternal; | ||
contents?: Content[]; | ||
@@ -232,2 +276,44 @@ } | ||
/** | ||
* Code generated by the model that is meant to be executed, where the result | ||
* is returned to the model. | ||
* Only generated when using the code execution tool, in which the code will | ||
* be automatically executed, and a corresponding `CodeExecutionResult` will | ||
* also be generated. | ||
* | ||
* @public | ||
*/ | ||
export declare interface ExecutableCode { | ||
/** | ||
* Programming language of the `code`. | ||
*/ | ||
language: ExecutableCodeLanguage; | ||
/** | ||
* The code to be executed. | ||
*/ | ||
code: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare enum ExecutableCodeLanguage { | ||
LANGUAGE_UNSPECIFIED = "language_unspecified", | ||
PYTHON = "python" | ||
} | ||
/** | ||
* Content part containing executable code generated by the model. | ||
* @public | ||
*/ | ||
export declare interface ExecutableCodePart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode: ExecutableCode; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Data pointing to a file uploaded with the Files API. | ||
@@ -242,3 +328,3 @@ * @public | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Content part interface if the part represents FileData. | ||
* @public | ||
@@ -252,2 +338,4 @@ */ | ||
fileData: FileData; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -298,3 +386,3 @@ | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Content part interface if the part represents a FunctionCall. | ||
* @public | ||
@@ -308,2 +396,4 @@ */ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -442,2 +532,4 @@ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -477,3 +569,3 @@ | ||
*/ | ||
export declare interface GenerateContentRequestInternal extends GenerateContentRequest { | ||
export declare interface _GenerateContentRequestInternal extends GenerateContentRequest { | ||
model?: string; | ||
@@ -704,2 +796,4 @@ } | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -720,6 +814,31 @@ | ||
/** | ||
* Possible outcomes of code execution. | ||
* @public | ||
*/ | ||
export declare enum Outcome { | ||
/** | ||
* Unspecified status. This value should not be used. | ||
*/ | ||
OUTCOME_UNSPECIFIED = "outcome_unspecified", | ||
/** | ||
* Code execution completed successfully. | ||
*/ | ||
OUTCOME_OK = "outcome_ok", | ||
/** | ||
* Code execution finished but with a failure. `stderr` should contain the | ||
* reason. | ||
*/ | ||
OUTCOME_FAILED = "outcome_failed", | ||
/** | ||
* Code execution ran for too long, and was cancelled. There may or may not | ||
* be a partial output present. | ||
*/ | ||
OUTCOME_DEADLINE_EXCEEDED = "outcome_deadline_exceeded" | ||
} | ||
/** | ||
* Content part - includes text or image part types. | ||
* @public | ||
*/ | ||
export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; | ||
export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart; | ||
@@ -867,2 +986,4 @@ /** | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -895,4 +1016,6 @@ | ||
totalTokenCount: number; | ||
/** Total token count in the cached part of the prompt, i.e. in the cached content. */ | ||
cachedContentTokenCount?: number; | ||
} | ||
export { } |
@@ -41,2 +41,52 @@ 'use strict'; | ||
/** | ||
* @public | ||
*/ | ||
exports.ExecutableCodeLanguage = void 0; | ||
(function (ExecutableCodeLanguage) { | ||
ExecutableCodeLanguage["LANGUAGE_UNSPECIFIED"] = "language_unspecified"; | ||
ExecutableCodeLanguage["PYTHON"] = "python"; | ||
})(exports.ExecutableCodeLanguage || (exports.ExecutableCodeLanguage = {})); | ||
/** | ||
* Possible outcomes of code execution. | ||
* @public | ||
*/ | ||
exports.Outcome = void 0; | ||
(function (Outcome) { | ||
/** | ||
* Unspecified status. This value should not be used. | ||
*/ | ||
Outcome["OUTCOME_UNSPECIFIED"] = "outcome_unspecified"; | ||
/** | ||
* Code execution completed successfully. | ||
*/ | ||
Outcome["OUTCOME_OK"] = "outcome_ok"; | ||
/** | ||
* Code execution finished but with a failure. `stderr` should contain the | ||
* reason. | ||
*/ | ||
Outcome["OUTCOME_FAILED"] = "outcome_failed"; | ||
/** | ||
* Code execution ran for too long, and was cancelled. There may or may not | ||
* be a partial output present. | ||
*/ | ||
Outcome["OUTCOME_DEADLINE_EXCEEDED"] = "outcome_deadline_exceeded"; | ||
})(exports.Outcome || (exports.Outcome = {})); | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* Possible roles. | ||
@@ -235,3 +285,3 @@ * @public | ||
*/ | ||
const PACKAGE_VERSION = "0.13.0"; | ||
const PACKAGE_VERSION = "0.14.0"; | ||
const PACKAGE_LOG_HEADER = "genai-js"; | ||
@@ -461,2 +511,8 @@ var Task; | ||
} | ||
if (part.executableCode) { | ||
textStrings.push("\n```python\n" + part.executableCode.code + "\n```\n"); | ||
} | ||
if (part.codeExecutionResult) { | ||
textStrings.push("\n```\n" + part.codeExecutionResult.output + "\n```\n"); | ||
} | ||
} | ||
@@ -707,2 +763,8 @@ } | ||
} | ||
if (part.executableCode) { | ||
newPart.executableCode = part.executableCode; | ||
} | ||
if (part.codeExecutionResult) { | ||
newPart.codeExecutionResult = part.codeExecutionResult; | ||
} | ||
if (Object.keys(newPart).length === 0) { | ||
@@ -906,2 +968,4 @@ newPart.text = ""; | ||
"functionResponse", | ||
"executableCode", | ||
"codeExecutionResult", | ||
]; | ||
@@ -911,3 +975,3 @@ const VALID_PARTS_PER_ROLE = { | ||
function: ["functionResponse"], | ||
model: ["text", "functionCall"], | ||
model: ["text", "functionCall", "executableCode", "codeExecutionResult"], | ||
// System instructions shouldn't be in history anyway. | ||
@@ -938,2 +1002,4 @@ system: ["text"], | ||
fileData: 0, | ||
executableCode: 0, | ||
codeExecutionResult: 0, | ||
}; | ||
@@ -940,0 +1006,0 @@ for (const part of parts) { |
@@ -72,3 +72,3 @@ 'use strict'; | ||
*/ | ||
const PACKAGE_VERSION = "0.13.0"; | ||
const PACKAGE_VERSION = "0.14.0"; | ||
const PACKAGE_LOG_HEADER = "genai-js"; | ||
@@ -602,2 +602,52 @@ var Task; | ||
/** | ||
* @public | ||
*/ | ||
exports.ExecutableCodeLanguage = void 0; | ||
(function (ExecutableCodeLanguage) { | ||
ExecutableCodeLanguage["LANGUAGE_UNSPECIFIED"] = "language_unspecified"; | ||
ExecutableCodeLanguage["PYTHON"] = "python"; | ||
})(exports.ExecutableCodeLanguage || (exports.ExecutableCodeLanguage = {})); | ||
/** | ||
* Possible outcomes of code execution. | ||
* @public | ||
*/ | ||
exports.Outcome = void 0; | ||
(function (Outcome) { | ||
/** | ||
* Unspecified status. This value should not be used. | ||
*/ | ||
Outcome["OUTCOME_UNSPECIFIED"] = "outcome_unspecified"; | ||
/** | ||
* Code execution completed successfully. | ||
*/ | ||
Outcome["OUTCOME_OK"] = "outcome_ok"; | ||
/** | ||
* Code execution finished but with a failure. `stderr` should contain the | ||
* reason. | ||
*/ | ||
Outcome["OUTCOME_FAILED"] = "outcome_failed"; | ||
/** | ||
* Code execution ran for too long, and was cancelled. There may or may not | ||
* be a partial output present. | ||
*/ | ||
Outcome["OUTCOME_DEADLINE_EXCEEDED"] = "outcome_deadline_exceeded"; | ||
})(exports.Outcome || (exports.Outcome = {})); | ||
/** | ||
* @license | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* Possible roles. | ||
@@ -604,0 +654,0 @@ * @public |
@@ -76,4 +76,4 @@ /** | ||
*/ | ||
export declare interface CachedContentUpdateRequest { | ||
cachedContent: CachedContentUpdateRequestFields; | ||
export declare interface _CachedContentUpdateRequest { | ||
cachedContent: _CachedContentUpdateRequestFields; | ||
/** | ||
@@ -89,3 +89,3 @@ * protobuf FieldMask | ||
*/ | ||
export declare interface CachedContentUpdateRequestFields { | ||
export declare interface _CachedContentUpdateRequestFields { | ||
ttl?: string; | ||
@@ -96,2 +96,34 @@ expireTime?: string; | ||
/** | ||
* Result of executing the `ExecutableCode`. | ||
* Only generated when using code execution, and always follows a `Part` | ||
* containing the `ExecutableCode`. | ||
* @public | ||
*/ | ||
export declare interface CodeExecutionResult { | ||
/** | ||
* Outcome of the code execution. | ||
*/ | ||
outcome: Outcome; | ||
/** | ||
* Contains stdout when code execution is successful, stderr or other | ||
* description otherwise. | ||
*/ | ||
output: string; | ||
} | ||
/** | ||
* Content part containing the result of executed code. | ||
* @public | ||
*/ | ||
export declare interface CodeExecutionResultPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult: CodeExecutionResult; | ||
} | ||
/** | ||
* Content type for both prompts and response candidates. | ||
@@ -118,2 +150,44 @@ * @public | ||
/** | ||
* Code generated by the model that is meant to be executed, where the result | ||
* is returned to the model. | ||
* Only generated when using the code execution tool, in which the code will | ||
* be automatically executed, and a corresponding `CodeExecutionResult` will | ||
* also be generated. | ||
* | ||
* @public | ||
*/ | ||
export declare interface ExecutableCode { | ||
/** | ||
* Programming language of the `code`. | ||
*/ | ||
language: ExecutableCodeLanguage; | ||
/** | ||
* The code to be executed. | ||
*/ | ||
code: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare enum ExecutableCodeLanguage { | ||
LANGUAGE_UNSPECIFIED = "language_unspecified", | ||
PYTHON = "python" | ||
} | ||
/** | ||
* Content part containing executable code generated by the model. | ||
* @public | ||
*/ | ||
export declare interface ExecutableCodePart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode: ExecutableCode; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Data pointing to a file uploaded with the Files API. | ||
@@ -128,3 +202,3 @@ * @public | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Content part interface if the part represents FileData. | ||
* @public | ||
@@ -138,2 +212,4 @@ */ | ||
fileData: FileData; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -217,3 +293,3 @@ | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Content part interface if the part represents a FunctionCall. | ||
* @public | ||
@@ -227,2 +303,4 @@ */ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -361,2 +439,4 @@ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -442,2 +522,4 @@ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -473,6 +555,31 @@ | ||
/** | ||
* Possible outcomes of code execution. | ||
* @public | ||
*/ | ||
export declare enum Outcome { | ||
/** | ||
* Unspecified status. This value should not be used. | ||
*/ | ||
OUTCOME_UNSPECIFIED = "outcome_unspecified", | ||
/** | ||
* Code execution completed successfully. | ||
*/ | ||
OUTCOME_OK = "outcome_ok", | ||
/** | ||
* Code execution finished but with a failure. `stderr` should contain the | ||
* reason. | ||
*/ | ||
OUTCOME_FAILED = "outcome_failed", | ||
/** | ||
* Code execution ran for too long, and was cancelled. There may or may not | ||
* be a partial output present. | ||
*/ | ||
OUTCOME_DEADLINE_EXCEEDED = "outcome_deadline_exceeded" | ||
} | ||
/** | ||
* Content part - includes text or image part types. | ||
* @public | ||
*/ | ||
export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; | ||
export declare type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart; | ||
@@ -576,2 +683,4 @@ /** | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -578,0 +687,0 @@ |
@@ -17,7 +17,7 @@ /** | ||
*/ | ||
import { Content, CountTokensRequest, CountTokensRequestInternal, EmbedContentRequest, GenerateContentRequest, Part } from "../../types"; | ||
import { Content, CountTokensRequest, EmbedContentRequest, GenerateContentRequest, Part, _CountTokensRequestInternal } from "../../types"; | ||
export declare function formatSystemInstruction(input?: string | Part | Content): Content | undefined; | ||
export declare function formatNewContent(request: string | Array<string | Part>): Content; | ||
export declare function formatCountTokensInput(params: CountTokensRequest | string | Array<string | Part>, model: string): CountTokensRequestInternal; | ||
export declare function formatCountTokensInput(params: CountTokensRequest | string | Array<string | Part>, model: string): _CountTokensRequestInternal; | ||
export declare function formatGenerateContentInput(params: GenerateContentRequest | string | Array<string | Part>): GenerateContentRequest; | ||
export declare function formatEmbedContentInput(params: EmbedContentRequest | string | Array<string | Part>): EmbedContentRequest; |
@@ -30,3 +30,3 @@ /** | ||
*/ | ||
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; | ||
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart; | ||
/** | ||
@@ -42,2 +42,4 @@ * Content part interface if the part represents a text string. | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -54,5 +56,7 @@ /** | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Content part interface if the part represents a FunctionCall. | ||
* @public | ||
@@ -66,2 +70,4 @@ */ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -78,4 +84,45 @@ /** | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part interface if the part represents FileData. | ||
* @public | ||
*/ | ||
export interface FileDataPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData: FileData; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part containing executable code generated by the model. | ||
* @public | ||
*/ | ||
export interface ExecutableCodePart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode: ExecutableCode; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part containing the result of executed code. | ||
* @public | ||
*/ | ||
export interface CodeExecutionResultPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult: CodeExecutionResult; | ||
} | ||
/** | ||
* A predicted [FunctionCall] returned from the model | ||
@@ -115,13 +162,2 @@ * that contains a string representing the [FunctionDeclaration.name] | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* @public | ||
*/ | ||
export interface FileDataPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData: FileData; | ||
} | ||
/** | ||
* Data pointing to a file uploaded with the Files API. | ||
@@ -134,1 +170,68 @@ * @public | ||
} | ||
/** | ||
* Code generated by the model that is meant to be executed, where the result | ||
* is returned to the model. | ||
* Only generated when using the code execution tool, in which the code will | ||
* be automatically executed, and a corresponding `CodeExecutionResult` will | ||
* also be generated. | ||
* | ||
* @public | ||
*/ | ||
export interface ExecutableCode { | ||
/** | ||
* Programming language of the `code`. | ||
*/ | ||
language: ExecutableCodeLanguage; | ||
/** | ||
* The code to be executed. | ||
*/ | ||
code: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare enum ExecutableCodeLanguage { | ||
LANGUAGE_UNSPECIFIED = "language_unspecified", | ||
PYTHON = "python" | ||
} | ||
/** | ||
* Result of executing the `ExecutableCode`. | ||
* Only generated when using code execution, and always follows a `Part` | ||
* containing the `ExecutableCode`. | ||
* @public | ||
*/ | ||
export interface CodeExecutionResult { | ||
/** | ||
* Outcome of the code execution. | ||
*/ | ||
outcome: Outcome; | ||
/** | ||
* Contains stdout when code execution is successful, stderr or other | ||
* description otherwise. | ||
*/ | ||
output: string; | ||
} | ||
/** | ||
* Possible outcomes of code execution. | ||
* @public | ||
*/ | ||
export declare enum Outcome { | ||
/** | ||
* Unspecified status. This value should not be used. | ||
*/ | ||
OUTCOME_UNSPECIFIED = "outcome_unspecified", | ||
/** | ||
* Code execution completed successfully. | ||
*/ | ||
OUTCOME_OK = "outcome_ok", | ||
/** | ||
* Code execution finished but with a failure. `stderr` should contain the | ||
* reason. | ||
*/ | ||
OUTCOME_FAILED = "outcome_failed", | ||
/** | ||
* Code execution ran for too long, and was cancelled. There may or may not | ||
* be a partial output present. | ||
*/ | ||
OUTCOME_DEADLINE_EXCEEDED = "outcome_deadline_exceeded" | ||
} |
@@ -19,7 +19,2 @@ /** | ||
/** | ||
* Defines a tool that model can call to access external knowledge. | ||
* @public | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool; | ||
/** | ||
* Structured representation of a function declaration as defined by the | ||
@@ -26,0 +21,0 @@ * [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included |
@@ -20,3 +20,3 @@ /** | ||
import { HarmBlockThreshold, HarmCategory, TaskType } from "./enums"; | ||
import { ResponseSchema, Tool, ToolConfig } from "./function-calling"; | ||
import { FunctionDeclarationsTool, ResponseSchema, ToolConfig } from "./function-calling"; | ||
/** | ||
@@ -59,3 +59,3 @@ * Base parameters for a number of methods. | ||
*/ | ||
export interface GenerateContentRequestInternal extends GenerateContentRequest { | ||
export interface _GenerateContentRequestInternal extends GenerateContentRequest { | ||
model?: string; | ||
@@ -127,4 +127,4 @@ } | ||
*/ | ||
export interface CountTokensRequestInternal { | ||
generateContentRequest?: GenerateContentRequestInternal; | ||
export interface _CountTokensRequestInternal { | ||
generateContentRequest?: _GenerateContentRequestInternal; | ||
contents?: Content[]; | ||
@@ -176,1 +176,17 @@ } | ||
} | ||
/** | ||
* Defines a tool that model can call to access external knowledge. | ||
* @public | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool; | ||
/** | ||
* Enables the model to execute code as part of generation. | ||
* @public | ||
*/ | ||
export interface CodeExecutionTool { | ||
/** | ||
* Provide an empty object to enable code execution. This field may have | ||
* subfields added in the future. | ||
*/ | ||
codeExecution: {}; | ||
} |
@@ -89,2 +89,4 @@ /** | ||
totalTokenCount: number; | ||
/** Total token count in the cached part of the prompt, i.e. in the cached content. */ | ||
cachedContentTokenCount?: number; | ||
} | ||
@@ -91,0 +93,0 @@ /** |
@@ -18,3 +18,4 @@ /** | ||
import { Content, Part } from "../content"; | ||
import { Tool, ToolConfig } from "../function-calling"; | ||
import { ToolConfig } from "../function-calling"; | ||
import { Tool } from "../requests"; | ||
/** | ||
@@ -90,3 +91,3 @@ * @public | ||
*/ | ||
export interface CachedContentUpdateRequestFields { | ||
export interface _CachedContentUpdateRequestFields { | ||
ttl?: string; | ||
@@ -99,4 +100,4 @@ expireTime?: string; | ||
*/ | ||
export interface CachedContentUpdateRequest { | ||
cachedContent: CachedContentUpdateRequestFields; | ||
export interface _CachedContentUpdateRequest { | ||
cachedContent: _CachedContentUpdateRequestFields; | ||
/** | ||
@@ -103,0 +104,0 @@ * protobuf FieldMask |
@@ -20,4 +20,4 @@ /** | ||
export * from "./shared"; | ||
export { RequestOptions } from "../../types/requests"; | ||
export { RequestOptions, Tool } from "../../types/requests"; | ||
export * from "../../types/content"; | ||
export { FunctionCallingMode } from "../../types/enums"; |
@@ -17,7 +17,7 @@ /** | ||
*/ | ||
import { Content, CountTokensRequest, CountTokensRequestInternal, EmbedContentRequest, GenerateContentRequest, Part } from "../../types"; | ||
import { Content, CountTokensRequest, EmbedContentRequest, GenerateContentRequest, Part, _CountTokensRequestInternal } from "../../types"; | ||
export declare function formatSystemInstruction(input?: string | Part | Content): Content | undefined; | ||
export declare function formatNewContent(request: string | Array<string | Part>): Content; | ||
export declare function formatCountTokensInput(params: CountTokensRequest | string | Array<string | Part>, model: string): CountTokensRequestInternal; | ||
export declare function formatCountTokensInput(params: CountTokensRequest | string | Array<string | Part>, model: string): _CountTokensRequestInternal; | ||
export declare function formatGenerateContentInput(params: GenerateContentRequest | string | Array<string | Part>): GenerateContentRequest; | ||
export declare function formatEmbedContentInput(params: EmbedContentRequest | string | Array<string | Part>): EmbedContentRequest; |
@@ -30,3 +30,3 @@ /** | ||
*/ | ||
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; | ||
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart | ExecutableCodePart | CodeExecutionResultPart; | ||
/** | ||
@@ -42,2 +42,4 @@ * Content part interface if the part represents a text string. | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -54,5 +56,7 @@ /** | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Content part interface if the part represents a FunctionCall. | ||
* @public | ||
@@ -66,2 +70,4 @@ */ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -78,4 +84,45 @@ /** | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part interface if the part represents FileData. | ||
* @public | ||
*/ | ||
export interface FileDataPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData: FileData; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part containing executable code generated by the model. | ||
* @public | ||
*/ | ||
export interface ExecutableCodePart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode: ExecutableCode; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part containing the result of executed code. | ||
* @public | ||
*/ | ||
export interface CodeExecutionResultPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult: CodeExecutionResult; | ||
} | ||
/** | ||
* A predicted [FunctionCall] returned from the model | ||
@@ -115,13 +162,2 @@ * that contains a string representing the [FunctionDeclaration.name] | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* @public | ||
*/ | ||
export interface FileDataPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData: FileData; | ||
} | ||
/** | ||
* Data pointing to a file uploaded with the Files API. | ||
@@ -134,1 +170,68 @@ * @public | ||
} | ||
/** | ||
* Code generated by the model that is meant to be executed, where the result | ||
* is returned to the model. | ||
* Only generated when using the code execution tool, in which the code will | ||
* be automatically executed, and a corresponding `CodeExecutionResult` will | ||
* also be generated. | ||
* | ||
* @public | ||
*/ | ||
export interface ExecutableCode { | ||
/** | ||
* Programming language of the `code`. | ||
*/ | ||
language: ExecutableCodeLanguage; | ||
/** | ||
* The code to be executed. | ||
*/ | ||
code: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare enum ExecutableCodeLanguage { | ||
LANGUAGE_UNSPECIFIED = "language_unspecified", | ||
PYTHON = "python" | ||
} | ||
/** | ||
* Result of executing the `ExecutableCode`. | ||
* Only generated when using code execution, and always follows a `Part` | ||
* containing the `ExecutableCode`. | ||
* @public | ||
*/ | ||
export interface CodeExecutionResult { | ||
/** | ||
* Outcome of the code execution. | ||
*/ | ||
outcome: Outcome; | ||
/** | ||
* Contains stdout when code execution is successful, stderr or other | ||
* description otherwise. | ||
*/ | ||
output: string; | ||
} | ||
/** | ||
* Possible outcomes of code execution. | ||
* @public | ||
*/ | ||
export declare enum Outcome { | ||
/** | ||
* Unspecified status. This value should not be used. | ||
*/ | ||
OUTCOME_UNSPECIFIED = "outcome_unspecified", | ||
/** | ||
* Code execution completed successfully. | ||
*/ | ||
OUTCOME_OK = "outcome_ok", | ||
/** | ||
* Code execution finished but with a failure. `stderr` should contain the | ||
* reason. | ||
*/ | ||
OUTCOME_FAILED = "outcome_failed", | ||
/** | ||
* Code execution ran for too long, and was cancelled. There may or may not | ||
* be a partial output present. | ||
*/ | ||
OUTCOME_DEADLINE_EXCEEDED = "outcome_deadline_exceeded" | ||
} |
@@ -19,7 +19,2 @@ /** | ||
/** | ||
* Defines a tool that model can call to access external knowledge. | ||
* @public | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool; | ||
/** | ||
* Structured representation of a function declaration as defined by the | ||
@@ -26,0 +21,0 @@ * [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included |
@@ -20,3 +20,3 @@ /** | ||
import { HarmBlockThreshold, HarmCategory, TaskType } from "./enums"; | ||
import { ResponseSchema, Tool, ToolConfig } from "./function-calling"; | ||
import { FunctionDeclarationsTool, ResponseSchema, ToolConfig } from "./function-calling"; | ||
/** | ||
@@ -59,3 +59,3 @@ * Base parameters for a number of methods. | ||
*/ | ||
export interface GenerateContentRequestInternal extends GenerateContentRequest { | ||
export interface _GenerateContentRequestInternal extends GenerateContentRequest { | ||
model?: string; | ||
@@ -127,4 +127,4 @@ } | ||
*/ | ||
export interface CountTokensRequestInternal { | ||
generateContentRequest?: GenerateContentRequestInternal; | ||
export interface _CountTokensRequestInternal { | ||
generateContentRequest?: _GenerateContentRequestInternal; | ||
contents?: Content[]; | ||
@@ -176,1 +176,17 @@ } | ||
} | ||
/** | ||
* Defines a tool that model can call to access external knowledge. | ||
* @public | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool; | ||
/** | ||
* Enables the model to execute code as part of generation. | ||
* @public | ||
*/ | ||
export interface CodeExecutionTool { | ||
/** | ||
* Provide an empty object to enable code execution. This field may have | ||
* subfields added in the future. | ||
*/ | ||
codeExecution: {}; | ||
} |
@@ -89,2 +89,4 @@ /** | ||
totalTokenCount: number; | ||
/** Total token count in the cached part of the prompt, i.e. in the cached content. */ | ||
cachedContentTokenCount?: number; | ||
} | ||
@@ -91,0 +93,0 @@ /** |
@@ -18,3 +18,4 @@ /** | ||
import { Content, Part } from "../content"; | ||
import { Tool, ToolConfig } from "../function-calling"; | ||
import { ToolConfig } from "../function-calling"; | ||
import { Tool } from "../requests"; | ||
/** | ||
@@ -90,3 +91,3 @@ * @public | ||
*/ | ||
export interface CachedContentUpdateRequestFields { | ||
export interface _CachedContentUpdateRequestFields { | ||
ttl?: string; | ||
@@ -99,4 +100,4 @@ expireTime?: string; | ||
*/ | ||
export interface CachedContentUpdateRequest { | ||
cachedContent: CachedContentUpdateRequestFields; | ||
export interface _CachedContentUpdateRequest { | ||
cachedContent: _CachedContentUpdateRequestFields; | ||
/** | ||
@@ -103,0 +104,0 @@ * protobuf FieldMask |
@@ -20,4 +20,4 @@ /** | ||
export * from "./shared"; | ||
export { RequestOptions } from "../../types/requests"; | ||
export { RequestOptions, Tool } from "../../types/requests"; | ||
export * from "../../types/content"; | ||
export { FunctionCallingMode } from "../../types/enums"; |
{ | ||
"name": "@google/generative-ai", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "Google AI JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -30,2 +30,4 @@ /** | ||
"functionResponse", | ||
"executableCode", | ||
"codeExecutionResult", | ||
]; | ||
@@ -36,3 +38,3 @@ | ||
function: ["functionResponse"], | ||
model: ["text", "functionCall"], | ||
model: ["text", "functionCall", "executableCode", "codeExecutionResult"], | ||
// System instructions shouldn't be in history anyway. | ||
@@ -77,2 +79,4 @@ system: ["text"], | ||
fileData: 0, | ||
executableCode: 0, | ||
codeExecutionResult: 0, | ||
}; | ||
@@ -79,0 +83,0 @@ |
@@ -21,6 +21,6 @@ /** | ||
CountTokensRequest, | ||
CountTokensRequestInternal, | ||
EmbedContentRequest, | ||
GenerateContentRequest, | ||
Part, | ||
_CountTokensRequestInternal, | ||
} from "../../types"; | ||
@@ -116,4 +116,4 @@ import { | ||
model: string, | ||
): CountTokensRequestInternal { | ||
let formattedRequest: CountTokensRequestInternal = {}; | ||
): _CountTokensRequestInternal { | ||
let formattedRequest: _CountTokensRequestInternal = {}; | ||
const containsGenerateContentRequest = | ||
@@ -120,0 +120,0 @@ (params as CountTokensRequest).generateContentRequest != null; |
@@ -25,4 +25,6 @@ /** | ||
Content, | ||
ExecutableCodeLanguage, | ||
FinishReason, | ||
GenerateContentResponse, | ||
Outcome, | ||
} from "../../types"; | ||
@@ -129,2 +131,28 @@ | ||
const fakeResponseCodeExecution: GenerateContentResponse = { | ||
candidates: [ | ||
{ | ||
index: 0, | ||
content: { | ||
role: "model", | ||
parts: [ | ||
{ text: "here's how to print hello world" }, | ||
{ | ||
executableCode: { | ||
language: ExecutableCodeLanguage.PYTHON, | ||
code: 'print("hello world")', | ||
}, | ||
}, | ||
{ | ||
codeExecutionResult: { | ||
outcome: Outcome.OUTCOME_OK, | ||
output: "hello world", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
const badFakeResponse: GenerateContentResponse = { | ||
@@ -183,2 +211,10 @@ promptFeedback: { | ||
}); | ||
it("good response code execution", async () => { | ||
const enhancedResponse = addHelpers(fakeResponseCodeExecution); | ||
console.log(enhancedResponse.text()); | ||
expect(enhancedResponse.text()).to.equal( | ||
'here\'s how to print hello world\n```python\nprint("hello world")\n```\n\n```\nhello world\n```\n', | ||
); | ||
expect(enhancedResponse.functionCalls()).to.be.undefined; | ||
}); | ||
it("bad response safety", async () => { | ||
@@ -185,0 +221,0 @@ const enhancedResponse = addHelpers(badFakeResponse); |
@@ -126,2 +126,12 @@ /** | ||
} | ||
if (part.executableCode) { | ||
textStrings.push( | ||
"\n```python\n" + part.executableCode.code + "\n```\n", | ||
); | ||
} | ||
if (part.codeExecutionResult) { | ||
textStrings.push( | ||
"\n```\n" + part.codeExecutionResult.output + "\n```\n", | ||
); | ||
} | ||
} | ||
@@ -128,0 +138,0 @@ } |
@@ -181,2 +181,8 @@ /** | ||
} | ||
if (part.executableCode) { | ||
newPart.executableCode = part.executableCode; | ||
} | ||
if (part.codeExecutionResult) { | ||
newPart.codeExecutionResult = part.codeExecutionResult; | ||
} | ||
if (Object.keys(newPart).length === 0) { | ||
@@ -183,0 +189,0 @@ newPart.text = ""; |
@@ -23,5 +23,5 @@ /** | ||
CachedContentUpdateParams, | ||
CachedContentUpdateRequestFields, | ||
ListCacheResponse, | ||
ListParams, | ||
_CachedContentUpdateRequestFields, | ||
} from "../../types/server"; | ||
@@ -141,3 +141,3 @@ import { RpcTask } from "./constants"; | ||
const headers = getHeaders(url); | ||
const formattedCachedContent: CachedContentUpdateRequestFields = { | ||
const formattedCachedContent: _CachedContentUpdateRequestFields = { | ||
...updateParams.cachedContent, | ||
@@ -144,0 +144,0 @@ }; |
@@ -53,15 +53,11 @@ ## API Report File for "@google/generative-ai" | ||
// 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) | ||
@@ -74,2 +70,26 @@ expireTime?: 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 { | ||
@@ -97,2 +117,34 @@ // (undocumented) | ||
// @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 { | ||
@@ -108,2 +160,6 @@ // (undocumented) | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData: FileData; | ||
@@ -199,2 +255,6 @@ // (undocumented) | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -258,2 +318,6 @@ // (undocumented) | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -303,2 +367,6 @@ // (undocumented) | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -340,5 +408,13 @@ // (undocumented) | ||
// @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 { | ||
@@ -381,2 +457,6 @@ apiClient?: string; | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -383,0 +463,0 @@ // (undocumented) |
@@ -96,2 +96,31 @@ ## API Report File for "@google/generative-ai" | ||
// @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 { | ||
@@ -118,10 +147,8 @@ // (undocumented) | ||
// 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; | ||
} | ||
@@ -174,2 +201,34 @@ | ||
// @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 { | ||
@@ -185,2 +244,6 @@ // (undocumented) | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData: FileData; | ||
@@ -244,2 +307,6 @@ // (undocumented) | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -303,2 +370,6 @@ // (undocumented) | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -344,6 +415,4 @@ // (undocumented) | ||
// 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) | ||
@@ -509,2 +578,6 @@ model?: string; | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -536,5 +609,13 @@ // (undocumented) | ||
// @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"]; | ||
@@ -628,2 +709,6 @@ | ||
// (undocumented) | ||
codeExecutionResult?: never; | ||
// (undocumented) | ||
executableCode?: never; | ||
// (undocumented) | ||
fileData?: never; | ||
@@ -651,2 +736,3 @@ // (undocumented) | ||
export interface UsageMetadata { | ||
cachedContentTokenCount?: number; | ||
candidatesTokenCount: number; | ||
@@ -653,0 +739,0 @@ promptTokenCount: number; |
@@ -65,31 +65,2 @@ /** | ||
}); | ||
it("stream true, blocked", async () => { | ||
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); | ||
const model = genAI.getGenerativeModel({ | ||
model: "gemini-1.5-flash-latest", | ||
safetySettings: [ | ||
{ | ||
category: HarmCategory.HARM_CATEGORY_HARASSMENT, | ||
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH, | ||
}, | ||
], | ||
}); | ||
const result = await model.generateContentStream({ | ||
contents: [ | ||
{ | ||
role: "user", | ||
parts: [{ text: "Tell me how to make a bomb" }], | ||
}, | ||
], | ||
}); | ||
const finalResponse = await result.response; | ||
expect(finalResponse.candidates).to.be.undefined; | ||
expect(finalResponse.promptFeedback?.blockReason).to.equal("SAFETY"); | ||
for await (const response of result.stream) { | ||
expect(response.text).to.throw( | ||
"[GoogleGenerativeAI Error]: Text not available. " + | ||
"Response was blocked due to SAFETY", | ||
); | ||
} | ||
}); | ||
it("stream true, invalid argument", async () => { | ||
@@ -96,0 +67,0 @@ const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); |
@@ -38,3 +38,5 @@ /** | ||
| FunctionResponsePart | ||
| FileDataPart; | ||
| FileDataPart | ||
| ExecutableCodePart | ||
| CodeExecutionResultPart; | ||
@@ -51,2 +53,4 @@ /** | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -64,6 +68,8 @@ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Content part interface if the part represents a FunctionCall. | ||
* @public | ||
@@ -77,2 +83,4 @@ */ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
@@ -90,5 +98,49 @@ | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part interface if the part represents FileData. | ||
* @public | ||
*/ | ||
export interface FileDataPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData: FileData; | ||
executableCode?: never; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part containing executable code generated by the model. | ||
* @public | ||
*/ | ||
export interface ExecutableCodePart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode: ExecutableCode; | ||
codeExecutionResult?: never; | ||
} | ||
/** | ||
* Content part containing the result of executed code. | ||
* @public | ||
*/ | ||
export interface CodeExecutionResultPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData?: never; | ||
executableCode?: never; | ||
codeExecutionResult: CodeExecutionResult; | ||
} | ||
/** | ||
* A predicted [FunctionCall] returned from the model | ||
@@ -131,20 +183,79 @@ * that contains a string representing the [FunctionDeclaration.name] | ||
/** | ||
* Content part interface if the part represents FunctionResponse. | ||
* Data pointing to a file uploaded with the Files API. | ||
* @public | ||
*/ | ||
export interface FileDataPart { | ||
text?: never; | ||
inlineData?: never; | ||
functionCall?: never; | ||
functionResponse?: never; | ||
fileData: FileData; | ||
export interface FileData { | ||
mimeType: string; | ||
fileUri: string; | ||
} | ||
/** | ||
* Data pointing to a file uploaded with the Files API. | ||
* Code generated by the model that is meant to be executed, where the result | ||
* is returned to the model. | ||
* Only generated when using the code execution tool, in which the code will | ||
* be automatically executed, and a corresponding `CodeExecutionResult` will | ||
* also be generated. | ||
* | ||
* @public | ||
*/ | ||
export interface FileData { | ||
mimeType: string; | ||
fileUri: string; | ||
export interface ExecutableCode { | ||
/** | ||
* Programming language of the `code`. | ||
*/ | ||
language: ExecutableCodeLanguage; | ||
/** | ||
* The code to be executed. | ||
*/ | ||
code: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export enum ExecutableCodeLanguage { | ||
LANGUAGE_UNSPECIFIED = "language_unspecified", | ||
PYTHON = "python", | ||
} | ||
/** | ||
* Result of executing the `ExecutableCode`. | ||
* Only generated when using code execution, and always follows a `Part` | ||
* containing the `ExecutableCode`. | ||
* @public | ||
*/ | ||
export interface CodeExecutionResult { | ||
/** | ||
* Outcome of the code execution. | ||
*/ | ||
outcome: Outcome; | ||
/** | ||
* Contains stdout when code execution is successful, stderr or other | ||
* description otherwise. | ||
*/ | ||
output: string; | ||
} | ||
/** | ||
* Possible outcomes of code execution. | ||
* @public | ||
*/ | ||
export enum Outcome { | ||
/** | ||
* Unspecified status. This value should not be used. | ||
*/ | ||
OUTCOME_UNSPECIFIED = "outcome_unspecified", | ||
/** | ||
* Code execution completed successfully. | ||
*/ | ||
OUTCOME_OK = "outcome_ok", | ||
/** | ||
* Code execution finished but with a failure. `stderr` should contain the | ||
* reason. | ||
*/ | ||
OUTCOME_FAILED = "outcome_failed", | ||
/** | ||
* Code execution ran for too long, and was cancelled. There may or may not | ||
* be a partial output present. | ||
*/ | ||
OUTCOME_DEADLINE_EXCEEDED = "outcome_deadline_exceeded", | ||
} |
@@ -20,8 +20,2 @@ /** | ||
/** | ||
* Defines a tool that model can call to access external knowledge. | ||
* @public | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool; | ||
/** | ||
* Structured representation of a function declaration as defined by the | ||
@@ -28,0 +22,0 @@ * [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included |
@@ -21,3 +21,7 @@ /** | ||
import { HarmBlockThreshold, HarmCategory, TaskType } from "./enums"; | ||
import { ResponseSchema, Tool, ToolConfig } from "./function-calling"; | ||
import { | ||
FunctionDeclarationsTool, | ||
ResponseSchema, | ||
ToolConfig, | ||
} from "./function-calling"; | ||
@@ -64,3 +68,4 @@ /** | ||
*/ | ||
export interface GenerateContentRequestInternal extends GenerateContentRequest { | ||
export interface _GenerateContentRequestInternal | ||
extends GenerateContentRequest { | ||
model?: string; | ||
@@ -137,4 +142,4 @@ } | ||
*/ | ||
export interface CountTokensRequestInternal { | ||
generateContentRequest?: GenerateContentRequestInternal; | ||
export interface _CountTokensRequestInternal { | ||
generateContentRequest?: _GenerateContentRequestInternal; | ||
contents?: Content[]; | ||
@@ -189,1 +194,19 @@ } | ||
} | ||
/** | ||
* Defines a tool that model can call to access external knowledge. | ||
* @public | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool; | ||
/** | ||
* Enables the model to execute code as part of generation. | ||
* @public | ||
*/ | ||
export interface CodeExecutionTool { | ||
/** | ||
* Provide an empty object to enable code execution. This field may have | ||
* subfields added in the future. | ||
*/ | ||
codeExecution: {}; | ||
} |
@@ -101,2 +101,4 @@ /** | ||
totalTokenCount: number; | ||
/** Total token count in the cached part of the prompt, i.e. in the cached content. */ | ||
cachedContentTokenCount?: number; | ||
} | ||
@@ -103,0 +105,0 @@ |
@@ -18,3 +18,4 @@ /** | ||
import { Content, Part } from "../content"; | ||
import { Tool, ToolConfig } from "../function-calling"; | ||
import { ToolConfig } from "../function-calling"; | ||
import { Tool } from "../requests"; | ||
@@ -96,3 +97,3 @@ /** | ||
*/ | ||
export interface CachedContentUpdateRequestFields { | ||
export interface _CachedContentUpdateRequestFields { | ||
ttl?: string; | ||
@@ -106,4 +107,4 @@ expireTime?: string; | ||
*/ | ||
export interface CachedContentUpdateRequest { | ||
cachedContent: CachedContentUpdateRequestFields; | ||
export interface _CachedContentUpdateRequest { | ||
cachedContent: _CachedContentUpdateRequestFields; | ||
/** | ||
@@ -110,0 +111,0 @@ * protobuf FieldMask |
@@ -22,4 +22,4 @@ /** | ||
export { RequestOptions } from "../../types/requests"; | ||
export { RequestOptions, Tool } from "../../types/requests"; | ||
export * from "../../types/content"; | ||
export { FunctionCallingMode } from "../../types/enums"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1532267
33324
8