@fuyun/generative-ai
Advanced tools
Comparing version
@@ -99,4 +99,4 @@ /** | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -110,4 +110,4 @@ sendMessage(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -229,2 +229,27 @@ sendMessageStream(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
/** | ||
* Specifies the dynamic retrieval configuration for the given source. | ||
* @public | ||
*/ | ||
export declare interface DynamicRetrievalConfig { | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
*/ | ||
mode?: DynamicRetrievalMode; | ||
/** | ||
* The threshold to be used in dynamic retrieval. If not set, a system default | ||
* value is used. | ||
*/ | ||
dynamicThreshold?: number; | ||
} | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
* @public | ||
*/ | ||
export declare enum DynamicRetrievalMode { | ||
MODE_UNSPECIFIED = "MODE_UNSPECIFIED", | ||
MODE_DYNAMIC = "MODE_DYNAMIC" | ||
} | ||
/** | ||
* Params for calling {@link GenerativeModel.embedContent} | ||
@@ -360,2 +385,6 @@ * @public | ||
LANGUAGE = "LANGUAGE", | ||
BLOCKLIST = "BLOCKLIST", | ||
PROHIBITED_CONTENT = "PROHIBITED_CONTENT", | ||
SPII = "SPII", | ||
MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL", | ||
OTHER = "OTHER" | ||
@@ -456,3 +485,3 @@ } | ||
/** The type of the parameter. */ | ||
type: FunctionDeclarationSchemaType; | ||
type: SchemaType; | ||
/** The format of the parameter. */ | ||
@@ -476,22 +505,2 @@ properties: { | ||
/** | ||
* Contains the list of OpenAPI data types | ||
* as defined by https://swagger.io/docs/specification/data-models/data-types/ | ||
* @public | ||
*/ | ||
export declare enum FunctionDeclarationSchemaType { | ||
/** String type. */ | ||
STRING = "STRING", | ||
/** Number type. */ | ||
NUMBER = "NUMBER", | ||
/** Integer type. */ | ||
INTEGER = "INTEGER", | ||
/** Boolean type. */ | ||
BOOLEAN = "BOOLEAN", | ||
/** Array type. */ | ||
ARRAY = "ARRAY", | ||
/** Object type. */ | ||
OBJECT = "OBJECT" | ||
} | ||
/** | ||
* A FunctionDeclarationsTool is a piece of code that enables the system to | ||
@@ -555,2 +564,8 @@ * interact with external systems to perform an action, or set of actions, | ||
citationMetadata?: CitationMetadata; | ||
/** Average log probability score of the candidate. */ | ||
avgLogprobs?: number; | ||
/** Log-likelihood scores for the response tokens and top tokens. */ | ||
logprobsResult?: LogprobsResult; | ||
/** Search grounding metadata. */ | ||
groundingMetadata?: GroundingMetadata; | ||
} | ||
@@ -643,2 +658,21 @@ | ||
responseSchema?: ResponseSchema; | ||
/** | ||
* Presence penalty applied to the next token's logprobs if the token has | ||
* already been seen in the response. | ||
*/ | ||
presencePenalty?: number; | ||
/** | ||
* Frequency penalty applied to the next token's logprobs, multiplied by the | ||
* number of times each token has been seen in the respponse so far. | ||
*/ | ||
frequencyPenalty?: number; | ||
/** | ||
* If True, export the logprobs results in response. | ||
*/ | ||
responseLogprobs?: boolean; | ||
/** | ||
* Valid if responseLogProbs is set to True. This will set the number of top | ||
* logprobs to return at each decoding step in the logprobsResult. | ||
*/ | ||
logprobs?: number; | ||
} | ||
@@ -668,3 +702,2 @@ | ||
safetySettings: SafetySetting[]; | ||
requestOptions: RequestOptions; | ||
tools?: Tool[]; | ||
@@ -680,4 +713,4 @@ toolConfig?: ToolConfig; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -692,4 +725,4 @@ generateContent(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -701,3 +734,3 @@ generateContentStream(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
*/ | ||
startChat(startChatParams?: StartChatParams, requestOptions?: SingleRequestOptions): ChatSession; | ||
startChat(startChatParams?: StartChatParams): ChatSession; | ||
/** | ||
@@ -707,4 +740,4 @@ * Counts the tokens in the provided request. | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -716,4 +749,4 @@ countTokens(request: CountTokensRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<CountTokensResponse>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -725,4 +758,4 @@ embedContent(request: EmbedContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<EmbedContentResponse>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -746,3 +779,3 @@ batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest, requestOptions?: SingleRequestOptions): Promise<BatchEmbedContentsResponse>; | ||
*/ | ||
getGenerativeModelFromCachedContent(cachedContent: CachedContent, requestOptions?: RequestOptions): GenerativeModel; | ||
getGenerativeModelFromCachedContent(cachedContent: CachedContent, modelParams?: Partial<ModelParams>, requestOptions?: RequestOptions): GenerativeModel; | ||
} | ||
@@ -788,2 +821,126 @@ | ||
/** | ||
* Retrieval tool that is powered by Google search. | ||
* @public | ||
*/ | ||
export declare interface GoogleSearchRetrieval { | ||
/** | ||
* Specifies the dynamic retrieval configuration for the given source. | ||
*/ | ||
dynamicRetrievalConfig?: DynamicRetrievalConfig; | ||
} | ||
/** | ||
* Retrieval tool that is powered by Google search. | ||
* @public | ||
*/ | ||
export declare interface GoogleSearchRetrievalTool { | ||
/** | ||
* Google search retrieval tool config. | ||
*/ | ||
googleSearchRetrieval?: GoogleSearchRetrieval; | ||
} | ||
/** | ||
* Grounding chunk. | ||
* @public | ||
*/ | ||
export declare interface GroundingChunk { | ||
/** | ||
* Chunk from the web. | ||
*/ | ||
web?: GroundingChunkWeb; | ||
} | ||
/** | ||
* Chunk from the web. | ||
* @public | ||
*/ | ||
export declare interface GroundingChunkWeb { | ||
/** | ||
* URI reference of the chunk. | ||
*/ | ||
uri?: string; | ||
/** | ||
* Title of the chunk. | ||
*/ | ||
title?: string; | ||
} | ||
/** | ||
* Metadata returned to client when grounding is enabled. | ||
* @public | ||
*/ | ||
export declare interface GroundingMetadata { | ||
/** | ||
* Google search entry for the following-up web searches. | ||
*/ | ||
searchEntryPoint?: SearchEntryPoint; | ||
/** | ||
* List of supporting references retrieved from specified grounding source. | ||
*/ | ||
groundingChuncks?: GroundingChunk[]; | ||
/** | ||
* List of grounding support. | ||
*/ | ||
groundingSupport?: GroundingSupport[]; | ||
/** | ||
* Metadata related to retrieval in the grounding flow. | ||
*/ | ||
retrievalMetadata?: RetrievalMetadata; | ||
/** | ||
* * Web search queries for the following-up web search. | ||
*/ | ||
webSearchQueries: string[]; | ||
} | ||
/** | ||
* Grounding support. | ||
* @public | ||
*/ | ||
export declare interface GroundingSupport { | ||
/** | ||
* URI reference of the chunk. | ||
*/ | ||
segment?: string; | ||
/** | ||
* A list of indices (into 'grounding_chunk') specifying the citations | ||
* associated with the claim. For instance [1,3,4] means that | ||
* grounding_chunk[1], grounding_chunk[3], grounding_chunk[4] are the | ||
* retrieved content attributed to the claim. | ||
*/ | ||
groundingChunckIndices?: number[]; | ||
/** | ||
* Confidence score of the support references. Ranges from 0 to 1. 1 is the | ||
* most confident. This list must have the same size as the | ||
* grounding_chunk_indices. | ||
*/ | ||
confidenceScores?: number[]; | ||
} | ||
/** | ||
* Segment of the content. | ||
* @public | ||
*/ | ||
export declare interface GroundingSupportSegment { | ||
/** | ||
* The index of a Part object within its parent Content object. | ||
*/ | ||
partIndex?: number; | ||
/** | ||
* Start index in the given Part, measured in bytes. Offset from the start of | ||
* the Part, inclusive, starting at zero. | ||
*/ | ||
startIndex?: number; | ||
/** | ||
* End index in the given Part, measured in bytes. Offset from the start of | ||
* the Part, exclusive, starting at zero. | ||
*/ | ||
endIndex?: number; | ||
/** | ||
* The text corresponding to the segment from the response. | ||
*/ | ||
text?: string; | ||
} | ||
/** | ||
* Threshold above which a prompt or candidate will be blocked. | ||
@@ -839,2 +996,29 @@ * @public | ||
/** | ||
* Candidate for the logprobs token and score. | ||
* @public | ||
*/ | ||
export declare interface LogprobsCandidate { | ||
/** The candidate's token string value. */ | ||
token: string; | ||
/** The candidate's token id value. */ | ||
tokenID: number; | ||
/** The candidate's log probability. */ | ||
logProbability: number; | ||
} | ||
/** | ||
* Logprobs Result | ||
* @public | ||
*/ | ||
export declare interface LogprobsResult { | ||
/** Length = total number of decoding steps. */ | ||
topCandidates: TopCandidates[]; | ||
/** | ||
* Length = total number of decoding steps. | ||
* The chosen candidates may or may not be in topCandidates. | ||
*/ | ||
chosenCandidates: LogprobsCandidate[]; | ||
} | ||
/** | ||
* Params passed to {@link GoogleGenerativeAI.getGenerativeModel}. | ||
@@ -937,2 +1121,17 @@ * @public | ||
/** | ||
* Metadata related to retrieval in the grounding flow. | ||
* @public | ||
*/ | ||
export declare interface RetrievalMetadata { | ||
/** | ||
* Score indicating how likely information from google search could help | ||
* answer the prompt. The score is in the range [0, 1], where 0 is the least | ||
* likely and 1 is the most likely. This score is only populated when google | ||
* search grounding and dynamic retrieval is enabled. It will becompared to | ||
* the threshold to determine whether to trigger google search. | ||
*/ | ||
googleSearchDynamicRetrievalScore?: number; | ||
} | ||
/** | ||
* A safety rating associated with a {@link GenerateContentCandidate} | ||
@@ -964,5 +1163,5 @@ * @public | ||
* Optional. The type of the property. {@link | ||
* FunctionDeclarationSchemaType}. | ||
* SchemaType}. | ||
*/ | ||
type?: FunctionDeclarationSchemaType; | ||
type?: SchemaType; | ||
/** Optional. The format of the property. */ | ||
@@ -974,9 +1173,9 @@ format?: string; | ||
nullable?: boolean; | ||
/** Optional. The items of the property. {@link FunctionDeclarationSchema} */ | ||
items?: FunctionDeclarationSchema; | ||
/** Optional. The items of the property. */ | ||
items?: Schema; | ||
/** Optional. The enum of the property. */ | ||
enum?: string[]; | ||
/** Optional. Map of {@link FunctionDeclarationSchema}. */ | ||
/** Optional. Map of {@link Schema}. */ | ||
properties?: { | ||
[k: string]: FunctionDeclarationSchema; | ||
[k: string]: Schema; | ||
}; | ||
@@ -990,2 +1189,37 @@ /** Optional. Array of required property. */ | ||
/** | ||
* Contains the list of OpenAPI data types | ||
* as defined by https://swagger.io/docs/specification/data-models/data-types/ | ||
* @public | ||
*/ | ||
export declare enum SchemaType { | ||
/** String type. */ | ||
STRING = "string", | ||
/** Number type. */ | ||
NUMBER = "number", | ||
/** Integer type. */ | ||
INTEGER = "integer", | ||
/** Boolean type. */ | ||
BOOLEAN = "boolean", | ||
/** Array type. */ | ||
ARRAY = "array", | ||
/** Object type. */ | ||
OBJECT = "object" | ||
} | ||
/** | ||
* Google search entry point. | ||
* @public | ||
*/ | ||
export declare interface SearchEntryPoint { | ||
/** | ||
* Web content snippet that can be embedded in a web page or an app webview. | ||
*/ | ||
renderedContent?: string; | ||
/** | ||
* Base64 encoded JSON representing array of <search term, search url> tuple. | ||
*/ | ||
sdkBlob?: string; | ||
} | ||
/** | ||
* Params passed to atomic asynchronous operations. | ||
@@ -1052,3 +1286,3 @@ * @public | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool; | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool; | ||
@@ -1064,2 +1298,10 @@ /** | ||
/** | ||
* Candidates with top log probabilities at each decoding step | ||
*/ | ||
export declare interface TopCandidates { | ||
/** Sorted by log probability in descending order. */ | ||
candidates: LogprobsCandidate[]; | ||
} | ||
/** | ||
* Metadata on the generation request's token usage. | ||
@@ -1066,0 +1308,0 @@ * @public |
@@ -8,17 +8,17 @@ 'use strict'; | ||
*/ | ||
exports.FunctionDeclarationSchemaType = void 0; | ||
(function (FunctionDeclarationSchemaType) { | ||
exports.SchemaType = void 0; | ||
(function (SchemaType) { | ||
/** String type. */ | ||
FunctionDeclarationSchemaType["STRING"] = "STRING"; | ||
SchemaType["STRING"] = "string"; | ||
/** Number type. */ | ||
FunctionDeclarationSchemaType["NUMBER"] = "NUMBER"; | ||
SchemaType["NUMBER"] = "number"; | ||
/** Integer type. */ | ||
FunctionDeclarationSchemaType["INTEGER"] = "INTEGER"; | ||
SchemaType["INTEGER"] = "integer"; | ||
/** Boolean type. */ | ||
FunctionDeclarationSchemaType["BOOLEAN"] = "BOOLEAN"; | ||
SchemaType["BOOLEAN"] = "boolean"; | ||
/** Array type. */ | ||
FunctionDeclarationSchemaType["ARRAY"] = "ARRAY"; | ||
SchemaType["ARRAY"] = "array"; | ||
/** Object type. */ | ||
FunctionDeclarationSchemaType["OBJECT"] = "OBJECT"; | ||
})(exports.FunctionDeclarationSchemaType || (exports.FunctionDeclarationSchemaType = {})); | ||
SchemaType["OBJECT"] = "object"; | ||
})(exports.SchemaType || (exports.SchemaType = {})); | ||
@@ -173,2 +173,10 @@ /** | ||
FinishReason["LANGUAGE"] = "LANGUAGE"; | ||
// Token generation stopped because the content contains forbidden terms. | ||
FinishReason["BLOCKLIST"] = "BLOCKLIST"; | ||
// Token generation stopped for potentially containing prohibited content. | ||
FinishReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT"; | ||
// Token generation stopped because the content potentially contains Sensitive Personally Identifiable Information (SPII). | ||
FinishReason["SPII"] = "SPII"; | ||
// The function call generated by the model is invalid. | ||
FinishReason["MALFORMED_FUNCTION_CALL"] = "MALFORMED_FUNCTION_CALL"; | ||
// Unknown reason. | ||
@@ -209,2 +217,13 @@ FinishReason["OTHER"] = "OTHER"; | ||
})(exports.FunctionCallingMode || (exports.FunctionCallingMode = {})); | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
* @public | ||
*/ | ||
exports.DynamicRetrievalMode = void 0; | ||
(function (DynamicRetrievalMode) { | ||
// Unspecified function calling mode. This value should not be used. | ||
DynamicRetrievalMode["MODE_UNSPECIFIED"] = "MODE_UNSPECIFIED"; | ||
// Run retrieval only when system decides it is necessary. | ||
DynamicRetrievalMode["MODE_DYNAMIC"] = "MODE_DYNAMIC"; | ||
})(exports.DynamicRetrievalMode || (exports.DynamicRetrievalMode = {})); | ||
@@ -289,3 +308,3 @@ /** | ||
*/ | ||
const PACKAGE_VERSION = "0.16.0"; | ||
const PACKAGE_VERSION = "0.21.0"; | ||
const PACKAGE_LOG_HEADER = "genai-js"; | ||
@@ -522,3 +541,7 @@ var Task; | ||
if (part.executableCode) { | ||
textStrings.push("\n```python\n" + part.executableCode.code + "\n```\n"); | ||
textStrings.push("\n```" + | ||
part.executableCode.language + | ||
"\n" + | ||
part.executableCode.code + | ||
"\n```\n"); | ||
} | ||
@@ -753,2 +776,4 @@ if (part.codeExecutionResult) { | ||
candidate.citationMetadata; | ||
aggregatedResponse.candidates[i].groundingMetadata = | ||
candidate.groundingMetadata; | ||
aggregatedResponse.candidates[i].finishReason = candidate.finishReason; | ||
@@ -1096,4 +1121,4 @@ aggregatedResponse.candidates[i].finishMessage = | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -1145,4 +1170,4 @@ async sendMessage(request, requestOptions = {}) { | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -1297,4 +1322,4 @@ async sendMessageStream(request, requestOptions = {}) { | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -1314,4 +1339,4 @@ async generateContent(request, requestOptions = {}) { | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -1328,6 +1353,5 @@ async generateContentStream(request, requestOptions = {}) { | ||
*/ | ||
startChat(startChatParams, requestOptions = {}) { | ||
startChat(startChatParams) { | ||
var _a; | ||
const generativeModelRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions); | ||
return new ChatSession(this.apiKey, this.model, Object.assign({ generationConfig: this.generationConfig, safetySettings: this.safetySettings, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, cachedContent: (_a = this.cachedContent) === null || _a === void 0 ? void 0 : _a.name }, startChatParams), generativeModelRequestOptions); | ||
return new ChatSession(this.apiKey, this.model, Object.assign({ generationConfig: this.generationConfig, safetySettings: this.safetySettings, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, cachedContent: (_a = this.cachedContent) === null || _a === void 0 ? void 0 : _a.name }, startChatParams), this._requestOptions); | ||
} | ||
@@ -1338,4 +1362,4 @@ /** | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -1359,4 +1383,4 @@ async countTokens(request, requestOptions = {}) { | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -1372,4 +1396,4 @@ async embedContent(request, requestOptions = {}) { | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -1419,3 +1443,3 @@ async batchEmbedContents(batchEmbedContentRequest, requestOptions = {}) { | ||
*/ | ||
getGenerativeModelFromCachedContent(cachedContent, requestOptions) { | ||
getGenerativeModelFromCachedContent(cachedContent, modelParams, requestOptions) { | ||
if (!cachedContent.name) { | ||
@@ -1427,9 +1451,27 @@ throw new GoogleGenerativeAIRequestInputError("Cached content must contain a `name` field."); | ||
} | ||
const modelParamsFromCache = { | ||
model: cachedContent.model, | ||
tools: cachedContent.tools, | ||
toolConfig: cachedContent.toolConfig, | ||
systemInstruction: cachedContent.systemInstruction, | ||
cachedContent, | ||
}; | ||
/** | ||
* Not checking tools and toolConfig for now as it would require a deep | ||
* equality comparison and isn't likely to be a common case. | ||
*/ | ||
const disallowedDuplicates = ["model", "systemInstruction"]; | ||
for (const key of disallowedDuplicates) { | ||
if ((modelParams === null || modelParams === void 0 ? void 0 : modelParams[key]) && | ||
cachedContent[key] && | ||
(modelParams === null || modelParams === void 0 ? void 0 : modelParams[key]) !== cachedContent[key]) { | ||
if (key === "model") { | ||
const modelParamsComp = modelParams.model.startsWith("models/") | ||
? modelParams.model.replace("models/", "") | ||
: modelParams.model; | ||
const cachedContentComp = cachedContent.model.startsWith("models/") | ||
? cachedContent.model.replace("models/", "") | ||
: cachedContent.model; | ||
if (modelParamsComp === cachedContentComp) { | ||
continue; | ||
} | ||
} | ||
throw new GoogleGenerativeAIRequestInputError(`Different value for "${key}" specified in modelParams` + | ||
` (${modelParams[key]}) and cachedContent (${cachedContent[key]})`); | ||
} | ||
} | ||
const modelParamsFromCache = Object.assign(Object.assign({}, modelParams), { model: cachedContent.model, tools: cachedContent.tools, toolConfig: cachedContent.toolConfig, systemInstruction: cachedContent.systemInstruction, cachedContent }); | ||
return new GenerativeModel(this.apiKey, modelParamsFromCache, requestOptions); | ||
@@ -1436,0 +1478,0 @@ } |
@@ -72,3 +72,3 @@ 'use strict'; | ||
*/ | ||
const PACKAGE_VERSION = "0.16.0"; | ||
const PACKAGE_VERSION = "0.21.0"; | ||
const PACKAGE_LOG_HEADER = "genai-js"; | ||
@@ -586,17 +586,17 @@ var Task; | ||
*/ | ||
exports.FunctionDeclarationSchemaType = void 0; | ||
(function (FunctionDeclarationSchemaType) { | ||
exports.SchemaType = void 0; | ||
(function (SchemaType) { | ||
/** String type. */ | ||
FunctionDeclarationSchemaType["STRING"] = "STRING"; | ||
SchemaType["STRING"] = "string"; | ||
/** Number type. */ | ||
FunctionDeclarationSchemaType["NUMBER"] = "NUMBER"; | ||
SchemaType["NUMBER"] = "number"; | ||
/** Integer type. */ | ||
FunctionDeclarationSchemaType["INTEGER"] = "INTEGER"; | ||
SchemaType["INTEGER"] = "integer"; | ||
/** Boolean type. */ | ||
FunctionDeclarationSchemaType["BOOLEAN"] = "BOOLEAN"; | ||
SchemaType["BOOLEAN"] = "boolean"; | ||
/** Array type. */ | ||
FunctionDeclarationSchemaType["ARRAY"] = "ARRAY"; | ||
SchemaType["ARRAY"] = "array"; | ||
/** Object type. */ | ||
FunctionDeclarationSchemaType["OBJECT"] = "OBJECT"; | ||
})(exports.FunctionDeclarationSchemaType || (exports.FunctionDeclarationSchemaType = {})); | ||
SchemaType["OBJECT"] = "object"; | ||
})(exports.SchemaType || (exports.SchemaType = {})); | ||
@@ -750,2 +750,10 @@ /** | ||
FinishReason["LANGUAGE"] = "LANGUAGE"; | ||
// Token generation stopped because the content contains forbidden terms. | ||
FinishReason["BLOCKLIST"] = "BLOCKLIST"; | ||
// Token generation stopped for potentially containing prohibited content. | ||
FinishReason["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT"; | ||
// Token generation stopped because the content potentially contains Sensitive Personally Identifiable Information (SPII). | ||
FinishReason["SPII"] = "SPII"; | ||
// The function call generated by the model is invalid. | ||
FinishReason["MALFORMED_FUNCTION_CALL"] = "MALFORMED_FUNCTION_CALL"; | ||
// Unknown reason. | ||
@@ -786,2 +794,13 @@ FinishReason["OTHER"] = "OTHER"; | ||
})(exports.FunctionCallingMode || (exports.FunctionCallingMode = {})); | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
* @public | ||
*/ | ||
var DynamicRetrievalMode; | ||
(function (DynamicRetrievalMode) { | ||
// Unspecified function calling mode. This value should not be used. | ||
DynamicRetrievalMode["MODE_UNSPECIFIED"] = "MODE_UNSPECIFIED"; | ||
// Run retrieval only when system decides it is necessary. | ||
DynamicRetrievalMode["MODE_DYNAMIC"] = "MODE_DYNAMIC"; | ||
})(DynamicRetrievalMode || (DynamicRetrievalMode = {})); | ||
@@ -788,0 +807,0 @@ exports.GoogleAICacheManager = GoogleAICacheManager; |
@@ -147,2 +147,27 @@ /** | ||
/** | ||
* Specifies the dynamic retrieval configuration for the given source. | ||
* @public | ||
*/ | ||
declare interface DynamicRetrievalConfig { | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
*/ | ||
mode?: DynamicRetrievalMode; | ||
/** | ||
* The threshold to be used in dynamic retrieval. If not set, a system default | ||
* value is used. | ||
*/ | ||
dynamicThreshold?: number; | ||
} | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
* @public | ||
*/ | ||
declare enum DynamicRetrievalMode { | ||
MODE_UNSPECIFIED = "MODE_UNSPECIFIED", | ||
MODE_DYNAMIC = "MODE_DYNAMIC" | ||
} | ||
/** | ||
* Details object that may be included in an error response. | ||
@@ -362,3 +387,3 @@ * @public | ||
/** The type of the parameter. */ | ||
type: FunctionDeclarationSchemaType; | ||
type: SchemaType; | ||
/** The format of the parameter. */ | ||
@@ -382,22 +407,2 @@ properties: { | ||
/** | ||
* Contains the list of OpenAPI data types | ||
* as defined by https://swagger.io/docs/specification/data-models/data-types/ | ||
* @public | ||
*/ | ||
export declare enum FunctionDeclarationSchemaType { | ||
/** String type. */ | ||
STRING = "STRING", | ||
/** Number type. */ | ||
NUMBER = "NUMBER", | ||
/** Integer type. */ | ||
INTEGER = "INTEGER", | ||
/** Boolean type. */ | ||
BOOLEAN = "BOOLEAN", | ||
/** Array type. */ | ||
ARRAY = "ARRAY", | ||
/** Object type. */ | ||
OBJECT = "OBJECT" | ||
} | ||
/** | ||
* A FunctionDeclarationsTool is a piece of code that enables the system to | ||
@@ -527,2 +532,24 @@ * interact with external systems to perform an action, or set of actions, | ||
/** | ||
* Retrieval tool that is powered by Google search. | ||
* @public | ||
*/ | ||
declare interface GoogleSearchRetrieval { | ||
/** | ||
* Specifies the dynamic retrieval configuration for the given source. | ||
*/ | ||
dynamicRetrievalConfig?: DynamicRetrievalConfig; | ||
} | ||
/** | ||
* Retrieval tool that is powered by Google search. | ||
* @public | ||
*/ | ||
declare interface GoogleSearchRetrievalTool { | ||
/** | ||
* Google search retrieval tool config. | ||
*/ | ||
googleSearchRetrieval?: GoogleSearchRetrieval; | ||
} | ||
/** | ||
* Content part interface if the part represents an image. | ||
@@ -664,5 +691,5 @@ * @public | ||
* Optional. The type of the property. {@link | ||
* FunctionDeclarationSchemaType}. | ||
* SchemaType}. | ||
*/ | ||
type?: FunctionDeclarationSchemaType; | ||
type?: SchemaType; | ||
/** Optional. The format of the property. */ | ||
@@ -674,9 +701,9 @@ format?: string; | ||
nullable?: boolean; | ||
/** Optional. The items of the property. {@link FunctionDeclarationSchema} */ | ||
items?: FunctionDeclarationSchema; | ||
/** Optional. The items of the property. */ | ||
items?: Schema; | ||
/** Optional. The enum of the property. */ | ||
enum?: string[]; | ||
/** Optional. Map of {@link FunctionDeclarationSchema}. */ | ||
/** Optional. Map of {@link Schema}. */ | ||
properties?: { | ||
[k: string]: FunctionDeclarationSchema; | ||
[k: string]: Schema; | ||
}; | ||
@@ -690,6 +717,26 @@ /** Optional. Array of required property. */ | ||
/** | ||
* Contains the list of OpenAPI data types | ||
* as defined by https://swagger.io/docs/specification/data-models/data-types/ | ||
* @public | ||
*/ | ||
export declare enum SchemaType { | ||
/** String type. */ | ||
STRING = "string", | ||
/** Number type. */ | ||
NUMBER = "number", | ||
/** Integer type. */ | ||
INTEGER = "integer", | ||
/** Boolean type. */ | ||
BOOLEAN = "boolean", | ||
/** Array type. */ | ||
ARRAY = "array", | ||
/** Object type. */ | ||
OBJECT = "object" | ||
} | ||
/** | ||
* Params passed to atomic asynchronous operations. | ||
* @public | ||
*/ | ||
declare interface SingleRequestOptions extends RequestOptions { | ||
export declare interface SingleRequestOptions extends RequestOptions { | ||
/** | ||
@@ -724,3 +771,3 @@ * An object that may be used to abort asynchronous requests. The request may | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool; | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool; | ||
@@ -727,0 +774,0 @@ /** |
@@ -35,3 +35,3 @@ /** | ||
*/ | ||
getGenerativeModelFromCachedContent(cachedContent: CachedContent, requestOptions?: RequestOptions): GenerativeModel; | ||
getGenerativeModelFromCachedContent(cachedContent: CachedContent, modelParams?: Partial<ModelParams>, requestOptions?: RequestOptions): GenerativeModel; | ||
} |
@@ -43,4 +43,4 @@ /** | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -54,6 +54,6 @@ sendMessage(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
sendMessageStream(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
} |
@@ -29,3 +29,2 @@ /** | ||
safetySettings: SafetySetting[]; | ||
requestOptions: RequestOptions; | ||
tools?: Tool[]; | ||
@@ -41,4 +40,4 @@ toolConfig?: ToolConfig; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -53,4 +52,4 @@ generateContent(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -62,3 +61,3 @@ generateContentStream(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
*/ | ||
startChat(startChatParams?: StartChatParams, requestOptions?: SingleRequestOptions): ChatSession; | ||
startChat(startChatParams?: StartChatParams): ChatSession; | ||
/** | ||
@@ -68,4 +67,4 @@ * Counts the tokens in the provided request. | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -77,4 +76,4 @@ countTokens(request: CountTokensRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<CountTokensResponse>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -86,6 +85,6 @@ embedContent(request: EmbedContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<EmbedContentResponse>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest, requestOptions?: SingleRequestOptions): Promise<BatchEmbedContentsResponse>; | ||
} |
@@ -75,2 +75,6 @@ /** | ||
LANGUAGE = "LANGUAGE", | ||
BLOCKLIST = "BLOCKLIST", | ||
PROHIBITED_CONTENT = "PROHIBITED_CONTENT", | ||
SPII = "SPII", | ||
MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL", | ||
OTHER = "OTHER" | ||
@@ -99,1 +103,9 @@ } | ||
} | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
* @public | ||
*/ | ||
export declare enum DynamicRetrievalMode { | ||
MODE_UNSPECIFIED = "MODE_UNSPECIFIED", | ||
MODE_DYNAMIC = "MODE_DYNAMIC" | ||
} |
@@ -84,15 +84,15 @@ /** | ||
*/ | ||
export declare enum FunctionDeclarationSchemaType { | ||
export declare enum SchemaType { | ||
/** String type. */ | ||
STRING = "STRING", | ||
STRING = "string", | ||
/** Number type. */ | ||
NUMBER = "NUMBER", | ||
NUMBER = "number", | ||
/** Integer type. */ | ||
INTEGER = "INTEGER", | ||
INTEGER = "integer", | ||
/** Boolean type. */ | ||
BOOLEAN = "BOOLEAN", | ||
BOOLEAN = "boolean", | ||
/** Array type. */ | ||
ARRAY = "ARRAY", | ||
ARRAY = "array", | ||
/** Object type. */ | ||
OBJECT = "OBJECT" | ||
OBJECT = "object" | ||
} | ||
@@ -108,5 +108,5 @@ /** | ||
* Optional. The type of the property. {@link | ||
* FunctionDeclarationSchemaType}. | ||
* SchemaType}. | ||
*/ | ||
type?: FunctionDeclarationSchemaType; | ||
type?: SchemaType; | ||
/** Optional. The format of the property. */ | ||
@@ -118,9 +118,9 @@ format?: string; | ||
nullable?: boolean; | ||
/** Optional. The items of the property. {@link FunctionDeclarationSchema} */ | ||
items?: FunctionDeclarationSchema; | ||
/** Optional. The items of the property. */ | ||
items?: Schema; | ||
/** Optional. The enum of the property. */ | ||
enum?: string[]; | ||
/** Optional. Map of {@link FunctionDeclarationSchema}. */ | ||
/** Optional. Map of {@link Schema}. */ | ||
properties?: { | ||
[k: string]: FunctionDeclarationSchema; | ||
[k: string]: Schema; | ||
}; | ||
@@ -138,3 +138,3 @@ /** Optional. Array of required property. */ | ||
/** The type of the parameter. */ | ||
type: FunctionDeclarationSchemaType; | ||
type: SchemaType; | ||
/** The format of the parameter. */ | ||
@@ -141,0 +141,0 @@ properties: { |
@@ -21,2 +21,3 @@ /** | ||
export * from "./responses"; | ||
export * from "./search-grounding"; | ||
export { CachedContent, CachedContentBase } from "./server/caching"; |
@@ -21,2 +21,3 @@ /** | ||
import { FunctionDeclarationsTool, ResponseSchema, ToolConfig } from "./function-calling"; | ||
import { GoogleSearchRetrievalTool } from "./search-grounding"; | ||
/** | ||
@@ -94,2 +95,21 @@ * Base parameters for a number of methods. | ||
responseSchema?: ResponseSchema; | ||
/** | ||
* Presence penalty applied to the next token's logprobs if the token has | ||
* already been seen in the response. | ||
*/ | ||
presencePenalty?: number; | ||
/** | ||
* Frequency penalty applied to the next token's logprobs, multiplied by the | ||
* number of times each token has been seen in the respponse so far. | ||
*/ | ||
frequencyPenalty?: number; | ||
/** | ||
* If True, export the logprobs results in response. | ||
*/ | ||
responseLogprobs?: boolean; | ||
/** | ||
* Valid if responseLogProbs is set to True. This will set the number of top | ||
* logprobs to return at each decoding step in the logprobsResult. | ||
*/ | ||
logprobs?: number; | ||
} | ||
@@ -195,3 +215,3 @@ /** | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool; | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool; | ||
/** | ||
@@ -198,0 +218,0 @@ * Enables the model to execute code as part of generation. |
@@ -19,2 +19,3 @@ /** | ||
import { BlockReason, FinishReason, HarmCategory, HarmProbability } from "./enums"; | ||
import { GroundingMetadata } from "./search-grounding"; | ||
/** | ||
@@ -80,2 +81,34 @@ * Result object returned from generateContent() call. | ||
/** | ||
* Logprobs Result | ||
* @public | ||
*/ | ||
export interface LogprobsResult { | ||
/** Length = total number of decoding steps. */ | ||
topCandidates: TopCandidates[]; | ||
/** | ||
* Length = total number of decoding steps. | ||
* The chosen candidates may or may not be in topCandidates. | ||
*/ | ||
chosenCandidates: LogprobsCandidate[]; | ||
} | ||
/** | ||
* Candidate for the logprobs token and score. | ||
* @public | ||
*/ | ||
export interface LogprobsCandidate { | ||
/** The candidate's token string value. */ | ||
token: string; | ||
/** The candidate's token id value. */ | ||
tokenID: number; | ||
/** The candidate's log probability. */ | ||
logProbability: number; | ||
} | ||
/** | ||
* Candidates with top log probabilities at each decoding step | ||
*/ | ||
export interface TopCandidates { | ||
/** Sorted by log probability in descending order. */ | ||
candidates: LogprobsCandidate[]; | ||
} | ||
/** | ||
* Metadata on the generation request's token usage. | ||
@@ -115,2 +148,8 @@ * @public | ||
citationMetadata?: CitationMetadata; | ||
/** Average log probability score of the candidate. */ | ||
avgLogprobs?: number; | ||
/** Log-likelihood scores for the response tokens and top tokens. */ | ||
logprobsResult?: LogprobsResult; | ||
/** Search grounding metadata. */ | ||
groundingMetadata?: GroundingMetadata; | ||
} | ||
@@ -117,0 +156,0 @@ /** |
@@ -20,4 +20,4 @@ /** | ||
export * from "./shared"; | ||
export { RequestOptions, Tool, CodeExecutionTool } from "../../types/requests"; | ||
export * from "../../types/content"; | ||
export { FunctionCallingMode } from "../../types/enums"; | ||
export { RequestOptions, Tool, CodeExecutionTool, SingleRequestOptions, } from "../requests"; | ||
export * from "../content"; | ||
export { FunctionCallingMode } from "../enums"; |
@@ -35,3 +35,3 @@ /** | ||
*/ | ||
getGenerativeModelFromCachedContent(cachedContent: CachedContent, requestOptions?: RequestOptions): GenerativeModel; | ||
getGenerativeModelFromCachedContent(cachedContent: CachedContent, modelParams?: Partial<ModelParams>, requestOptions?: RequestOptions): GenerativeModel; | ||
} |
@@ -43,4 +43,4 @@ /** | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -54,6 +54,6 @@ sendMessage(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
sendMessageStream(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
} |
@@ -29,3 +29,2 @@ /** | ||
safetySettings: SafetySetting[]; | ||
requestOptions: RequestOptions; | ||
tools?: Tool[]; | ||
@@ -41,4 +40,4 @@ toolConfig?: ToolConfig; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -53,4 +52,4 @@ generateContent(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -62,3 +61,3 @@ generateContentStream(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
*/ | ||
startChat(startChatParams?: StartChatParams, requestOptions?: SingleRequestOptions): ChatSession; | ||
startChat(startChatParams?: StartChatParams): ChatSession; | ||
/** | ||
@@ -68,4 +67,4 @@ * Counts the tokens in the provided request. | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -77,4 +76,4 @@ countTokens(request: CountTokensRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<CountTokensResponse>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
@@ -86,6 +85,6 @@ embedContent(request: EmbedContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<EmbedContentResponse>; | ||
* Fields set in the optional {@link SingleRequestOptions} parameter will | ||
* take precedence over the {@link RequestOptions} values provided at the | ||
* time of the {@link GoogleAIFileManager} initialization. | ||
* take precedence over the {@link RequestOptions} values provided to | ||
* {@link GoogleGenerativeAI.getGenerativeModel }. | ||
*/ | ||
batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest, requestOptions?: SingleRequestOptions): Promise<BatchEmbedContentsResponse>; | ||
} |
@@ -75,2 +75,6 @@ /** | ||
LANGUAGE = "LANGUAGE", | ||
BLOCKLIST = "BLOCKLIST", | ||
PROHIBITED_CONTENT = "PROHIBITED_CONTENT", | ||
SPII = "SPII", | ||
MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL", | ||
OTHER = "OTHER" | ||
@@ -99,1 +103,9 @@ } | ||
} | ||
/** | ||
* The mode of the predictor to be used in dynamic retrieval. | ||
* @public | ||
*/ | ||
export declare enum DynamicRetrievalMode { | ||
MODE_UNSPECIFIED = "MODE_UNSPECIFIED", | ||
MODE_DYNAMIC = "MODE_DYNAMIC" | ||
} |
@@ -84,15 +84,15 @@ /** | ||
*/ | ||
export declare enum FunctionDeclarationSchemaType { | ||
export declare enum SchemaType { | ||
/** String type. */ | ||
STRING = "STRING", | ||
STRING = "string", | ||
/** Number type. */ | ||
NUMBER = "NUMBER", | ||
NUMBER = "number", | ||
/** Integer type. */ | ||
INTEGER = "INTEGER", | ||
INTEGER = "integer", | ||
/** Boolean type. */ | ||
BOOLEAN = "BOOLEAN", | ||
BOOLEAN = "boolean", | ||
/** Array type. */ | ||
ARRAY = "ARRAY", | ||
ARRAY = "array", | ||
/** Object type. */ | ||
OBJECT = "OBJECT" | ||
OBJECT = "object" | ||
} | ||
@@ -108,5 +108,5 @@ /** | ||
* Optional. The type of the property. {@link | ||
* FunctionDeclarationSchemaType}. | ||
* SchemaType}. | ||
*/ | ||
type?: FunctionDeclarationSchemaType; | ||
type?: SchemaType; | ||
/** Optional. The format of the property. */ | ||
@@ -118,9 +118,9 @@ format?: string; | ||
nullable?: boolean; | ||
/** Optional. The items of the property. {@link FunctionDeclarationSchema} */ | ||
items?: FunctionDeclarationSchema; | ||
/** Optional. The items of the property. */ | ||
items?: Schema; | ||
/** Optional. The enum of the property. */ | ||
enum?: string[]; | ||
/** Optional. Map of {@link FunctionDeclarationSchema}. */ | ||
/** Optional. Map of {@link Schema}. */ | ||
properties?: { | ||
[k: string]: FunctionDeclarationSchema; | ||
[k: string]: Schema; | ||
}; | ||
@@ -138,3 +138,3 @@ /** Optional. Array of required property. */ | ||
/** The type of the parameter. */ | ||
type: FunctionDeclarationSchemaType; | ||
type: SchemaType; | ||
/** The format of the parameter. */ | ||
@@ -141,0 +141,0 @@ properties: { |
@@ -21,2 +21,3 @@ /** | ||
export * from "./responses"; | ||
export * from "./search-grounding"; | ||
export { CachedContent, CachedContentBase } from "./server/caching"; |
@@ -21,2 +21,3 @@ /** | ||
import { FunctionDeclarationsTool, ResponseSchema, ToolConfig } from "./function-calling"; | ||
import { GoogleSearchRetrievalTool } from "./search-grounding"; | ||
/** | ||
@@ -94,2 +95,21 @@ * Base parameters for a number of methods. | ||
responseSchema?: ResponseSchema; | ||
/** | ||
* Presence penalty applied to the next token's logprobs if the token has | ||
* already been seen in the response. | ||
*/ | ||
presencePenalty?: number; | ||
/** | ||
* Frequency penalty applied to the next token's logprobs, multiplied by the | ||
* number of times each token has been seen in the respponse so far. | ||
*/ | ||
frequencyPenalty?: number; | ||
/** | ||
* If True, export the logprobs results in response. | ||
*/ | ||
responseLogprobs?: boolean; | ||
/** | ||
* Valid if responseLogProbs is set to True. This will set the number of top | ||
* logprobs to return at each decoding step in the logprobsResult. | ||
*/ | ||
logprobs?: number; | ||
} | ||
@@ -195,3 +215,3 @@ /** | ||
*/ | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool; | ||
export declare type Tool = FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool; | ||
/** | ||
@@ -198,0 +218,0 @@ * Enables the model to execute code as part of generation. |
@@ -19,2 +19,3 @@ /** | ||
import { BlockReason, FinishReason, HarmCategory, HarmProbability } from "./enums"; | ||
import { GroundingMetadata } from "./search-grounding"; | ||
/** | ||
@@ -80,2 +81,34 @@ * Result object returned from generateContent() call. | ||
/** | ||
* Logprobs Result | ||
* @public | ||
*/ | ||
export interface LogprobsResult { | ||
/** Length = total number of decoding steps. */ | ||
topCandidates: TopCandidates[]; | ||
/** | ||
* Length = total number of decoding steps. | ||
* The chosen candidates may or may not be in topCandidates. | ||
*/ | ||
chosenCandidates: LogprobsCandidate[]; | ||
} | ||
/** | ||
* Candidate for the logprobs token and score. | ||
* @public | ||
*/ | ||
export interface LogprobsCandidate { | ||
/** The candidate's token string value. */ | ||
token: string; | ||
/** The candidate's token id value. */ | ||
tokenID: number; | ||
/** The candidate's log probability. */ | ||
logProbability: number; | ||
} | ||
/** | ||
* Candidates with top log probabilities at each decoding step | ||
*/ | ||
export interface TopCandidates { | ||
/** Sorted by log probability in descending order. */ | ||
candidates: LogprobsCandidate[]; | ||
} | ||
/** | ||
* Metadata on the generation request's token usage. | ||
@@ -115,2 +148,8 @@ * @public | ||
citationMetadata?: CitationMetadata; | ||
/** Average log probability score of the candidate. */ | ||
avgLogprobs?: number; | ||
/** Log-likelihood scores for the response tokens and top tokens. */ | ||
logprobsResult?: LogprobsResult; | ||
/** Search grounding metadata. */ | ||
groundingMetadata?: GroundingMetadata; | ||
} | ||
@@ -117,0 +156,0 @@ /** |
@@ -20,4 +20,4 @@ /** | ||
export * from "./shared"; | ||
export { RequestOptions, Tool, CodeExecutionTool } from "../../types/requests"; | ||
export * from "../../types/content"; | ||
export { FunctionCallingMode } from "../../types/enums"; | ||
export { RequestOptions, Tool, CodeExecutionTool, SingleRequestOptions, } from "../requests"; | ||
export * from "../content"; | ||
export { FunctionCallingMode } from "../enums"; |
{ | ||
"name": "@fuyun/generative-ai", | ||
"version": "0.16.0", | ||
"version": "0.21.0", | ||
"description": "Google AI JavaScript SDK", | ||
@@ -26,2 +26,6 @@ "main": "dist/index.js", | ||
}, | ||
"files": [ | ||
"server", | ||
"dist" | ||
], | ||
"server": [ | ||
@@ -37,9 +41,47 @@ "dist", | ||
"test:node:integration": "yarn build && TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha \"test-integration/node/**/*.test.ts\"", | ||
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", | ||
"api-report": "api-extractor run --local --verbose && api-extractor run -c api-extractor.server.json --local --verbose", | ||
"docs": "yarn build && yarn api-documenter markdown -i ./temp/main -o ../../docs/reference/main && yarn api-documenter markdown -i ./temp/server -o ../../docs/reference/server" | ||
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path './.gitignore'", | ||
"api-report": "api-extractor run -c api-extractor.json --local --verbose && api-extractor run -c api-extractor.server.json --local --verbose", | ||
"docs": "yarn build && yarn api-documenter markdown -i ./temp/main -o ./docs/reference/main && yarn api-documenter markdown -i ./temp/server -o ./docs/reference/server", | ||
"format": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"nodenext\"}' yarn ts-node scripts/run-format.ts", | ||
"format:check": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"nodenext\"}' yarn ts-node scripts/check-format.ts" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.27.1", | ||
"@esm-bundle/chai": "^4.3.4-fix.0", | ||
"@microsoft/api-documenter": "^7.23.12", | ||
"@microsoft/api-extractor": "^7.38.2", | ||
"@rollup/plugin-json": "^6.0.1", | ||
"@types/chai": "^4.3.9", | ||
"@types/chai-as-promised": "^7.1.8", | ||
"@types/mocha": "^10.0.3", | ||
"@types/node": "^20.8.10", | ||
"@types/sinon": "^10.0.20", | ||
"@types/sinon-chai": "^3.2.11", | ||
"@typescript-eslint/eslint-plugin": "^6.9.1", | ||
"@typescript-eslint/eslint-plugin-tslint": "^6.9.1", | ||
"@typescript-eslint/parser": "^6.9.1", | ||
"@web/dev-server-esbuild": "^1.0.1", | ||
"@web/test-runner": "^0.18.0", | ||
"chai": "^4.3.10", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-deep-equal-ignore-undefined": "^1.1.1", | ||
"eslint": "^8.52.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-unused-imports": "^3.0.0", | ||
"glob": "^10.3.10", | ||
"mocha": "^10.2.0", | ||
"prettier": "^3.0.3", | ||
"rollup": "^4.2.0", | ||
"rollup-plugin-dts": "^6.1.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-typescript2": "^0.36.0", | ||
"sinon": "^17.0.1", | ||
"sinon-chai": "^3.7.0", | ||
"ts-node": "^10.9.1", | ||
"tslint": "^6.1.3", | ||
"typescript": "5.2.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/google/generative-ai-js.git" | ||
"url": "git+https://github.com/fuyun/generative-ai-js.git" | ||
}, | ||
@@ -49,5 +91,6 @@ "author": "", | ||
"bugs": { | ||
"url": "https://github.com/google/generative-ai-js/issues" | ||
"url": "https://github.com/fuyun/generative-ai-js/issues" | ||
}, | ||
"homepage": "https://github.com/google/generative-ai-js#readme" | ||
"homepage": "https://github.com/fuyun/generative-ai-js#readme", | ||
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447" | ||
} |
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
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
3
-25%404068
-77.32%34
Infinity%81
-47.74%10692
-73.48%2
100%2
100%