From d069d67a76f5e6c47c0a497e6d0809b102d82e94 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 5 Jun 2024 13:39:05 -0700 Subject: [PATCH 01/14] add cache, streamline request functions --- packages/main/api-extractor.files.json | 12 -- packages/main/api-extractor.server.json | 12 ++ packages/main/files/package.json | 8 - packages/main/server/package.json | 8 + packages/main/src/methods/count-tokens.ts | 4 +- packages/main/src/methods/embed-content.ts | 6 +- packages/main/src/methods/generate-content.ts | 6 +- packages/main/src/requests/request.test.ts | 30 ++-- packages/main/src/requests/request.ts | 117 +++++++------- packages/main/src/server/cache-manager.ts | 147 ++++++++++++++++++ .../main/src/{files => server}/constants.ts | 4 +- .../{files => server}/file-manager.test.ts | 22 +-- .../src/{files => server}/file-manager.ts | 20 +-- packages/main/src/{files => server}/index.ts | 0 .../src/{files => server}/request.test.ts | 36 ++--- .../main/src/{files => server}/request.ts | 111 ++++++------- packages/main/src/server/types/caching.ts | 62 ++++++++ .../{files/types.ts => server/types/files.ts} | 33 +--- packages/main/src/server/types/index.ts | 20 +++ packages/main/src/server/types/shared.ts | 49 ++++++ 20 files changed, 470 insertions(+), 237 deletions(-) delete mode 100644 packages/main/api-extractor.files.json create mode 100644 packages/main/api-extractor.server.json delete mode 100644 packages/main/files/package.json create mode 100644 packages/main/server/package.json create mode 100644 packages/main/src/server/cache-manager.ts rename packages/main/src/{files => server}/constants.ts (91%) rename packages/main/src/{files => server}/file-manager.test.ts (93%) rename packages/main/src/{files => server}/file-manager.ts (90%) rename packages/main/src/{files => server}/index.ts (100%) rename packages/main/src/{files => server}/request.test.ts (86%) rename packages/main/src/{files => server}/request.ts (61%) create mode 100644 packages/main/src/server/types/caching.ts rename packages/main/src/{files/types.ts => server/types/files.ts} (81%) create mode 100644 packages/main/src/server/types/index.ts create mode 100644 packages/main/src/server/types/shared.ts diff --git a/packages/main/api-extractor.files.json b/packages/main/api-extractor.files.json deleted file mode 100644 index ffa2f792..00000000 --- a/packages/main/api-extractor.files.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "../../config/api-extractor.json", - "mainEntryPointFilePath": "/dist/src/files/index.d.ts", - "dtsRollup": { - "enabled": true, - "untrimmedFilePath": "/dist/files/files.d.ts" - }, - "docModel": { - "enabled": true, - "apiJsonFilePath": "/temp/files/-files.api.json" - } -} diff --git a/packages/main/api-extractor.server.json b/packages/main/api-extractor.server.json new file mode 100644 index 00000000..e1cd2777 --- /dev/null +++ b/packages/main/api-extractor.server.json @@ -0,0 +1,12 @@ +{ + "extends": "../../config/api-extractor.json", + "mainEntryPointFilePath": "/dist/src/server/index.d.ts", + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "/dist/server/server.d.ts" + }, + "docModel": { + "enabled": true, + "apiJsonFilePath": "/temp/server/-server.api.json" + } +} diff --git a/packages/main/files/package.json b/packages/main/files/package.json deleted file mode 100644 index d88794bd..00000000 --- a/packages/main/files/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "@google/generative-ai-files", - "description": "GoogleAI file upload manager", - "main": "../dist/files/index.js", - "browser": "../dist/files/index.mjs", - "module": "../dist/files/index.mjs", - "typings": "../dist/files/files.d.ts" -} diff --git a/packages/main/server/package.json b/packages/main/server/package.json new file mode 100644 index 00000000..68af6537 --- /dev/null +++ b/packages/main/server/package.json @@ -0,0 +1,8 @@ +{ + "name": "@google/generative-ai-server", + "description": "GoogleAI file upload manager", + "main": "../dist/server/index.js", + "browser": "../dist/server/index.mjs", + "module": "../dist/server/index.mjs", + "typings": "../dist/server/server.d.ts" +} diff --git a/packages/main/src/methods/count-tokens.ts b/packages/main/src/methods/count-tokens.ts index 90ef8e05..a8a38e93 100644 --- a/packages/main/src/methods/count-tokens.ts +++ b/packages/main/src/methods/count-tokens.ts @@ -20,7 +20,7 @@ import { CountTokensResponse, RequestOptions, } from "../../types"; -import { Task, makeRequest } from "../requests/request"; +import { Task, makeModelRequest } from "../requests/request"; export async function countTokens( apiKey: string, @@ -28,7 +28,7 @@ export async function countTokens( params: CountTokensRequest, requestOptions?: RequestOptions, ): Promise { - const response = await makeRequest( + const response = await makeModelRequest( model, Task.COUNT_TOKENS, apiKey, diff --git a/packages/main/src/methods/embed-content.ts b/packages/main/src/methods/embed-content.ts index f5060e56..339a08a6 100644 --- a/packages/main/src/methods/embed-content.ts +++ b/packages/main/src/methods/embed-content.ts @@ -22,7 +22,7 @@ import { EmbedContentResponse, RequestOptions, } from "../../types"; -import { Task, makeRequest } from "../requests/request"; +import { Task, makeModelRequest } from "../requests/request"; export async function embedContent( apiKey: string, @@ -30,7 +30,7 @@ export async function embedContent( params: EmbedContentRequest, requestOptions?: RequestOptions, ): Promise { - const response = await makeRequest( + const response = await makeModelRequest( model, Task.EMBED_CONTENT, apiKey, @@ -52,7 +52,7 @@ export async function batchEmbedContents( return { ...request, model }; }, ); - const response = await makeRequest( + const response = await makeModelRequest( model, Task.BATCH_EMBED_CONTENTS, apiKey, diff --git a/packages/main/src/methods/generate-content.ts b/packages/main/src/methods/generate-content.ts index d9aa3aab..327cd96e 100644 --- a/packages/main/src/methods/generate-content.ts +++ b/packages/main/src/methods/generate-content.ts @@ -22,7 +22,7 @@ import { GenerateContentStreamResult, RequestOptions, } from "../../types"; -import { Task, makeRequest } from "../requests/request"; +import { Task, makeModelRequest } from "../requests/request"; import { addHelpers } from "../requests/response-helpers"; import { processStream } from "../requests/stream-reader"; @@ -32,7 +32,7 @@ export async function generateContentStream( params: GenerateContentRequest, requestOptions?: RequestOptions, ): Promise { - const response = await makeRequest( + const response = await makeModelRequest( model, Task.STREAM_GENERATE_CONTENT, apiKey, @@ -49,7 +49,7 @@ export async function generateContent( params: GenerateContentRequest, requestOptions?: RequestOptions, ): Promise { - const response = await makeRequest( + const response = await makeModelRequest( model, Task.GENERATE_CONTENT, apiKey, diff --git a/packages/main/src/requests/request.test.ts b/packages/main/src/requests/request.test.ts index 14ce6450..b898b443 100644 --- a/packages/main/src/requests/request.test.ts +++ b/packages/main/src/requests/request.test.ts @@ -24,8 +24,8 @@ import { DEFAULT_BASE_URL, RequestUrl, Task, - _makeRequestInternal, - constructRequest, + constructModelRequest, + makeModelRequest, } from "./request"; import { GoogleGenerativeAIFetchError, @@ -112,7 +112,7 @@ describe("request methods", () => { }); describe("constructRequest", () => { it("handles basic request", async () => { - const request = await constructRequest( + const request = await constructModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -131,7 +131,7 @@ describe("request methods", () => { ).to.equal("application/json"); }); it("passes apiClient", async () => { - const request = await constructRequest( + const request = await constructModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -146,7 +146,7 @@ describe("request methods", () => { ).to.equal("client/version genai-js/__PACKAGE_VERSION__"); }); it("passes timeout", async () => { - const request = await constructRequest( + const request = await constructModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -159,7 +159,7 @@ describe("request methods", () => { expect(request.fetchOptions.signal).to.be.instanceOf(AbortSignal); }); it("passes custom headers", async () => { - const request = await constructRequest( + const request = await constructModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -175,7 +175,7 @@ describe("request methods", () => { }); it("passes custom x-goog-api-client header", async () => { await expect( - constructRequest("model-name", Task.GENERATE_CONTENT, "key", true, "", { + constructModelRequest("model-name", Task.GENERATE_CONTENT, "key", true, "", { customHeaders: new Headers({ "x-goog-api-client": "client/version", }), @@ -184,7 +184,7 @@ describe("request methods", () => { }); it("passes apiClient and custom x-goog-api-client header", async () => { await expect( - constructRequest("model-name", Task.GENERATE_CONTENT, "key", true, "", { + constructModelRequest("model-name", Task.GENERATE_CONTENT, "key", true, "", { apiClient: "client/version", customHeaders: new Headers({ "x-goog-api-client": "client/version2", @@ -193,12 +193,12 @@ describe("request methods", () => { ).to.be.rejectedWith(GoogleGenerativeAIRequestInputError); }); }); - describe("_makeRequestInternal", () => { + describe("makeModelRequest", () => { it("no error", async () => { const fetchStub = stub().resolves({ ok: true, } as Response); - const response = await _makeRequestInternal( + const response = await makeModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -222,7 +222,7 @@ describe("request methods", () => { } as Response); try { - await _makeRequestInternal( + await makeModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -251,7 +251,7 @@ describe("request methods", () => { statusText: "Server Error", } as Response); try { - await _makeRequestInternal( + await makeModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -280,7 +280,7 @@ describe("request methods", () => { } as Response); try { - await _makeRequestInternal( + await makeModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -321,7 +321,7 @@ describe("request methods", () => { } as Response); try { - await _makeRequestInternal( + await makeModelRequest( "model-name", Task.GENERATE_CONTENT, "key", @@ -349,7 +349,7 @@ describe("request methods", () => { it("has invalid custom header", async () => { const fetchStub = stub(); await expect( - _makeRequestInternal( + makeModelRequest( "model-name", Task.GENERATE_CONTENT, "key", diff --git a/packages/main/src/requests/request.ts b/packages/main/src/requests/request.ts index 540de899..3c0072f8 100644 --- a/packages/main/src/requests/request.ts +++ b/packages/main/src/requests/request.ts @@ -110,7 +110,7 @@ export async function getHeaders(url: RequestUrl): Promise { return headers; } -export async function constructRequest( +export async function constructModelRequest( model: string, task: Task, apiKey: string, @@ -130,89 +130,86 @@ export async function constructRequest( }; } -/** - * Wrapper for _makeRequestInternal that automatically uses native fetch, - * allowing _makeRequestInternal to be tested with a mocked fetch function. - */ -export async function makeRequest( +export async function makeModelRequest( model: string, task: Task, apiKey: string, stream: boolean, body: string, requestOptions?: RequestOptions, + // Allows this to be stubbed for tests + fetchFn = fetch, ): Promise { - return _makeRequestInternal( + const { url, fetchOptions } = await constructModelRequest( model, task, apiKey, stream, body, requestOptions, - fetch, ); + return makeRequest(url, fetchOptions, fetchFn); } -export async function _makeRequestInternal( - model: string, - task: Task, - apiKey: string, - stream: boolean, - body: string, - requestOptions?: RequestOptions, - // Allows this to be stubbed for tests +export async function makeRequest( + url: string, + fetchOptions: RequestInit, fetchFn = fetch, ): Promise { - const url = new RequestUrl(model, task, apiKey, stream, requestOptions); let response; try { - const request = await constructRequest( - model, - task, - apiKey, - stream, - body, - requestOptions, + response = await fetchFn(url, fetchOptions); + } catch (e) { + handleResponseError(e, url); + } + + if (!response.ok) { + await handleResponseNotOk(response, url); + } + + return response; +} + +export function handleResponseError(e: Error, url: string): void { + let err = e; + if ( + !( + e instanceof GoogleGenerativeAIFetchError || + e instanceof GoogleGenerativeAIRequestInputError + ) + ) { + err = new GoogleGenerativeAIError( + `Error fetching from ${url.toString()}: ${e.message}`, ); - response = await fetchFn(request.url, request.fetchOptions); - if (!response.ok) { - let message = ""; - let errorDetails; - try { - const json = await response.json(); - message = json.error.message; - if (json.error.details) { - message += ` ${JSON.stringify(json.error.details)}`; - errorDetails = json.error.details; - } - } catch (e) { - // ignored - } - throw new GoogleGenerativeAIFetchError( - `Error fetching from ${url.toString()}: [${response.status} ${ - response.statusText - }] ${message}`, - response.status, - response.statusText, - errorDetails, - ); + err.stack = e.stack; + } + throw err; +} + +export async function handleResponseNotOk( + response: Response, + url: string, +): Promise { + let message = ""; + let errorDetails; + try { + const json = await response.json(); + message = json.error.message; + if (json.error.details) { + message += ` ${JSON.stringify(json.error.details)}`; + errorDetails = json.error.details; } } catch (e) { - let err = e; - if ( - !( - e instanceof GoogleGenerativeAIFetchError || - e instanceof GoogleGenerativeAIRequestInputError - ) - ) { - err = new GoogleGenerativeAIError( - `Error fetching from ${url.toString()}: ${e.message}`, - ); - err.stack = e.stack; - } - throw err; + // ignored } - return response; + throw new GoogleGenerativeAIFetchError( + `Error fetching from ${url.toString()}: [${response.status} ${ + response.statusText + }] ${message}`, + response.status, + response.statusText, + errorDetails, + ); } /** diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts new file mode 100644 index 00000000..d316589a --- /dev/null +++ b/packages/main/src/server/cache-manager.ts @@ -0,0 +1,147 @@ +/** + * @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. + */ + +import { Content, Part, RequestOptions, Tool, ToolConfig } from "../../types"; +import { + CachedContentUrl, + FilesRequestUrl, + getHeaders, + makeServerRequest, +} from "./request"; +import { + CachedContent, + CachedContentCreateParams, + CachedContentUpdateParams, + ListCacheResponse, + ListParams, +} from "./types"; +import { RpcTask } from "./constants"; + +/** + * Class for managing GoogleAI file uploads. + * @public + */ +export class CacheManager { + model: string; + ttl?: string; + tools?: Tool[]; + toolConfig?: ToolConfig; + systemInstruction?: string | Part | Content; + + constructor( + public apiKey: string, + private _requestOptions: RequestOptions, + ) {} + + /** + * Upload a new content cache + */ + async create( + createOptions: CachedContentCreateParams, + ): Promise { + const newCachedContent: CachedContent = { ...createOptions }; + if (createOptions.ttlSeconds) { + newCachedContent.ttl = createOptions.ttlSeconds.toString() + "s"; + delete (newCachedContent as CachedContentCreateParams).ttlSeconds; + } + const url = new CachedContentUrl( + RpcTask.UPLOAD, + this.apiKey, + this._requestOptions, + ); + + const uploadHeaders = getHeaders(url); + + const response = await makeServerRequest( + url, + uploadHeaders, + JSON.stringify(newCachedContent), + ); + return response.json(); + } + + /** + * List all uploaded content caches + */ + async list(listParams?: ListParams): Promise { + const url = new CachedContentUrl( + RpcTask.LIST, + this.apiKey, + this._requestOptions, + ); + if (listParams?.pageSize) { + url.appendParam("pageSize", listParams.pageSize.toString()); + } + if (listParams?.pageToken) { + url.appendParam("pageToken", listParams.pageToken); + } + const uploadHeaders = getHeaders(url); + const response = await makeServerRequest(url, uploadHeaders); + return response.json(); + } + + /** + * Get a content cache + */ + async get(name: string): Promise { + const url = new CachedContentUrl( + RpcTask.GET, + this.apiKey, + this._requestOptions, + ); + url.appendPath(name); + const uploadHeaders = getHeaders(url); + const response = await makeServerRequest(url, uploadHeaders); + return response.json(); + } + + /** + * Update an existing content cache + */ + async update( + name: string, + updateParams: CachedContentUpdateParams, + ): Promise { + const url = new CachedContentUrl( + RpcTask.UPDATE, + this.apiKey, + this._requestOptions, + ); + url.appendPath(name); + const uploadHeaders = getHeaders(url); + const response = await makeServerRequest( + url, + uploadHeaders, + JSON.stringify(updateParams), + ); + return response.json(); + } + + /** + * Delete content cache with given name + */ + async delete(name: string): Promise { + const url = new FilesRequestUrl( + RpcTask.DELETE, + this.apiKey, + this._requestOptions, + ); + url.appendPath(name); + const uploadHeaders = getHeaders(url); + await makeServerRequest(url, uploadHeaders); + } +} diff --git a/packages/main/src/files/constants.ts b/packages/main/src/server/constants.ts similarity index 91% rename from packages/main/src/files/constants.ts rename to packages/main/src/server/constants.ts index d9f6857c..1c101b85 100644 --- a/packages/main/src/files/constants.ts +++ b/packages/main/src/server/constants.ts @@ -14,9 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export enum FilesTask { +export enum RpcTask { UPLOAD = "upload", LIST = "list", GET = "get", DELETE = "delete", + UPDATE = "update", + CREATE = "create" } diff --git a/packages/main/src/files/file-manager.test.ts b/packages/main/src/server/file-manager.test.ts similarity index 93% rename from packages/main/src/files/file-manager.test.ts rename to packages/main/src/server/file-manager.test.ts index 748f6743..b35b0636 100644 --- a/packages/main/src/files/file-manager.test.ts +++ b/packages/main/src/server/file-manager.test.ts @@ -20,7 +20,7 @@ import * as sinonChai from "sinon-chai"; import * as chaiAsPromised from "chai-as-promised"; import { restore, stub } from "sinon"; import * as request from "./request"; -import { FilesTask } from "./constants"; +import { RpcTask } from "./constants"; import { DEFAULT_API_VERSION } from "../requests/request"; import { FileMetadata } from "./types"; @@ -50,7 +50,7 @@ describe("GoogleAIFileManager", () => { mimeType: "image/png", }); expect(result.file.uri).to.equal(FAKE_URI); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.UPLOAD); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.UPLOAD); expect(makeRequestStub.args[0][0].toString()).to.include("/upload/"); expect(makeRequestStub.args[0][1]).to.be.instanceOf(Headers); expect(makeRequestStub.args[0][1].get("X-Goog-Upload-Protocol")).to.equal( @@ -108,7 +108,7 @@ describe("GoogleAIFileManager", () => { mimeType: "image/png", }); expect(result.file.uri).to.equal(FAKE_URI); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.UPLOAD); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.UPLOAD); expect(makeRequestStub.args[0][0].toString()).to.include("/upload/"); expect(makeRequestStub.args[0][1]).to.be.instanceOf(Headers); expect(makeRequestStub.args[0][1].get("X-Goog-Upload-Protocol")).to.equal( @@ -131,7 +131,7 @@ describe("GoogleAIFileManager", () => { const fileManager = new GoogleAIFileManager("apiKey"); const result = await fileManager.listFiles(); expect(result.files[0].uri).to.equal(FAKE_URI); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.LIST); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.LIST); expect(makeRequestStub.args[0][0].toString()).to.match(/\/files$/); }); it("passes listFiles request info with params", async () => { @@ -145,7 +145,7 @@ describe("GoogleAIFileManager", () => { pageToken: "abc", }); expect(result.files[0].uri).to.equal(FAKE_URI); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.LIST); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.LIST); expect(makeRequestStub.args[0][0].toString()).to.include("pageSize=3"); expect(makeRequestStub.args[0][0].toString()).to.include("pageToken=abc"); }); @@ -160,7 +160,7 @@ describe("GoogleAIFileManager", () => { }); const result = await fileManager.listFiles(); expect(result.files[0].uri).to.equal(FAKE_URI); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.LIST); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.LIST); expect(makeRequestStub.args[0][0].toString()).to.match(/\/files$/); expect(makeRequestStub.args[0][0].toString()).to.include("v3000/files"); expect(makeRequestStub.args[0][0].toString()).to.match( @@ -175,7 +175,7 @@ describe("GoogleAIFileManager", () => { const fileManager = new GoogleAIFileManager("apiKey"); const result = await fileManager.getFile("nameoffile"); expect(result.uri).to.equal(FAKE_URI); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.GET); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.GET); expect(makeRequestStub.args[0][0].toString()).to.include( `${DEFAULT_API_VERSION}/files/nameoffile`, ); @@ -187,7 +187,7 @@ describe("GoogleAIFileManager", () => { } as Response); const fileManager = new GoogleAIFileManager("apiKey"); await fileManager.getFile("files/nameoffile"); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.GET); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.GET); expect(makeRequestStub.args[0][0].toString()).to.include( `${DEFAULT_API_VERSION}/files/nameoffile`, ); @@ -203,7 +203,7 @@ describe("GoogleAIFileManager", () => { }); const result = await fileManager.getFile("nameoffile"); expect(result.uri).to.equal(FAKE_URI); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.GET); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.GET); expect(makeRequestStub.args[0][0].toString()).to.include("/nameoffile"); expect(makeRequestStub.args[0][0].toString()).to.include("v3000/files"); expect(makeRequestStub.args[0][0].toString()).to.match( @@ -225,7 +225,7 @@ describe("GoogleAIFileManager", () => { } as Response); const fileManager = new GoogleAIFileManager("apiKey"); await fileManager.deleteFile("nameoffile"); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.DELETE); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.DELETE); expect(makeRequestStub.args[0][0].toString()).to.include("/nameoffile"); }); it("passes deleteFile request info (with options)", async () => { @@ -238,7 +238,7 @@ describe("GoogleAIFileManager", () => { baseUrl: "http://mysite.com", }); await fileManager.deleteFile("nameoffile"); - expect(makeRequestStub.args[0][0].task).to.equal(FilesTask.DELETE); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.DELETE); expect(makeRequestStub.args[0][0].toString()).to.include("/nameoffile"); expect(makeRequestStub.args[0][0].toString()).to.include("v3000/files"); expect(makeRequestStub.args[0][0].toString()).to.match( diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/server/file-manager.ts similarity index 90% rename from packages/main/src/files/file-manager.ts rename to packages/main/src/server/file-manager.ts index 42f6b8c5..e3daf487 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/server/file-manager.ts @@ -17,7 +17,7 @@ import { RequestOptions } from "../../types"; import { readFileSync } from "fs"; -import { FilesRequestUrl, getHeaders, makeFilesRequest } from "./request"; +import { FilesRequestUrl, getHeaders, makeServerRequest } from "./request"; import { FileMetadata, FileMetadataResponse, @@ -25,7 +25,7 @@ import { ListParams, UploadFileResponse, } from "./types"; -import { FilesTask } from "./constants"; +import { RpcTask } from "./constants"; import { GoogleGenerativeAIError, GoogleGenerativeAIRequestInputError, @@ -56,7 +56,7 @@ export class GoogleAIFileManager { ): Promise { const file = readFileSync(filePath); const url = new FilesRequestUrl( - FilesTask.UPLOAD, + RpcTask.UPLOAD, this.apiKey, this._requestOptions, ); @@ -88,7 +88,7 @@ export class GoogleAIFileManager { const postBlobPart = "\r\n--" + boundary + "--"; const blob = new Blob([preBlobPart, file, postBlobPart]); - const response = await makeFilesRequest(url, uploadHeaders, blob); + const response = await makeServerRequest(url, uploadHeaders, blob); return response.json(); } @@ -97,7 +97,7 @@ export class GoogleAIFileManager { */ async listFiles(listParams?: ListParams): Promise { const url = new FilesRequestUrl( - FilesTask.LIST, + RpcTask.LIST, this.apiKey, this._requestOptions, ); @@ -108,7 +108,7 @@ export class GoogleAIFileManager { url.appendParam("pageToken", listParams.pageToken); } const uploadHeaders = getHeaders(url); - const response = await makeFilesRequest(url, uploadHeaders); + const response = await makeServerRequest(url, uploadHeaders); return response.json(); } @@ -117,13 +117,13 @@ export class GoogleAIFileManager { */ async getFile(fileId: string): Promise { const url = new FilesRequestUrl( - FilesTask.GET, + RpcTask.GET, this.apiKey, this._requestOptions, ); url.appendPath(parseFileId(fileId)); const uploadHeaders = getHeaders(url); - const response = await makeFilesRequest(url, uploadHeaders); + const response = await makeServerRequest(url, uploadHeaders); return response.json(); } @@ -132,13 +132,13 @@ export class GoogleAIFileManager { */ async deleteFile(fileId: string): Promise { const url = new FilesRequestUrl( - FilesTask.DELETE, + RpcTask.DELETE, this.apiKey, this._requestOptions, ); url.appendPath(parseFileId(fileId)); const uploadHeaders = getHeaders(url); - await makeFilesRequest(url, uploadHeaders); + await makeServerRequest(url, uploadHeaders); } } diff --git a/packages/main/src/files/index.ts b/packages/main/src/server/index.ts similarity index 100% rename from packages/main/src/files/index.ts rename to packages/main/src/server/index.ts diff --git a/packages/main/src/files/request.test.ts b/packages/main/src/server/request.test.ts similarity index 86% rename from packages/main/src/files/request.test.ts rename to packages/main/src/server/request.test.ts index ad92dda7..dd2c15d2 100644 --- a/packages/main/src/files/request.test.ts +++ b/packages/main/src/server/request.test.ts @@ -20,8 +20,8 @@ import { match, restore, stub } from "sinon"; import * as sinonChai from "sinon-chai"; import * as chaiAsPromised from "chai-as-promised"; import { DEFAULT_API_VERSION, DEFAULT_BASE_URL } from "../requests/request"; -import { FilesRequestUrl, makeFilesRequest } from "./request"; -import { FilesTask } from "./constants"; +import { FilesRequestUrl, makeServerRequest } from "./request"; +import { RpcTask } from "./constants"; import { GoogleGenerativeAIFetchError } from "../errors"; use(sinonChai); @@ -33,38 +33,38 @@ describe("Files API - request methods", () => { }); describe("FilesRequestUrl", () => { it("includes task, apiVersion, baseURL, upload if upload task", async () => { - const url = new FilesRequestUrl(FilesTask.UPLOAD, "key", {}); + const url = new FilesRequestUrl(RpcTask.UPLOAD, "key", {}); expect(url.toString()).to.include("/upload"); expect(url.toString()).to.not.include("key"); expect(url.toString()).to.include(DEFAULT_API_VERSION); expect(url.toString()).to.include(DEFAULT_BASE_URL); }); it("includes task, apiVersion, baseURL, no upload if non-upload task", async () => { - const url = new FilesRequestUrl(FilesTask.GET, "key", {}); + const url = new FilesRequestUrl(RpcTask.GET, "key", {}); expect(url.toString()).to.not.include("/upload"); expect(url.toString()).to.not.include("key"); expect(url.toString()).to.include(DEFAULT_API_VERSION); expect(url.toString()).to.include(DEFAULT_BASE_URL); }); it("gets custom apiVersion", async () => { - const url = new FilesRequestUrl(FilesTask.GET, "key", { + const url = new FilesRequestUrl(RpcTask.GET, "key", { apiVersion: "v2beta", }); expect(url.toString()).to.include("/v2beta/files"); }); it("custom baseUrl", async () => { - const url = new FilesRequestUrl(FilesTask.GET, "key", { + const url = new FilesRequestUrl(RpcTask.GET, "key", { baseUrl: "http://my.staging.website", }); expect(url.toString()).to.include("http://my.staging.website"); }); it("adds params", async () => { - const url = new FilesRequestUrl(FilesTask.GET, "key", {}); + const url = new FilesRequestUrl(RpcTask.GET, "key", {}); url.appendParam("param1", "value1"); expect(url.toString()).to.include("?param1=value1"); }); it("adds path segments", async () => { - const url = new FilesRequestUrl(FilesTask.GET, "key", {}); + const url = new FilesRequestUrl(RpcTask.GET, "key", {}); url.appendPath("newpath"); expect(url.toString()).to.match(/\/newpath$/); }); @@ -74,9 +74,9 @@ describe("Files API - request methods", () => { const fetchStub = stub().resolves({ ok: true, } as Response); - const url = new FilesRequestUrl(FilesTask.UPLOAD, "key"); + const url = new FilesRequestUrl(RpcTask.UPLOAD, "key"); const headers = new Headers(); - const response = await makeFilesRequest( + const response = await makeServerRequest( url, headers, new Blob(), @@ -96,10 +96,10 @@ describe("Files API - request methods", () => { statusText: "AbortError", } as Response); - const url = new FilesRequestUrl(FilesTask.GET, "key", { timeout: 0 }); + const url = new FilesRequestUrl(RpcTask.GET, "key", { timeout: 0 }); const headers = new Headers(); try { - await makeFilesRequest( + await makeServerRequest( url, headers, new Blob(), @@ -122,10 +122,10 @@ describe("Files API - request methods", () => { status: 500, statusText: "Server Error", } as Response); - const url = new FilesRequestUrl(FilesTask.GET, "key"); + const url = new FilesRequestUrl(RpcTask.GET, "key"); const headers = new Headers(); try { - await makeFilesRequest( + await makeServerRequest( url, headers, new Blob(), @@ -149,10 +149,10 @@ describe("Files API - request methods", () => { statusText: "Server Error", json: () => Promise.resolve({ error: { message: "extra info" } }), } as Response); - const url = new FilesRequestUrl(FilesTask.GET, "key"); + const url = new FilesRequestUrl(RpcTask.GET, "key"); const headers = new Headers(); try { - await makeFilesRequest( + await makeServerRequest( url, headers, new Blob(), @@ -188,10 +188,10 @@ describe("Files API - request methods", () => { }, }), } as Response); - const url = new FilesRequestUrl(FilesTask.GET, "key"); + const url = new FilesRequestUrl(RpcTask.GET, "key"); const headers = new Headers(); try { - await makeFilesRequest( + await makeServerRequest( url, headers, new Blob(), diff --git a/packages/main/src/files/request.ts b/packages/main/src/server/request.ts similarity index 61% rename from packages/main/src/files/request.ts rename to packages/main/src/server/request.ts index 489a1022..1c8a2339 100644 --- a/packages/main/src/files/request.ts +++ b/packages/main/src/server/request.ts @@ -15,42 +15,31 @@ * limitations under the License. */ -import { - GoogleGenerativeAIError, - GoogleGenerativeAIFetchError, -} from "../errors"; import { DEFAULT_API_VERSION, DEFAULT_BASE_URL, getClientHeaders, + makeRequest, } from "../requests/request"; import { RequestOptions } from "../../types"; -import { FilesTask } from "./constants"; +import { RpcTask } from "./constants"; const taskToMethod = { - [FilesTask.UPLOAD]: "POST", - [FilesTask.LIST]: "GET", - [FilesTask.GET]: "GET", - [FilesTask.DELETE]: "DELETE", + [RpcTask.UPLOAD]: "POST", + [RpcTask.LIST]: "GET", + [RpcTask.GET]: "GET", + [RpcTask.DELETE]: "DELETE", + [RpcTask.UPDATE]: "PATCH", + [RpcTask.CREATE]: "POST", }; -export class FilesRequestUrl { - private _url: URL; - +export class ServerRequestUrl { + protected _url: URL; constructor( - public task: FilesTask, + public task: RpcTask, public apiKey: string, public requestOptions?: RequestOptions, - ) { - const apiVersion = this.requestOptions?.apiVersion || DEFAULT_API_VERSION; - const baseUrl = this.requestOptions?.baseUrl || DEFAULT_BASE_URL; - let initialUrl = baseUrl; - if (this.task === FilesTask.UPLOAD) { - initialUrl += `/upload`; - } - initialUrl += `/${apiVersion}/files`; - this._url = new URL(initialUrl); - } + ) {} appendPath(path: string): void { this._url.pathname = this._url.pathname + `/${path}`; @@ -65,17 +54,50 @@ export class FilesRequestUrl { } } -export function getHeaders(url: FilesRequestUrl): Headers { +export class CachedContentUrl extends ServerRequestUrl { + constructor( + public task: RpcTask, + public apiKey: string, + public requestOptions?: RequestOptions, + ) { + super(task, apiKey, requestOptions); + const apiVersion = this.requestOptions?.apiVersion || DEFAULT_API_VERSION; + const baseUrl = this.requestOptions?.baseUrl || DEFAULT_BASE_URL; + let initialUrl = baseUrl; + initialUrl += `/${apiVersion}/cachedContents`; + this._url = new URL(initialUrl); + } +} + +export class FilesRequestUrl extends ServerRequestUrl { + constructor( + public task: RpcTask, + public apiKey: string, + public requestOptions?: RequestOptions, + ) { + super(task, apiKey, requestOptions); + const apiVersion = this.requestOptions?.apiVersion || DEFAULT_API_VERSION; + const baseUrl = this.requestOptions?.baseUrl || DEFAULT_BASE_URL; + let initialUrl = baseUrl; + if (this.task === RpcTask.UPLOAD) { + initialUrl += `/upload`; + } + initialUrl += `/${apiVersion}/files`; + this._url = new URL(initialUrl); + } +} + +export function getHeaders(url: ServerRequestUrl): Headers { const headers = new Headers(); headers.append("x-goog-api-client", getClientHeaders(url.requestOptions)); headers.append("x-goog-api-key", url.apiKey); return headers; } -export async function makeFilesRequest( +export async function makeServerRequest( url: FilesRequestUrl, headers: Headers, - body?: Blob, + body?: Blob | string, fetchFn: typeof fetch = fetch, ): Promise { const requestInit: RequestInit = { @@ -92,42 +114,7 @@ export async function makeFilesRequest( requestInit.signal = signal; } - try { - const response = await fetchFn(url.toString(), requestInit); - if (!response.ok) { - let message = ""; - let errorDetails; - try { - const json = await response.json(); - message = json.error.message; - if (json.error.details) { - message += ` ${JSON.stringify(json.error.details)}`; - errorDetails = json.error.details; - } - } catch (e) { - // ignored - } - throw new GoogleGenerativeAIFetchError( - `Error fetching from ${url.toString()}: [${response.status} ${ - response.statusText - }] ${message}`, - response.status, - response.statusText, - errorDetails, - ); - } else { - return response; - } - } catch (e) { - let err = e; - if (!(e instanceof GoogleGenerativeAIFetchError)) { - err = new GoogleGenerativeAIError( - `Error fetching from ${url.toString()}: ${e.message}`, - ); - err.stack = e.stack; - } - throw err; - } + return makeRequest(url.toString(), requestInit, fetchFn); } /** diff --git a/packages/main/src/server/types/caching.ts b/packages/main/src/server/types/caching.ts new file mode 100644 index 00000000..4c943560 --- /dev/null +++ b/packages/main/src/server/types/caching.ts @@ -0,0 +1,62 @@ +/** + * @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. + */ + +import { Content, Part, Tool, ToolConfig } from "../../../types"; + +export interface CachedContentBase { + model?: string; + contents: Content[]; + tools?: Tool[]; + toolConfig?: ToolConfig; + systemInstruction?: string | Part | Content; +} + +/** + * Params to pass to {@link CacheManager.create} + */ +export interface CachedContentCreateParams extends CachedContentBase { + // sent field needs to be protobuf Duration ("3.0001s") + ttlSeconds?: number; +} + +/** + * Params to pass to {@link CacheManager.update} + */ +export interface CachedContentUpdateParams { + cachedContent: CachedContentCreateParams; + /** + * protobuf FieldMask + */ + updateMask: string[]; +} + +/** + * Describes CachedContent interface for sending to the server (if creating) + * or received from the server (using getters or list methods). + */ +export interface CachedContent extends CachedContentBase { + ttl?: string; + // ISO string + createTime?: string; + // ISO string + updateTime?: string; +} + +export interface ListCacheResponse { + cachedContents: CachedContent[]; + nextPageToken?: string; +} \ No newline at end of file diff --git a/packages/main/src/files/types.ts b/packages/main/src/server/types/files.ts similarity index 81% rename from packages/main/src/files/types.ts rename to packages/main/src/server/types/files.ts index a7ff2c4e..d2fa5323 100644 --- a/packages/main/src/files/types.ts +++ b/packages/main/src/server/types/files.ts @@ -14,19 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import { ErrorDetails } from "../../types"; - -export { ErrorDetails }; - -/** - * Params to pass to {@link GoogleAIFileManager.listFiles} - * @public - */ -export interface ListParams { - pageSize?: number; - pageToken?: string; -} +import { RpcStatus } from "./shared"; /** * Metadata to provide alongside a file upload @@ -95,25 +83,6 @@ export enum FileState { FAILED = "FAILED", } -/** - * Standard RPC error status object. - * @public - */ -export interface RpcStatus { - /** - * Error status code - */ - code: number; - /** - * A developer-facing error message. - */ - message: string; - /** - * A list of messages that carry the error details. - */ - details?: ErrorDetails[]; -} - /** * Metadata populated when video has been processed. * @public diff --git a/packages/main/src/server/types/index.ts b/packages/main/src/server/types/index.ts new file mode 100644 index 00000000..c9a84036 --- /dev/null +++ b/packages/main/src/server/types/index.ts @@ -0,0 +1,20 @@ +/** + * @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. + */ + +export * from './files'; +export * from './caching'; +export * from './shared'; diff --git a/packages/main/src/server/types/shared.ts b/packages/main/src/server/types/shared.ts new file mode 100644 index 00000000..0a229473 --- /dev/null +++ b/packages/main/src/server/types/shared.ts @@ -0,0 +1,49 @@ +/** + * @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. + */ + +import { ErrorDetails } from "../../../types"; + +export { ErrorDetails }; + +/** + * Standard RPC error status object. + * @public + */ +export interface RpcStatus { + /** + * Error status code + */ + code: number; + /** + * A developer-facing error message. + */ + message: string; + /** + * A list of messages that carry the error details. + */ + details?: ErrorDetails[]; +} + +/** + * Params to pass to {@link GoogleAIFileManager.listFiles} or + * {@link CacheManager.list} + * @public + */ +export interface ListParams { + pageSize?: number; + pageToken?: string; +} \ No newline at end of file From 5feec5fb18084ef6b0aadf47ced721a2e552d1bf Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 5 Jun 2024 14:39:55 -0700 Subject: [PATCH 02/14] add cachedContent to model --- packages/main/src/gen-ai.ts | 18 ++++++++++++++++++ packages/main/src/methods/chat-session.ts | 2 ++ packages/main/src/models/generative-model.ts | 6 ++++++ packages/main/src/requests/request.ts | 1 + packages/main/types/requests.ts | 4 ++++ 5 files changed, 31 insertions(+) diff --git a/packages/main/src/gen-ai.ts b/packages/main/src/gen-ai.ts index f6c9f865..a3c2bce4 100644 --- a/packages/main/src/gen-ai.ts +++ b/packages/main/src/gen-ai.ts @@ -18,6 +18,7 @@ import { GoogleGenerativeAIError } from "./errors"; import { ModelParams, RequestOptions } from "../types"; import { GenerativeModel } from "./models/generative-model"; +import { CachedContent } from "./server"; export { ChatSession } from "./methods/chat-session"; export { GenerativeModel }; @@ -44,4 +45,21 @@ export class GoogleGenerativeAI { } return new GenerativeModel(this.apiKey, modelParams, requestOptions); } + + /** + * Creates a {@link GenerativeModel} instance from provided content cache. + */ + getGenerativeModelFromCachedContent( + cachedContent: CachedContent, + requestOptions?: RequestOptions, + ): GenerativeModel { + const modelParams: ModelParams = { + model: cachedContent.model, + tools: cachedContent.tools, + toolConfig: cachedContent.toolConfig, + systemInstruction: cachedContent.systemInstruction, + cachedContent + }; + return new GenerativeModel(this.apiKey, modelParams, requestOptions); + } } diff --git a/packages/main/src/methods/chat-session.ts b/packages/main/src/methods/chat-session.ts index 9b6e3335..fd469bfe 100644 --- a/packages/main/src/methods/chat-session.ts +++ b/packages/main/src/methods/chat-session.ts @@ -83,6 +83,7 @@ export class ChatSession { tools: this.params?.tools, toolConfig: this.params?.toolConfig, systemInstruction: this.params?.systemInstruction, + cachedContent: this.params?.cachedContent, contents: [...this._history, newContent], }; let finalResult; @@ -139,6 +140,7 @@ export class ChatSession { tools: this.params?.tools, toolConfig: this.params?.toolConfig, systemInstruction: this.params?.systemInstruction, + cachedContent: this.params?.cachedContent, contents: [...this._history, newContent], }; const streamPromise = generateContentStream( diff --git a/packages/main/src/models/generative-model.ts b/packages/main/src/models/generative-model.ts index 4bc2c63e..8f8d85d4 100644 --- a/packages/main/src/models/generative-model.ts +++ b/packages/main/src/models/generative-model.ts @@ -48,6 +48,7 @@ import { formatGenerateContentInput, formatSystemInstruction, } from "../requests/request-helpers"; +import { CachedContent } from "../server"; /** * Class for generative model APIs. @@ -61,6 +62,7 @@ export class GenerativeModel { tools?: Tool[]; toolConfig?: ToolConfig; systemInstruction?: Content; + cachedContent: CachedContent; constructor( public apiKey: string, @@ -81,6 +83,7 @@ export class GenerativeModel { this.systemInstruction = formatSystemInstruction( modelParams.systemInstruction, ); + this.cachedContent = modelParams.cachedContent; this.requestOptions = requestOptions || {}; } @@ -101,6 +104,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, + cachedContent: this.cachedContent, ...formattedParams, }, this.requestOptions, @@ -126,6 +130,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, + cachedContent: this.cachedContent, ...formattedParams, }, this.requestOptions, @@ -146,6 +151,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, + cachedContent: this.cachedContent, ...startChatParams, }, this.requestOptions, diff --git a/packages/main/src/requests/request.ts b/packages/main/src/requests/request.ts index 3c0072f8..f7d09394 100644 --- a/packages/main/src/requests/request.ts +++ b/packages/main/src/requests/request.ts @@ -227,3 +227,4 @@ function buildFetchOptions(requestOptions?: RequestOptions): RequestInit { } return fetchOptions; } + diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index d46657c6..7dec6cda 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { CachedContent } from "../src/server"; import { Content, Part } from "./content"; import { FunctionCallingMode, @@ -41,6 +42,7 @@ export interface ModelParams extends BaseParams { tools?: Tool[]; toolConfig?: ToolConfig; systemInstruction?: string | Part | Content; + cachedContent?: CachedContent; } /** @@ -52,6 +54,7 @@ export interface GenerateContentRequest extends BaseParams { tools?: Tool[]; toolConfig?: ToolConfig; systemInstruction?: string | Part | Content; + cachedContent?: CachedContent; } /** @@ -106,6 +109,7 @@ export interface StartChatParams extends BaseParams { tools?: Tool[]; toolConfig?: ToolConfig; systemInstruction?: string | Part | Content; + cachedContent?: CachedContent; } /** From 9a8f6e6f2792fa5385f9472a2a6d09e4439a2a8d Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 5 Jun 2024 16:55:28 -0700 Subject: [PATCH 03/14] fix types/build --- common/api-review/generative-ai-server.api.md | 378 ++++++++++ common/api-review/generative-ai.api.md | 648 ++++++++++++++++++ config/api-extractor.json | 2 +- packages/main/api-extractor.json | 3 + packages/main/api-extractor.server.json | 3 + packages/main/package.json | 18 +- packages/main/rollup.config.mjs | 12 +- packages/main/src/gen-ai.ts | 3 +- packages/main/src/models/generative-model.ts | 2 +- packages/main/src/server/cache-manager.ts | 8 +- packages/main/src/server/file-manager.test.ts | 2 +- packages/main/src/server/file-manager.ts | 2 +- packages/main/src/server/index.ts | 5 +- packages/main/types/cached-content.ts | 26 + packages/main/types/content.ts | 2 + packages/main/types/function-calling.ts | 163 +++++ packages/main/types/index.ts | 1 + packages/main/types/requests.ts | 166 +---- .../server/types => types/server}/caching.ts | 27 +- .../server/types => types/server}/files.ts | 0 .../server/types => types/server}/index.ts | 4 + .../server/types => types/server}/shared.ts | 4 +- 22 files changed, 1265 insertions(+), 214 deletions(-) create mode 100644 common/api-review/generative-ai-server.api.md create mode 100644 common/api-review/generative-ai.api.md create mode 100644 packages/main/types/cached-content.ts create mode 100644 packages/main/types/function-calling.ts rename packages/main/{src/server/types => types/server}/caching.ts (62%) rename packages/main/{src/server/types => types/server}/files.ts (100%) rename packages/main/{src/server/types => types/server}/index.ts (83%) rename packages/main/{src/server/types => types/server}/shared.ts (93%) diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md new file mode 100644 index 00000000..3ed6fdcf --- /dev/null +++ b/common/api-review/generative-ai-server.api.md @@ -0,0 +1,378 @@ +## API Report File for "@google/generative-ai" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +// @public +export interface CachedContent extends CachedContentBase { + // (undocumented) + createTime?: string; + // (undocumented) + ttl?: string; + // (undocumented) + updateTime?: string; +} + +// @public (undocumented) +export interface CachedContentBase { + // (undocumented) + contents: Content[]; + // (undocumented) + model?: string; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export interface CachedContentCreateParams extends CachedContentBase { + // (undocumented) + ttlSeconds?: number; +} + +// @public +export interface CachedContentUpdateParams { + // (undocumented) + cachedContent: CachedContentCreateParams; + updateMask: string[]; +} + +// @public +export interface Content { + // (undocumented) + parts: Part[]; + // (undocumented) + role: string; +} + +// @public +export interface ErrorDetails { + // (undocumented) + "@type"?: string; + // (undocumented) + [key: string]: unknown; + // (undocumented) + domain?: string; + // (undocumented) + metadata?: Record; + // (undocumented) + reason?: string; +} + +// @public +export interface FileData { + // (undocumented) + fileUri: string; + // (undocumented) + mimeType: string; +} + +// @public +export interface FileDataPart { + // (undocumented) + fileData: FileData; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export interface FileMetadata { + // (undocumented) + displayName?: string; + // (undocumented) + mimeType: string; + // (undocumented) + name?: string; +} + +// @public +export interface FileMetadataResponse { + // (undocumented) + createTime: string; + // (undocumented) + displayName?: string; + error?: RpcStatus; + // (undocumented) + expirationTime: string; + // (undocumented) + mimeType: string; + // (undocumented) + name: string; + // (undocumented) + sha256Hash: string; + // (undocumented) + sizeBytes: string; + // (undocumented) + state: FileState; + // (undocumented) + updateTime: string; + // (undocumented) + uri: string; + videoMetadata?: VideoMetadata; +} + +// @public +export enum FileState { + // (undocumented) + ACTIVE = "ACTIVE", + // (undocumented) + FAILED = "FAILED", + // (undocumented) + PROCESSING = "PROCESSING", + // (undocumented) + STATE_UNSPECIFIED = "STATE_UNSPECIFIED" +} + +// @public +export interface FunctionCall { + // (undocumented) + args: object; + // (undocumented) + name: string; +} + +// @public (undocumented) +export interface FunctionCallingConfig { + // (undocumented) + allowedFunctionNames?: string[]; + // Warning: (ae-forgotten-export) The symbol "FunctionCallingMode" needs to be exported by the entry point index.d.ts + // + // (undocumented) + mode?: FunctionCallingMode; +} + +// @public +export interface FunctionCallPart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall: FunctionCall; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export interface FunctionDeclaration { + description?: string; + name: string; + parameters?: FunctionDeclarationSchema; +} + +// @public +export interface FunctionDeclarationSchema { + description?: string; + properties: { + [k: string]: FunctionDeclarationSchemaProperty; + }; + required?: string[]; + type: FunctionDeclarationSchemaType; +} + +// @public +export interface FunctionDeclarationSchemaProperty extends Schema { +} + +// @public +export enum FunctionDeclarationSchemaType { + ARRAY = "ARRAY", + BOOLEAN = "BOOLEAN", + INTEGER = "INTEGER", + NUMBER = "NUMBER", + OBJECT = "OBJECT", + STRING = "STRING" +} + +// @public +export interface FunctionDeclarationsTool { + functionDeclarations?: FunctionDeclaration[]; +} + +// @public +export interface FunctionResponse { + // (undocumented) + name: string; + // (undocumented) + response: object; +} + +// @public +export interface FunctionResponsePart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse: FunctionResponse; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export interface GenerativeContentBlob { + data: string; + // (undocumented) + mimeType: string; +} + +// @public +export class GoogleAICacheManager { + constructor(apiKey: string, _requestOptions: RequestOptions); + // (undocumented) + apiKey: string; + create(createOptions: CachedContentCreateParams): Promise; + delete(name: string): Promise; + get(name: string): Promise; + list(listParams?: ListParams): Promise; + // (undocumented) + model: string; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; + // (undocumented) + ttl?: string; + update(name: string, updateParams: CachedContentUpdateParams): Promise; +} + +// @public +export class GoogleAIFileManager { + constructor(apiKey: string, _requestOptions?: RequestOptions); + // (undocumented) + apiKey: string; + deleteFile(fileId: string): Promise; + getFile(fileId: string): Promise; + listFiles(listParams?: ListParams): Promise; + uploadFile(filePath: string, fileMetadata: FileMetadata): Promise; +} + +// @public +export interface InlineDataPart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData: GenerativeContentBlob; + // (undocumented) + text?: never; +} + +// @public (undocumented) +export interface ListCacheResponse { + // (undocumented) + cachedContents: CachedContent[]; + // (undocumented) + nextPageToken?: string; +} + +// @public +export interface ListFilesResponse { + // (undocumented) + files: FileMetadataResponse[]; + // (undocumented) + nextPageToken?: string; +} + +// @public +export interface ListParams { + // (undocumented) + pageSize?: number; + // (undocumented) + pageToken?: string; +} + +// @public +export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; + +// @public +export interface RequestOptions { + apiClient?: string; + apiVersion?: string; + baseUrl?: string; + customHeaders?: Headers | Record; + timeout?: number; +} + +// @public +export interface ResponseSchema extends Schema { +} + +// @public +export interface RpcStatus { + code: number; + details?: ErrorDetails[]; + message: string; +} + +// @public +export interface Schema { + description?: string; + enum?: string[]; + example?: unknown; + format?: string; + items?: FunctionDeclarationSchema; + nullable?: boolean; + properties?: { + [k: string]: FunctionDeclarationSchema; + }; + required?: string[]; + type?: FunctionDeclarationSchemaType; +} + +// @public +export interface TextPart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text: string; +} + +// @public +export type Tool = FunctionDeclarationsTool; + +// @public +export interface ToolConfig { + // (undocumented) + functionCallingConfig: FunctionCallingConfig; +} + +// @public +export interface UploadFileResponse { + // (undocumented) + file: FileMetadataResponse; +} + +// @public +export interface VideoMetadata { + videoDuration: string; +} + +// (No @packageDocumentation comment for this package) + +``` diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md new file mode 100644 index 00000000..60999238 --- /dev/null +++ b/common/api-review/generative-ai.api.md @@ -0,0 +1,648 @@ +## API Report File for "@google/generative-ai" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +// @public +export interface BaseParams { + // (undocumented) + generationConfig?: GenerationConfig; + // (undocumented) + safetySettings?: SafetySetting[]; +} + +// @public +export interface BatchEmbedContentsRequest { + // (undocumented) + requests: EmbedContentRequest[]; +} + +// @public +export interface BatchEmbedContentsResponse { + // (undocumented) + embeddings: ContentEmbedding[]; +} + +// @public +export enum BlockReason { + // (undocumented) + BLOCKED_REASON_UNSPECIFIED = "BLOCKED_REASON_UNSPECIFIED", + // (undocumented) + OTHER = "OTHER", + // (undocumented) + SAFETY = "SAFETY" +} + +// @public +export interface CachedContent extends CachedContentBase { + // (undocumented) + createTime?: string; + // (undocumented) + ttl?: string; + // (undocumented) + updateTime?: string; +} + +// @public (undocumented) +export interface CachedContentBase { + // (undocumented) + contents: Content[]; + // (undocumented) + model?: string; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export class ChatSession { + constructor(apiKey: string, model: string, params?: StartChatParams, requestOptions?: RequestOptions); + getHistory(): Promise; + // (undocumented) + model: string; + // (undocumented) + params?: StartChatParams; + // (undocumented) + requestOptions?: RequestOptions; + sendMessage(request: string | Array): Promise; + sendMessageStream(request: string | Array): Promise; +} + +// @public +export interface CitationMetadata { + // (undocumented) + citationSources: CitationSource[]; +} + +// @public +export interface CitationSource { + // (undocumented) + endIndex?: number; + // (undocumented) + license?: string; + // (undocumented) + startIndex?: number; + // (undocumented) + uri?: string; +} + +// @public +export interface Content { + // (undocumented) + parts: Part[]; + // (undocumented) + role: string; +} + +// @public +export interface ContentEmbedding { + // (undocumented) + values: number[]; +} + +// @public +export interface CountTokensRequest { + // (undocumented) + contents?: Content[]; + // (undocumented) + generateContentRequest?: GenerateContentRequest; +} + +// Warning: (ae-internal-missing-underscore) The name "CountTokensRequestInternal" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal +export interface CountTokensRequestInternal { + // (undocumented) + contents?: Content[]; + // (undocumented) + generateContentRequest?: GenerateContentRequestInternal; +} + +// @public +export interface CountTokensResponse { + // (undocumented) + totalTokens: number; +} + +// @public +export interface EmbedContentRequest { + // (undocumented) + content: Content; + // (undocumented) + taskType?: TaskType; + // (undocumented) + title?: string; +} + +// @public +export interface EmbedContentResponse { + // (undocumented) + embedding: ContentEmbedding; +} + +// @public +export interface EnhancedGenerateContentResponse extends GenerateContentResponse { + // @deprecated + functionCall: () => FunctionCall | undefined; + functionCalls: () => FunctionCall[] | undefined; + text: () => string; +} + +// @public +export interface ErrorDetails { + // (undocumented) + "@type"?: string; + // (undocumented) + [key: string]: unknown; + // (undocumented) + domain?: string; + // (undocumented) + metadata?: Record; + // (undocumented) + reason?: string; +} + +// @public +export interface FileData { + // (undocumented) + fileUri: string; + // (undocumented) + mimeType: string; +} + +// @public +export interface FileDataPart { + // (undocumented) + fileData: FileData; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export enum FinishReason { + // (undocumented) + FINISH_REASON_UNSPECIFIED = "FINISH_REASON_UNSPECIFIED", + // (undocumented) + MAX_TOKENS = "MAX_TOKENS", + // (undocumented) + OTHER = "OTHER", + // (undocumented) + RECITATION = "RECITATION", + // (undocumented) + SAFETY = "SAFETY", + // (undocumented) + STOP = "STOP" +} + +// @public +export interface FunctionCall { + // (undocumented) + args: object; + // (undocumented) + name: string; +} + +// @public (undocumented) +export interface FunctionCallingConfig { + // (undocumented) + allowedFunctionNames?: string[]; + // (undocumented) + mode?: FunctionCallingMode; +} + +// @public (undocumented) +export enum FunctionCallingMode { + // (undocumented) + ANY = "ANY", + // (undocumented) + AUTO = "AUTO", + // (undocumented) + MODE_UNSPECIFIED = "MODE_UNSPECIFIED", + // (undocumented) + NONE = "NONE" +} + +// @public +export interface FunctionCallPart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall: FunctionCall; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export interface FunctionDeclaration { + description?: string; + name: string; + parameters?: FunctionDeclarationSchema; +} + +// @public +export interface FunctionDeclarationSchema { + description?: string; + properties: { + [k: string]: FunctionDeclarationSchemaProperty; + }; + required?: string[]; + type: FunctionDeclarationSchemaType; +} + +// @public +export interface FunctionDeclarationSchemaProperty extends Schema { +} + +// @public +export enum FunctionDeclarationSchemaType { + ARRAY = "ARRAY", + BOOLEAN = "BOOLEAN", + INTEGER = "INTEGER", + NUMBER = "NUMBER", + OBJECT = "OBJECT", + STRING = "STRING" +} + +// @public +export interface FunctionDeclarationsTool { + functionDeclarations?: FunctionDeclaration[]; +} + +// @public +export interface FunctionResponse { + // (undocumented) + name: string; + // (undocumented) + response: object; +} + +// @public +export interface FunctionResponsePart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse: FunctionResponse; + // (undocumented) + inlineData?: never; + // (undocumented) + text?: never; +} + +// @public +export interface GenerateContentCandidate { + // (undocumented) + citationMetadata?: CitationMetadata; + // (undocumented) + content: Content; + // (undocumented) + finishMessage?: string; + // (undocumented) + finishReason?: FinishReason; + // (undocumented) + index: number; + // (undocumented) + safetyRatings?: SafetyRating[]; +} + +// @public +export interface GenerateContentRequest extends BaseParams { + // (undocumented) + cachedContent?: CachedContent; + // (undocumented) + contents: Content[]; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// Warning: (ae-internal-missing-underscore) The name "GenerateContentRequestInternal" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal +export interface GenerateContentRequestInternal extends GenerateContentRequest { + // (undocumented) + model?: string; +} + +// @public +export interface GenerateContentResponse { + candidates?: GenerateContentCandidate[]; + promptFeedback?: PromptFeedback; + usageMetadata?: UsageMetadata; +} + +// @public +export interface GenerateContentResult { + // (undocumented) + response: EnhancedGenerateContentResponse; +} + +// @public +export interface GenerateContentStreamResult { + // (undocumented) + response: Promise; + // (undocumented) + stream: AsyncGenerator; +} + +// @public +export interface GenerationConfig { + // (undocumented) + candidateCount?: number; + // (undocumented) + maxOutputTokens?: number; + responseMimeType?: string; + responseSchema?: ResponseSchema; + // (undocumented) + stopSequences?: string[]; + // (undocumented) + temperature?: number; + // (undocumented) + topK?: number; + // (undocumented) + topP?: number; +} + +// @public +export interface GenerativeContentBlob { + data: string; + // (undocumented) + mimeType: string; +} + +// @public +export class GenerativeModel { + constructor(apiKey: string, modelParams: ModelParams, requestOptions?: RequestOptions); + // (undocumented) + apiKey: string; + batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest): Promise; + // (undocumented) + cachedContent: CachedContent; + countTokens(request: CountTokensRequest | string | Array): Promise; + embedContent(request: EmbedContentRequest | string | Array): Promise; + generateContent(request: GenerateContentRequest | string | Array): Promise; + generateContentStream(request: GenerateContentRequest | string | Array): Promise; + // (undocumented) + generationConfig: GenerationConfig; + // (undocumented) + model: string; + // (undocumented) + requestOptions: RequestOptions; + // (undocumented) + safetySettings: SafetySetting[]; + startChat(startChatParams?: StartChatParams): ChatSession; + // (undocumented) + systemInstruction?: Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export class GoogleGenerativeAI { + constructor(apiKey: string); + // (undocumented) + apiKey: string; + getGenerativeModel(modelParams: ModelParams, requestOptions?: RequestOptions): GenerativeModel; + getGenerativeModelFromCachedContent(cachedContent: CachedContent, requestOptions?: RequestOptions): GenerativeModel; +} + +// @public +export class GoogleGenerativeAIError extends Error { + constructor(message: string); +} + +// @public +export class GoogleGenerativeAIFetchError extends GoogleGenerativeAIError { + constructor(message: string, status?: number, statusText?: string, errorDetails?: ErrorDetails[]); + // (undocumented) + errorDetails?: ErrorDetails[]; + // (undocumented) + status?: number; + // (undocumented) + statusText?: string; +} + +// @public +export class GoogleGenerativeAIRequestInputError extends GoogleGenerativeAIError { +} + +// @public +export class GoogleGenerativeAIResponseError extends GoogleGenerativeAIError { + constructor(message: string, response?: T); + // (undocumented) + response?: T; +} + +// @public +export enum HarmBlockThreshold { + // (undocumented) + BLOCK_LOW_AND_ABOVE = "BLOCK_LOW_AND_ABOVE", + // (undocumented) + BLOCK_MEDIUM_AND_ABOVE = "BLOCK_MEDIUM_AND_ABOVE", + // (undocumented) + BLOCK_NONE = "BLOCK_NONE", + // (undocumented) + BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH", + // (undocumented) + HARM_BLOCK_THRESHOLD_UNSPECIFIED = "HARM_BLOCK_THRESHOLD_UNSPECIFIED" +} + +// @public +export enum HarmCategory { + // (undocumented) + HARM_CATEGORY_DANGEROUS_CONTENT = "HARM_CATEGORY_DANGEROUS_CONTENT", + // (undocumented) + HARM_CATEGORY_HARASSMENT = "HARM_CATEGORY_HARASSMENT", + // (undocumented) + HARM_CATEGORY_HATE_SPEECH = "HARM_CATEGORY_HATE_SPEECH", + // (undocumented) + HARM_CATEGORY_SEXUALLY_EXPLICIT = "HARM_CATEGORY_SEXUALLY_EXPLICIT", + // (undocumented) + HARM_CATEGORY_UNSPECIFIED = "HARM_CATEGORY_UNSPECIFIED" +} + +// @public +export enum HarmProbability { + // (undocumented) + HARM_PROBABILITY_UNSPECIFIED = "HARM_PROBABILITY_UNSPECIFIED", + // (undocumented) + HIGH = "HIGH", + // (undocumented) + LOW = "LOW", + // (undocumented) + MEDIUM = "MEDIUM", + // (undocumented) + NEGLIGIBLE = "NEGLIGIBLE" +} + +// @public +export interface InlineDataPart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData: GenerativeContentBlob; + // (undocumented) + text?: never; +} + +// @public +export interface ModelParams extends BaseParams { + // (undocumented) + cachedContent?: CachedContent; + // (undocumented) + model: string; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; + +// @public +export const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"]; + +// @public +export interface PromptFeedback { + // (undocumented) + blockReason: BlockReason; + // (undocumented) + blockReasonMessage?: string; + // (undocumented) + safetyRatings: SafetyRating[]; +} + +// @public +export interface RequestOptions { + apiClient?: string; + apiVersion?: string; + baseUrl?: string; + customHeaders?: Headers | Record; + timeout?: number; +} + +// @public +export interface ResponseSchema extends Schema { +} + +// @public +export interface SafetyRating { + // (undocumented) + category: HarmCategory; + // (undocumented) + probability: HarmProbability; +} + +// @public +export interface SafetySetting { + // (undocumented) + category: HarmCategory; + // (undocumented) + threshold: HarmBlockThreshold; +} + +// @public +export interface Schema { + description?: string; + enum?: string[]; + example?: unknown; + format?: string; + items?: FunctionDeclarationSchema; + nullable?: boolean; + properties?: { + [k: string]: FunctionDeclarationSchema; + }; + required?: string[]; + type?: FunctionDeclarationSchemaType; +} + +// @public +export interface StartChatParams extends BaseParams { + // (undocumented) + cachedContent?: CachedContent; + // (undocumented) + history?: Content[]; + // (undocumented) + systemInstruction?: string | Part | Content; + // (undocumented) + toolConfig?: ToolConfig; + // (undocumented) + tools?: Tool[]; +} + +// @public +export enum TaskType { + // (undocumented) + CLASSIFICATION = "CLASSIFICATION", + // (undocumented) + CLUSTERING = "CLUSTERING", + // (undocumented) + RETRIEVAL_DOCUMENT = "RETRIEVAL_DOCUMENT", + // (undocumented) + RETRIEVAL_QUERY = "RETRIEVAL_QUERY", + // (undocumented) + SEMANTIC_SIMILARITY = "SEMANTIC_SIMILARITY", + // (undocumented) + TASK_TYPE_UNSPECIFIED = "TASK_TYPE_UNSPECIFIED" +} + +// @public +export interface TextPart { + // (undocumented) + fileData?: never; + // (undocumented) + functionCall?: never; + // (undocumented) + functionResponse?: never; + // (undocumented) + inlineData?: never; + // (undocumented) + text: string; +} + +// @public +export type Tool = FunctionDeclarationsTool; + +// @public +export interface ToolConfig { + // (undocumented) + functionCallingConfig: FunctionCallingConfig; +} + +// @public +export interface UsageMetadata { + candidatesTokenCount: number; + promptTokenCount: number; + totalTokenCount: number; +} + +// (No @packageDocumentation comment for this package) + +``` diff --git a/config/api-extractor.json b/config/api-extractor.json index 5a60a26f..846d0bc6 100644 --- a/config/api-extractor.json +++ b/config/api-extractor.json @@ -110,7 +110,7 @@ /** * (REQUIRED) Whether to generate an API report. */ - "enabled": false, + "enabled": true, /** * The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce diff --git a/packages/main/api-extractor.json b/packages/main/api-extractor.json index f7546e09..3499b2e1 100644 --- a/packages/main/api-extractor.json +++ b/packages/main/api-extractor.json @@ -1,6 +1,9 @@ { "extends": "../../config/api-extractor.json", "mainEntryPointFilePath": "/dist/src/index.d.ts", + "apiReport": { + "reportFileName": ".api.md" + }, "dtsRollup": { "enabled": true, "untrimmedFilePath": "/dist/.d.ts" diff --git a/packages/main/api-extractor.server.json b/packages/main/api-extractor.server.json index e1cd2777..f226c528 100644 --- a/packages/main/api-extractor.server.json +++ b/packages/main/api-extractor.server.json @@ -1,6 +1,9 @@ { "extends": "../../config/api-extractor.json", "mainEntryPointFilePath": "/dist/src/server/index.d.ts", + "apiReport": { + "reportFileName": "-server.api.md" + }, "dtsRollup": { "enabled": true, "untrimmedFilePath": "/dist/server/server.d.ts" diff --git a/packages/main/package.json b/packages/main/package.json index 2fbabf62..325e01eb 100644 --- a/packages/main/package.json +++ b/packages/main/package.json @@ -12,20 +12,20 @@ "import": "./dist/index.mjs", "default": "./dist/index.js" }, - "./files": { - "types": "./dist/files/files.d.ts", - "require": "./dist/files/index.js", - "import": "./dist/files/index.mjs", - "default": "./dist/files/index.js" + "./server": { + "types": "./dist/server/server.d.ts", + "require": "./dist/server/index.js", + "import": "./dist/server/index.mjs", + "default": "./dist/server/index.js" }, "./package.json": "./package.json" }, "engines": { "node": ">=18.0.0" }, - "files": [ + "server": [ "dist", - "files/package.json" + "server/package.json" ], "scripts": { "build": "rollup -c && yarn api-report", @@ -34,8 +34,8 @@ "test:node:unit": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha \"src/**/*.test.ts\"", "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.files.json --local --verbose", - "docs": "yarn build && yarn api-documenter markdown -i ./temp/main -o ../../docs/reference/main && yarn api-documenter markdown -i ./temp/files -o ../../docs/reference/files" + "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" }, "repository": { "type": "git", diff --git a/packages/main/rollup.config.mjs b/packages/main/rollup.config.mjs index 4daae413..d309351f 100644 --- a/packages/main/rollup.config.mjs +++ b/packages/main/rollup.config.mjs @@ -61,19 +61,19 @@ const cjsBuilds = [ }, ]; -const filesBuilds = [ +const serverBuilds = [ { - input: "src/files/index.ts", + input: "src/server/index.ts", output: [ - { file: pkg.exports["./files"].import, format: "es", sourcemap: true }, + { file: pkg.exports["./server"].import, format: "es", sourcemap: true }, ], external: ["fs"], plugins: [...es2017BuildPlugins], }, { - input: "src/files/index.ts", + input: "src/server/index.ts", output: [ - { file: pkg.exports["./files"].require, format: "cjs", sourcemap: true }, + { file: pkg.exports["./server"].require, format: "cjs", sourcemap: true }, ], external: ["fs"], plugins: [...es2017BuildPlugins], @@ -81,4 +81,4 @@ const filesBuilds = [ ]; // eslint-disable-next-line import/no-default-export -export default [...esmBuilds, ...cjsBuilds, ...filesBuilds]; +export default [...esmBuilds, ...cjsBuilds, ...serverBuilds]; diff --git a/packages/main/src/gen-ai.ts b/packages/main/src/gen-ai.ts index a3c2bce4..229f8c9b 100644 --- a/packages/main/src/gen-ai.ts +++ b/packages/main/src/gen-ai.ts @@ -16,9 +16,8 @@ */ import { GoogleGenerativeAIError } from "./errors"; -import { ModelParams, RequestOptions } from "../types"; +import { CachedContent, ModelParams, RequestOptions } from "../types"; import { GenerativeModel } from "./models/generative-model"; -import { CachedContent } from "./server"; export { ChatSession } from "./methods/chat-session"; export { GenerativeModel }; diff --git a/packages/main/src/models/generative-model.ts b/packages/main/src/models/generative-model.ts index 8f8d85d4..ad6ba0a8 100644 --- a/packages/main/src/models/generative-model.ts +++ b/packages/main/src/models/generative-model.ts @@ -22,6 +22,7 @@ import { import { BatchEmbedContentsRequest, BatchEmbedContentsResponse, + CachedContent, Content, CountTokensRequest, CountTokensResponse, @@ -48,7 +49,6 @@ import { formatGenerateContentInput, formatSystemInstruction, } from "../requests/request-helpers"; -import { CachedContent } from "../server"; /** * Class for generative model APIs. diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts index d316589a..10ab35d1 100644 --- a/packages/main/src/server/cache-manager.ts +++ b/packages/main/src/server/cache-manager.ts @@ -15,7 +15,8 @@ * limitations under the License. */ -import { Content, Part, RequestOptions, Tool, ToolConfig } from "../../types"; +import { + CachedContent, Content, Part, RequestOptions, Tool, ToolConfig } from "../../types"; import { CachedContentUrl, FilesRequestUrl, @@ -23,19 +24,18 @@ import { makeServerRequest, } from "./request"; import { - CachedContent, CachedContentCreateParams, CachedContentUpdateParams, ListCacheResponse, ListParams, -} from "./types"; +} from "../../types/server"; import { RpcTask } from "./constants"; /** * Class for managing GoogleAI file uploads. * @public */ -export class CacheManager { +export class GoogleAICacheManager { model: string; ttl?: string; tools?: Tool[]; diff --git a/packages/main/src/server/file-manager.test.ts b/packages/main/src/server/file-manager.test.ts index b35b0636..f593ba7f 100644 --- a/packages/main/src/server/file-manager.test.ts +++ b/packages/main/src/server/file-manager.test.ts @@ -22,7 +22,7 @@ import { restore, stub } from "sinon"; import * as request from "./request"; import { RpcTask } from "./constants"; import { DEFAULT_API_VERSION } from "../requests/request"; -import { FileMetadata } from "./types"; +import { FileMetadata } from "../../types/server"; use(sinonChai); use(chaiAsPromised); diff --git a/packages/main/src/server/file-manager.ts b/packages/main/src/server/file-manager.ts index e3daf487..e839b8f7 100644 --- a/packages/main/src/server/file-manager.ts +++ b/packages/main/src/server/file-manager.ts @@ -24,7 +24,7 @@ import { ListFilesResponse, ListParams, UploadFileResponse, -} from "./types"; +} from "../../types/server"; import { RpcTask } from "./constants"; import { GoogleGenerativeAIError, diff --git a/packages/main/src/server/index.ts b/packages/main/src/server/index.ts index 6d89670f..e13b849c 100644 --- a/packages/main/src/server/index.ts +++ b/packages/main/src/server/index.ts @@ -16,5 +16,6 @@ */ export { GoogleAIFileManager } from "./file-manager"; -export * from "./types"; -export { RequestOptions } from "../../types"; +export { GoogleAICacheManager } from "./cache-manager"; + +export * from "../../types/server"; diff --git a/packages/main/types/cached-content.ts b/packages/main/types/cached-content.ts new file mode 100644 index 00000000..9bbbf8ed --- /dev/null +++ b/packages/main/types/cached-content.ts @@ -0,0 +1,26 @@ +import { Content, Part } from "./content"; +import { Tool, ToolConfig } from "./function-calling"; + +/** + * @public + */ +export interface CachedContentBase { + model?: string; + contents: Content[]; + tools?: Tool[]; + toolConfig?: ToolConfig; + systemInstruction?: string | Part | Content; +} + +/** + * Describes CachedContent interface for sending to the server (if creating) + * or received from the server (using getters or list methods). + * @public + */ +export interface CachedContent extends CachedContentBase { + ttl?: string; + // ISO string + createTime?: string; + // ISO string + updateTime?: string; +} \ No newline at end of file diff --git a/packages/main/types/content.ts b/packages/main/types/content.ts index 69c50a92..9367d4bb 100644 --- a/packages/main/types/content.ts +++ b/packages/main/types/content.ts @@ -15,6 +15,8 @@ * limitations under the License. */ +export * from './function-calling'; + /** * Content type for both prompts and response candidates. * @public diff --git a/packages/main/types/function-calling.ts b/packages/main/types/function-calling.ts new file mode 100644 index 00000000..0963ef28 --- /dev/null +++ b/packages/main/types/function-calling.ts @@ -0,0 +1,163 @@ +import { FunctionCallingMode } from "./enums"; + +/** + * 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 + * [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included + * in this declaration are the function name and parameters. This + * FunctionDeclaration is a representation of a block of code that can be used + * as a Tool by the model and executed by the client. + * @public + */ +export declare interface FunctionDeclaration { + /** + * The name of the function to call. Must start with a letter or an + * underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with + * a max length of 64. + */ + name: string; + /** + * Optional. Description and purpose of the function. Model uses it to decide + * how and whether to call the function. + */ + description?: string; + /** + * Optional. Describes the parameters to this function in JSON Schema Object + * format. Reflects the Open API 3.03 Parameter Object. string Key: the name + * of the parameter. Parameter names are case sensitive. Schema Value: the + * Schema defining the type used for the parameter. For function with no + * parameters, this can be left unset. + * + * @example with 1 required and 1 optional parameter: type: OBJECT properties: + * ``` + * param1: + * + * type: STRING + * param2: + * + * type: INTEGER + * required: + * + * - param1 + * ``` + */ + parameters?: FunctionDeclarationSchema; +} + +/** + * A FunctionDeclarationsTool is a piece of code that enables the system to + * interact with external systems to perform an action, or set of actions, + * outside of knowledge and scope of the model. + * @public + */ +export declare interface FunctionDeclarationsTool { + /** + * Optional. One or more function declarations + * to be passed to the model along with the current user query. Model may + * decide to call a subset of these functions by populating + * [FunctionCall][content.part.functionCall] in the response. User should + * provide a [FunctionResponse][content.part.functionResponse] for each + * function call in the next turn. Based on the function responses, Model will + * generate the final response back to the user. Maximum 64 function + * declarations can be provided. + */ + functionDeclarations?: FunctionDeclaration[]; +} + +/** + * Contains the list of OpenAPI data types + * as defined by https://swagger.io/docs/specification/data-models/data-types/ + * @public + */ +export 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", +} + +/** + * Schema is used to define the format of input/output data. + * Represents a select subset of an OpenAPI 3.0 schema object. + * More fields may be added in the future as needed. + * @public + */ +export interface Schema { + /** + * Optional. The type of the property. {@link + * FunctionDeclarationSchemaType}. + */ + type?: FunctionDeclarationSchemaType; + /** Optional. The format of the property. */ + format?: string; + /** Optional. The description of the property. */ + description?: string; + /** Optional. Whether the property is nullable. */ + nullable?: boolean; + /** Optional. The items of the property. {@link FunctionDeclarationSchema} */ + items?: FunctionDeclarationSchema; + /** Optional. The enum of the property. */ + enum?: string[]; + /** Optional. Map of {@link FunctionDeclarationSchema}. */ + properties?: { [k: string]: FunctionDeclarationSchema }; + /** Optional. Array of required property. */ + required?: string[]; + /** Optional. The example of the property. */ + example?: unknown; +} + +/** + * Schema for parameters passed to {@link FunctionDeclaration.parameters}. + * @public + */ +export interface FunctionDeclarationSchema { + /** The type of the parameter. */ + type: FunctionDeclarationSchemaType; + /** The format of the parameter. */ + properties: { [k: string]: FunctionDeclarationSchemaProperty }; + /** Optional. Description of the parameter. */ + description?: string; + /** Optional. Array of required parameters. */ + required?: string[]; +} + +/** + * Schema for top-level function declaration + * @public + */ +export interface FunctionDeclarationSchemaProperty extends Schema {} + +/** + * Schema passed to `GenerationConfig.responseSchema` + * @public + */ +export interface ResponseSchema extends Schema {} + +/** + * Tool config. This config is shared for all tools provided in the request. + * @public + */ +export interface ToolConfig { + functionCallingConfig: FunctionCallingConfig; +} + +/** + * @public + */ +export interface FunctionCallingConfig { + mode?: FunctionCallingMode; + allowedFunctionNames?: string[]; +} diff --git a/packages/main/types/index.ts b/packages/main/types/index.ts index 55b341f6..8ea43996 100644 --- a/packages/main/types/index.ts +++ b/packages/main/types/index.ts @@ -19,3 +19,4 @@ export * from "./content"; export * from "./enums"; export * from "./requests"; export * from "./responses"; +export * from './cached-content'; diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index 7dec6cda..1ee52ffd 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -15,14 +15,14 @@ * limitations under the License. */ -import { CachedContent } from "../src/server"; +import { CachedContent } from "./cached-content"; import { Content, Part } from "./content"; import { - FunctionCallingMode, HarmBlockThreshold, HarmCategory, TaskType, } from "./enums"; +import { ResponseSchema, Tool, ToolConfig } from "./function-calling"; /** * Base parameters for a number of methods. @@ -181,165 +181,3 @@ export interface RequestOptions { */ customHeaders?: Headers | Record; } - -/** - * 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 - * [OpenAPI 3.0 specification](https://spec.openapis.org/oas/v3.0.3). Included - * in this declaration are the function name and parameters. This - * FunctionDeclaration is a representation of a block of code that can be used - * as a Tool by the model and executed by the client. - * @public - */ -export declare interface FunctionDeclaration { - /** - * The name of the function to call. Must start with a letter or an - * underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with - * a max length of 64. - */ - name: string; - /** - * Optional. Description and purpose of the function. Model uses it to decide - * how and whether to call the function. - */ - description?: string; - /** - * Optional. Describes the parameters to this function in JSON Schema Object - * format. Reflects the Open API 3.03 Parameter Object. string Key: the name - * of the parameter. Parameter names are case sensitive. Schema Value: the - * Schema defining the type used for the parameter. For function with no - * parameters, this can be left unset. - * - * @example with 1 required and 1 optional parameter: type: OBJECT properties: - * ``` - * param1: - * - * type: STRING - * param2: - * - * type: INTEGER - * required: - * - * - param1 - * ``` - */ - parameters?: FunctionDeclarationSchema; -} - -/** - * A FunctionDeclarationsTool is a piece of code that enables the system to - * interact with external systems to perform an action, or set of actions, - * outside of knowledge and scope of the model. - * @public - */ -export declare interface FunctionDeclarationsTool { - /** - * Optional. One or more function declarations - * to be passed to the model along with the current user query. Model may - * decide to call a subset of these functions by populating - * [FunctionCall][content.part.functionCall] in the response. User should - * provide a [FunctionResponse][content.part.functionResponse] for each - * function call in the next turn. Based on the function responses, Model will - * generate the final response back to the user. Maximum 64 function - * declarations can be provided. - */ - functionDeclarations?: FunctionDeclaration[]; -} - -/** - * Contains the list of OpenAPI data types - * as defined by https://swagger.io/docs/specification/data-models/data-types/ - * @public - */ -export 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", -} - -/** - * Schema is used to define the format of input/output data. - * Represents a select subset of an OpenAPI 3.0 schema object. - * More fields may be added in the future as needed. - * @public - */ -export interface Schema { - /** - * Optional. The type of the property. {@link - * FunctionDeclarationSchemaType}. - */ - type?: FunctionDeclarationSchemaType; - /** Optional. The format of the property. */ - format?: string; - /** Optional. The description of the property. */ - description?: string; - /** Optional. Whether the property is nullable. */ - nullable?: boolean; - /** Optional. The items of the property. {@link FunctionDeclarationSchema} */ - items?: FunctionDeclarationSchema; - /** Optional. The enum of the property. */ - enum?: string[]; - /** Optional. Map of {@link FunctionDeclarationSchema}. */ - properties?: { [k: string]: FunctionDeclarationSchema }; - /** Optional. Array of required property. */ - required?: string[]; - /** Optional. The example of the property. */ - example?: unknown; -} - -/** - * Schema for parameters passed to {@link FunctionDeclaration.parameters}. - * @public - */ -export interface FunctionDeclarationSchema { - /** The type of the parameter. */ - type: FunctionDeclarationSchemaType; - /** The format of the parameter. */ - properties: { [k: string]: FunctionDeclarationSchemaProperty }; - /** Optional. Description of the parameter. */ - description?: string; - /** Optional. Array of required parameters. */ - required?: string[]; -} - -/** - * Schema for top-level function declaration - * @public - */ -export interface FunctionDeclarationSchemaProperty extends Schema {} - -/** - * Schema passed to {@link GenerationConfig.responseSchema} - * @public - */ -export interface ResponseSchema extends Schema {} - -/** - * Tool config. This config is shared for all tools provided in the request. - * @public - */ -export interface ToolConfig { - functionCallingConfig: FunctionCallingConfig; -} - -/** - * @public - */ -export interface FunctionCallingConfig { - mode?: FunctionCallingMode; - allowedFunctionNames?: string[]; -} diff --git a/packages/main/src/server/types/caching.ts b/packages/main/types/server/caching.ts similarity index 62% rename from packages/main/src/server/types/caching.ts rename to packages/main/types/server/caching.ts index 4c943560..c39045b6 100644 --- a/packages/main/src/server/types/caching.ts +++ b/packages/main/types/server/caching.ts @@ -15,18 +15,11 @@ * limitations under the License. */ -import { Content, Part, Tool, ToolConfig } from "../../../types"; - -export interface CachedContentBase { - model?: string; - contents: Content[]; - tools?: Tool[]; - toolConfig?: ToolConfig; - systemInstruction?: string | Part | Content; -} +import { CachedContent, CachedContentBase } from "../cached-content"; /** - * Params to pass to {@link CacheManager.create} + * Params to pass to {@link GoogleAICacheManager.create} + * @public */ export interface CachedContentCreateParams extends CachedContentBase { // sent field needs to be protobuf Duration ("3.0001s") @@ -34,7 +27,8 @@ export interface CachedContentCreateParams extends CachedContentBase { } /** - * Params to pass to {@link CacheManager.update} + * Params to pass to {@link GoogleAICacheManager.update} + * @public */ export interface CachedContentUpdateParams { cachedContent: CachedContentCreateParams; @@ -45,17 +39,8 @@ export interface CachedContentUpdateParams { } /** - * Describes CachedContent interface for sending to the server (if creating) - * or received from the server (using getters or list methods). + * @public */ -export interface CachedContent extends CachedContentBase { - ttl?: string; - // ISO string - createTime?: string; - // ISO string - updateTime?: string; -} - export interface ListCacheResponse { cachedContents: CachedContent[]; nextPageToken?: string; diff --git a/packages/main/src/server/types/files.ts b/packages/main/types/server/files.ts similarity index 100% rename from packages/main/src/server/types/files.ts rename to packages/main/types/server/files.ts diff --git a/packages/main/src/server/types/index.ts b/packages/main/types/server/index.ts similarity index 83% rename from packages/main/src/server/types/index.ts rename to packages/main/types/server/index.ts index c9a84036..89e07291 100644 --- a/packages/main/src/server/types/index.ts +++ b/packages/main/types/server/index.ts @@ -18,3 +18,7 @@ export * from './files'; export * from './caching'; export * from './shared'; + +export { RequestOptions } from "../../types/requests"; +export * from "../../types/content"; +export * from "../../types/cached-content"; \ No newline at end of file diff --git a/packages/main/src/server/types/shared.ts b/packages/main/types/server/shared.ts similarity index 93% rename from packages/main/src/server/types/shared.ts rename to packages/main/types/server/shared.ts index 0a229473..36265f45 100644 --- a/packages/main/src/server/types/shared.ts +++ b/packages/main/types/server/shared.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ErrorDetails } from "../../../types"; +import { ErrorDetails } from "../responses"; export { ErrorDetails }; @@ -40,7 +40,7 @@ export interface RpcStatus { /** * Params to pass to {@link GoogleAIFileManager.listFiles} or - * {@link CacheManager.list} + * {@link GoogleAICacheManager.list} * @public */ export interface ListParams { From 5bf7ac5719857c3e9331cb8cc3e78561e2f78b43 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Wed, 5 Jun 2024 17:46:14 -0700 Subject: [PATCH 04/14] handle model and cache name prefixes --- packages/main/src/server/cache-manager.ts | 28 ++++++++++++++++++++--- packages/main/types/cached-content.ts | 26 --------------------- packages/main/types/index.ts | 2 +- packages/main/types/requests.ts | 2 +- packages/main/types/server/caching.ts | 26 ++++++++++++++++++++- packages/main/types/server/index.ts | 3 +-- 6 files changed, 53 insertions(+), 34 deletions(-) delete mode 100644 packages/main/types/cached-content.ts diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts index 10ab35d1..8c71400c 100644 --- a/packages/main/src/server/cache-manager.ts +++ b/packages/main/src/server/cache-manager.ts @@ -30,6 +30,7 @@ import { ListParams, } from "../../types/server"; import { RpcTask } from "./constants"; +import { GoogleGenerativeAIError } from "../errors"; /** * Class for managing GoogleAI file uploads. @@ -58,6 +59,10 @@ export class GoogleAICacheManager { newCachedContent.ttl = createOptions.ttlSeconds.toString() + "s"; delete (newCachedContent as CachedContentCreateParams).ttlSeconds; } + if (!newCachedContent.model.includes("/")) { + // If path is not included, assume it's a non-tuned model. + newCachedContent.model = `models/${newCachedContent.model}`; + } const url = new CachedContentUrl( RpcTask.UPLOAD, this.apiKey, @@ -103,7 +108,7 @@ export class GoogleAICacheManager { this.apiKey, this._requestOptions, ); - url.appendPath(name); + url.appendPath(parseCacheName(name)); const uploadHeaders = getHeaders(url); const response = await makeServerRequest(url, uploadHeaders); return response.json(); @@ -121,7 +126,7 @@ export class GoogleAICacheManager { this.apiKey, this._requestOptions, ); - url.appendPath(name); + url.appendPath(parseCacheName(name)); const uploadHeaders = getHeaders(url); const response = await makeServerRequest( url, @@ -140,8 +145,25 @@ export class GoogleAICacheManager { this.apiKey, this._requestOptions, ); - url.appendPath(name); + url.appendPath(parseCacheName(name)); const uploadHeaders = getHeaders(url); await makeServerRequest(url, uploadHeaders); } } + +/** + * If fileId is prepended with "files/", remove prefix + */ +function parseCacheName(name: string): string { + if (name.startsWith("cachedContents/")) { + return name.split("cachedContents/")[1]; + } + if (!name) { + throw new GoogleGenerativeAIError( + `Invalid name ${name}. ` + + `Must be in the format "cachedContents/name" or "name"`, + ); + } + + return name; +} diff --git a/packages/main/types/cached-content.ts b/packages/main/types/cached-content.ts deleted file mode 100644 index 9bbbf8ed..00000000 --- a/packages/main/types/cached-content.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Content, Part } from "./content"; -import { Tool, ToolConfig } from "./function-calling"; - -/** - * @public - */ -export interface CachedContentBase { - model?: string; - contents: Content[]; - tools?: Tool[]; - toolConfig?: ToolConfig; - systemInstruction?: string | Part | Content; -} - -/** - * Describes CachedContent interface for sending to the server (if creating) - * or received from the server (using getters or list methods). - * @public - */ -export interface CachedContent extends CachedContentBase { - ttl?: string; - // ISO string - createTime?: string; - // ISO string - updateTime?: string; -} \ No newline at end of file diff --git a/packages/main/types/index.ts b/packages/main/types/index.ts index 8ea43996..41a2b601 100644 --- a/packages/main/types/index.ts +++ b/packages/main/types/index.ts @@ -19,4 +19,4 @@ export * from "./content"; export * from "./enums"; export * from "./requests"; export * from "./responses"; -export * from './cached-content'; +export { CachedContent, CachedContentBase } from './server/caching'; diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index 1ee52ffd..df030e33 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { CachedContent } from "./cached-content"; +import { CachedContent } from "./server/caching"; import { Content, Part } from "./content"; import { HarmBlockThreshold, diff --git a/packages/main/types/server/caching.ts b/packages/main/types/server/caching.ts index c39045b6..39f6a450 100644 --- a/packages/main/types/server/caching.ts +++ b/packages/main/types/server/caching.ts @@ -14,8 +14,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { Content, Part } from "../content"; +import { Tool, ToolConfig } from "../function-calling"; -import { CachedContent, CachedContentBase } from "../cached-content"; +/** + * @public + */ +export interface CachedContentBase { + model?: string; + contents: Content[]; + tools?: Tool[]; + toolConfig?: ToolConfig; + systemInstruction?: string | Part | Content; +} + +/** + * Describes CachedContent interface for sending to the server (if creating) + * or received from the server (using getters or list methods). + * @public + */ +export interface CachedContent extends CachedContentBase { + ttl?: string; + // ISO string + createTime?: string; + // ISO string + updateTime?: string; +} /** * Params to pass to {@link GoogleAICacheManager.create} diff --git a/packages/main/types/server/index.ts b/packages/main/types/server/index.ts index 89e07291..aa9b0063 100644 --- a/packages/main/types/server/index.ts +++ b/packages/main/types/server/index.ts @@ -20,5 +20,4 @@ export * from './caching'; export * from './shared'; export { RequestOptions } from "../../types/requests"; -export * from "../../types/content"; -export * from "../../types/cached-content"; \ No newline at end of file +export * from "../../types/content"; \ No newline at end of file From 477d7bba38396784e89cbea30359d9b353e7473a Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Thu, 6 Jun 2024 10:14:31 -0700 Subject: [PATCH 05/14] generateContent only sends the cache name --- common/api-review/generative-ai-server.api.md | 2 ++ common/api-review/generative-ai.api.md | 8 ++++---- packages/main/rollup.config.mjs | 4 ++++ packages/main/src/gen-ai.ts | 10 +++++++--- packages/main/src/models/generative-model.ts | 6 +++--- packages/main/types/requests.ts | 10 ++++++++-- packages/main/types/server/caching.ts | 1 + 7 files changed, 29 insertions(+), 12 deletions(-) diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md index 3ed6fdcf..e54f275f 100644 --- a/common/api-review/generative-ai-server.api.md +++ b/common/api-review/generative-ai-server.api.md @@ -9,6 +9,8 @@ export interface CachedContent extends CachedContentBase { // (undocumented) createTime?: string; // (undocumented) + name?: string; + // (undocumented) ttl?: string; // (undocumented) updateTime?: string; diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index 60999238..d2481acc 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -39,6 +39,8 @@ export interface CachedContent extends CachedContentBase { // (undocumented) createTime?: string; // (undocumented) + name?: string; + // (undocumented) ttl?: string; // (undocumented) updateTime?: string; @@ -322,8 +324,7 @@ export interface GenerateContentCandidate { // @public export interface GenerateContentRequest extends BaseParams { - // (undocumented) - cachedContent?: CachedContent; + cachedContent?: string; // (undocumented) contents: Content[]; // (undocumented) @@ -585,8 +586,7 @@ export interface Schema { // @public export interface StartChatParams extends BaseParams { - // (undocumented) - cachedContent?: CachedContent; + cachedContent?: string; // (undocumented) history?: Content[]; // (undocumented) diff --git a/packages/main/rollup.config.mjs b/packages/main/rollup.config.mjs index d309351f..9367f59d 100644 --- a/packages/main/rollup.config.mjs +++ b/packages/main/rollup.config.mjs @@ -41,6 +41,7 @@ const es2017BuildPlugins = [ const esmBuilds = [ { + clean: true, input: "src/index.ts", output: { file: pkg.module, @@ -54,6 +55,7 @@ const esmBuilds = [ const cjsBuilds = [ { + clean: true, input: "src/index.ts", output: [{ file: pkg.main, format: "cjs", sourcemap: true }], external: ["fs"], @@ -63,6 +65,7 @@ const cjsBuilds = [ const serverBuilds = [ { + clean: true, input: "src/server/index.ts", output: [ { file: pkg.exports["./server"].import, format: "es", sourcemap: true }, @@ -71,6 +74,7 @@ const serverBuilds = [ plugins: [...es2017BuildPlugins], }, { + clean: true, input: "src/server/index.ts", output: [ { file: pkg.exports["./server"].require, format: "cjs", sourcemap: true }, diff --git a/packages/main/src/gen-ai.ts b/packages/main/src/gen-ai.ts index 229f8c9b..5aea6dfa 100644 --- a/packages/main/src/gen-ai.ts +++ b/packages/main/src/gen-ai.ts @@ -52,13 +52,17 @@ export class GoogleGenerativeAI { cachedContent: CachedContent, requestOptions?: RequestOptions, ): GenerativeModel { - const modelParams: ModelParams = { + const modelParamsFromCache: ModelParams = { model: cachedContent.model, tools: cachedContent.tools, toolConfig: cachedContent.toolConfig, systemInstruction: cachedContent.systemInstruction, - cachedContent + cachedContent, }; - return new GenerativeModel(this.apiKey, modelParams, requestOptions); + return new GenerativeModel( + this.apiKey, + modelParamsFromCache, + requestOptions, + ); } } diff --git a/packages/main/src/models/generative-model.ts b/packages/main/src/models/generative-model.ts index ad6ba0a8..8af2aabc 100644 --- a/packages/main/src/models/generative-model.ts +++ b/packages/main/src/models/generative-model.ts @@ -104,7 +104,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, - cachedContent: this.cachedContent, + cachedContent: this.cachedContent.name, ...formattedParams, }, this.requestOptions, @@ -130,7 +130,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, - cachedContent: this.cachedContent, + cachedContent: this.cachedContent.name, ...formattedParams, }, this.requestOptions, @@ -151,7 +151,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, - cachedContent: this.cachedContent, + cachedContent: this.cachedContent.name, ...startChatParams, }, this.requestOptions, diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index df030e33..544b246c 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -54,7 +54,10 @@ export interface GenerateContentRequest extends BaseParams { tools?: Tool[]; toolConfig?: ToolConfig; systemInstruction?: string | Part | Content; - cachedContent?: CachedContent; + /** + * This is the name of a `CachedContent` and not the cache object itself. + */ + cachedContent?: string; } /** @@ -109,7 +112,10 @@ export interface StartChatParams extends BaseParams { tools?: Tool[]; toolConfig?: ToolConfig; systemInstruction?: string | Part | Content; - cachedContent?: CachedContent; + /** + * This is the name of a `CachedContent` and not the cache object itself. + */ + cachedContent?: string; } /** diff --git a/packages/main/types/server/caching.ts b/packages/main/types/server/caching.ts index 39f6a450..d5d18185 100644 --- a/packages/main/types/server/caching.ts +++ b/packages/main/types/server/caching.ts @@ -34,6 +34,7 @@ export interface CachedContentBase { * @public */ export interface CachedContent extends CachedContentBase { + name?: string; ttl?: string; // ISO string createTime?: string; From 22277ae86c6b0241c20e2347a90862498397b28f Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Thu, 6 Jun 2024 13:50:04 -0700 Subject: [PATCH 06/14] format and add expireTime --- packages/main/src/requests/request.test.ts | 36 +++++++++++++++------- packages/main/src/requests/request.ts | 1 - packages/main/src/server/cache-manager.ts | 8 ++++- packages/main/src/server/constants.ts | 2 +- packages/main/types/content.ts | 2 +- packages/main/types/function-calling.ts | 16 ++++++++++ packages/main/types/index.ts | 2 +- packages/main/types/requests.ts | 6 +--- packages/main/types/server/caching.ts | 22 ++++++++++--- packages/main/types/server/index.ts | 8 ++--- packages/main/types/server/shared.ts | 2 +- 11 files changed, 75 insertions(+), 30 deletions(-) diff --git a/packages/main/src/requests/request.test.ts b/packages/main/src/requests/request.test.ts index b898b443..61d39924 100644 --- a/packages/main/src/requests/request.test.ts +++ b/packages/main/src/requests/request.test.ts @@ -175,21 +175,35 @@ describe("request methods", () => { }); it("passes custom x-goog-api-client header", async () => { await expect( - constructModelRequest("model-name", Task.GENERATE_CONTENT, "key", true, "", { - customHeaders: new Headers({ - "x-goog-api-client": "client/version", - }), - }), + constructModelRequest( + "model-name", + Task.GENERATE_CONTENT, + "key", + true, + "", + { + customHeaders: new Headers({ + "x-goog-api-client": "client/version", + }), + }, + ), ).to.be.rejectedWith(GoogleGenerativeAIRequestInputError); }); it("passes apiClient and custom x-goog-api-client header", async () => { await expect( - constructModelRequest("model-name", Task.GENERATE_CONTENT, "key", true, "", { - apiClient: "client/version", - customHeaders: new Headers({ - "x-goog-api-client": "client/version2", - }), - }), + constructModelRequest( + "model-name", + Task.GENERATE_CONTENT, + "key", + true, + "", + { + apiClient: "client/version", + customHeaders: new Headers({ + "x-goog-api-client": "client/version2", + }), + }, + ), ).to.be.rejectedWith(GoogleGenerativeAIRequestInputError); }); }); diff --git a/packages/main/src/requests/request.ts b/packages/main/src/requests/request.ts index f7d09394..3c0072f8 100644 --- a/packages/main/src/requests/request.ts +++ b/packages/main/src/requests/request.ts @@ -227,4 +227,3 @@ function buildFetchOptions(requestOptions?: RequestOptions): RequestInit { } return fetchOptions; } - diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts index 8c71400c..775f7350 100644 --- a/packages/main/src/server/cache-manager.ts +++ b/packages/main/src/server/cache-manager.ts @@ -16,7 +16,13 @@ */ import { - CachedContent, Content, Part, RequestOptions, Tool, ToolConfig } from "../../types"; + CachedContent, + Content, + Part, + RequestOptions, + Tool, + ToolConfig, +} from "../../types"; import { CachedContentUrl, FilesRequestUrl, diff --git a/packages/main/src/server/constants.ts b/packages/main/src/server/constants.ts index 1c101b85..fbf6859f 100644 --- a/packages/main/src/server/constants.ts +++ b/packages/main/src/server/constants.ts @@ -20,5 +20,5 @@ export enum RpcTask { GET = "get", DELETE = "delete", UPDATE = "update", - CREATE = "create" + CREATE = "create", } diff --git a/packages/main/types/content.ts b/packages/main/types/content.ts index 9367d4bb..661a0269 100644 --- a/packages/main/types/content.ts +++ b/packages/main/types/content.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -export * from './function-calling'; +export * from "./function-calling"; /** * Content type for both prompts and response candidates. diff --git a/packages/main/types/function-calling.ts b/packages/main/types/function-calling.ts index 0963ef28..ff15554a 100644 --- a/packages/main/types/function-calling.ts +++ b/packages/main/types/function-calling.ts @@ -1,3 +1,19 @@ +/** + * @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. + */ import { FunctionCallingMode } from "./enums"; /** diff --git a/packages/main/types/index.ts b/packages/main/types/index.ts index 41a2b601..67a41ff7 100644 --- a/packages/main/types/index.ts +++ b/packages/main/types/index.ts @@ -19,4 +19,4 @@ export * from "./content"; export * from "./enums"; export * from "./requests"; export * from "./responses"; -export { CachedContent, CachedContentBase } from './server/caching'; +export { CachedContent, CachedContentBase } from "./server/caching"; diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index 544b246c..85078652 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -17,11 +17,7 @@ import { CachedContent } from "./server/caching"; import { Content, Part } from "./content"; -import { - HarmBlockThreshold, - HarmCategory, - TaskType, -} from "./enums"; +import { HarmBlockThreshold, HarmCategory, TaskType } from "./enums"; import { ResponseSchema, Tool, ToolConfig } from "./function-calling"; /** diff --git a/packages/main/types/server/caching.ts b/packages/main/types/server/caching.ts index d5d18185..696e0443 100644 --- a/packages/main/types/server/caching.ts +++ b/packages/main/types/server/caching.ts @@ -35,10 +35,22 @@ export interface CachedContentBase { */ export interface CachedContent extends CachedContentBase { name?: string; + /** + * protobuf.Duration format (ex. "3.0001s"). Specify either this or + * `expireTime`. + */ ttl?: string; - // ISO string + /** + * Expiration time in ISO string format. Specify either this or `ttl`. + */ + expireTime?: string; + /** + * CachedContent creation time in ISO string format + */ createTime?: string; - // ISO string + /** + * CachedContent update time in ISO string format + */ updateTime?: string; } @@ -47,7 +59,9 @@ export interface CachedContent extends CachedContentBase { * @public */ export interface CachedContentCreateParams extends CachedContentBase { - // sent field needs to be protobuf Duration ("3.0001s") + /** + * CachedContent ttl in seconds. + */ ttlSeconds?: number; } @@ -69,4 +83,4 @@ export interface CachedContentUpdateParams { export interface ListCacheResponse { cachedContents: CachedContent[]; nextPageToken?: string; -} \ No newline at end of file +} diff --git a/packages/main/types/server/index.ts b/packages/main/types/server/index.ts index aa9b0063..2bc04922 100644 --- a/packages/main/types/server/index.ts +++ b/packages/main/types/server/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -export * from './files'; -export * from './caching'; -export * from './shared'; +export * from "./files"; +export * from "./caching"; +export * from "./shared"; export { RequestOptions } from "../../types/requests"; -export * from "../../types/content"; \ No newline at end of file +export * from "../../types/content"; diff --git a/packages/main/types/server/shared.ts b/packages/main/types/server/shared.ts index 36265f45..aee18106 100644 --- a/packages/main/types/server/shared.ts +++ b/packages/main/types/server/shared.ts @@ -46,4 +46,4 @@ export interface RpcStatus { export interface ListParams { pageSize?: number; pageToken?: string; -} \ No newline at end of file +} From 0de921186f7a6c5c0a262bb11ec56c097c89f865 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Thu, 6 Jun 2024 14:03:12 -0700 Subject: [PATCH 07/14] fix existing tests --- .../main/src/methods/generate-content.test.ts | 16 ++++----- .../main/src/models/generative-model.test.ts | 16 ++++----- packages/main/src/models/generative-model.ts | 6 ++-- packages/main/src/requests/request.ts | 2 +- packages/main/src/server/file-manager.test.ts | 36 +++++++++---------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/main/src/methods/generate-content.test.ts b/packages/main/src/methods/generate-content.test.ts index cea96bda..5f49dc15 100644 --- a/packages/main/src/methods/generate-content.test.ts +++ b/packages/main/src/methods/generate-content.test.ts @@ -52,7 +52,7 @@ describe("generateContent()", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const result = await generateContent("key", "model", fakeRequestParams); @@ -69,7 +69,7 @@ describe("generateContent()", () => { }); it("long response", async () => { const mockResponse = getMockResponse("unary-success-basic-reply-long.json"); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const result = await generateContent("key", "model", fakeRequestParams); @@ -85,7 +85,7 @@ describe("generateContent()", () => { }); it("citations", async () => { const mockResponse = getMockResponse("unary-success-citations.json"); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const result = await generateContent("key", "model", fakeRequestParams); @@ -105,7 +105,7 @@ describe("generateContent()", () => { const mockResponse = getMockResponse( "unary-failure-prompt-blocked-safety.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const result = await generateContent("key", "model", fakeRequestParams); @@ -122,7 +122,7 @@ describe("generateContent()", () => { const mockResponse = getMockResponse( "unary-failure-finish-reason-safety.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const result = await generateContent("key", "model", fakeRequestParams); @@ -137,7 +137,7 @@ describe("generateContent()", () => { }); it("empty content", async () => { const mockResponse = getMockResponse("unary-failure-empty-content.json"); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const result = await generateContent("key", "model", fakeRequestParams); @@ -152,7 +152,7 @@ describe("generateContent()", () => { }); it("unknown enum - should ignore", async () => { const mockResponse = getMockResponse("unary-unknown-enum.json"); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const result = await generateContent("key", "model", fakeRequestParams); @@ -168,7 +168,7 @@ describe("generateContent()", () => { it("image rejected (400)", async () => { const mockResponse = getMockResponse("unary-failure-image-rejected.json"); const errorJson = await mockResponse.json(); - const makeRequestStub = stub(request, "makeRequest").rejects( + const makeRequestStub = stub(request, "makeModelRequest").rejects( new Error(`[400 ] ${errorJson.error.message}`), ); await expect( diff --git a/packages/main/src/models/generative-model.test.ts b/packages/main/src/models/generative-model.test.ts index 9e10f062..61cb630e 100644 --- a/packages/main/src/models/generative-model.test.ts +++ b/packages/main/src/models/generative-model.test.ts @@ -100,7 +100,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); await genModel.generateContent("hello"); @@ -134,7 +134,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); await genModel.generateContent("hello"); @@ -184,7 +184,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); await genModel.generateContent({ @@ -248,7 +248,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); await genModel.countTokens("hello"); @@ -279,7 +279,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); await genModel.startChat().sendMessage("hello"); @@ -323,7 +323,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); await genModel.startChat().sendMessage("hello"); @@ -369,7 +369,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); await genModel @@ -423,7 +423,7 @@ describe("GenerativeModel", () => { const mockResponse = getMockResponse( "unary-success-basic-reply-short.json", ); - const makeRequestStub = stub(request, "makeRequest").resolves( + const makeRequestStub = stub(request, "makeModelRequest").resolves( mockResponse as Response, ); const countTokensRequest: CountTokensRequest = { diff --git a/packages/main/src/models/generative-model.ts b/packages/main/src/models/generative-model.ts index 8af2aabc..029ac95a 100644 --- a/packages/main/src/models/generative-model.ts +++ b/packages/main/src/models/generative-model.ts @@ -104,7 +104,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, - cachedContent: this.cachedContent.name, + cachedContent: this.cachedContent?.name, ...formattedParams, }, this.requestOptions, @@ -130,7 +130,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, - cachedContent: this.cachedContent.name, + cachedContent: this.cachedContent?.name, ...formattedParams, }, this.requestOptions, @@ -151,7 +151,7 @@ export class GenerativeModel { tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, - cachedContent: this.cachedContent.name, + cachedContent: this.cachedContent?.name, ...startChatParams, }, this.requestOptions, diff --git a/packages/main/src/requests/request.ts b/packages/main/src/requests/request.ts index 3c0072f8..9eeeadcf 100644 --- a/packages/main/src/requests/request.ts +++ b/packages/main/src/requests/request.ts @@ -78,7 +78,7 @@ export async function getHeaders(url: RequestUrl): Promise { headers.append("x-goog-api-client", getClientHeaders(url.requestOptions)); headers.append("x-goog-api-key", url.apiKey); - let customHeaders = url.requestOptions.customHeaders; + let customHeaders = url.requestOptions?.customHeaders; if (customHeaders) { if (!(customHeaders instanceof Headers)) { try { diff --git a/packages/main/src/server/file-manager.test.ts b/packages/main/src/server/file-manager.test.ts index f593ba7f..93fed994 100644 --- a/packages/main/src/server/file-manager.test.ts +++ b/packages/main/src/server/file-manager.test.ts @@ -41,7 +41,7 @@ describe("GoogleAIFileManager", () => { expect(fileManager.apiKey).to.equal("apiKey"); }); it("passes uploadFile request info", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: fakeUploadJson, } as Response); @@ -58,11 +58,11 @@ describe("GoogleAIFileManager", () => { ); expect(makeRequestStub.args[0][2]).to.be.instanceOf(Blob); const bodyBlob = makeRequestStub.args[0][2]; - const blobText = await bodyBlob.text(); + const blobText = await (bodyBlob as Blob).text(); expect(blobText).to.include("Content-Type: image/png"); }); it("passes uploadFile request info and metadata", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: fakeUploadJson, } as Response); @@ -75,13 +75,13 @@ describe("GoogleAIFileManager", () => { expect(result.file.uri).to.equal(FAKE_URI); expect(makeRequestStub.args[0][2]).to.be.instanceOf(Blob); const bodyBlob = makeRequestStub.args[0][2]; - const blobText = await bodyBlob.text(); + const blobText = await (bodyBlob as Blob).text(); expect(blobText).to.include("Content-Type: image/png"); expect(blobText).to.include("files/customname"); expect(blobText).to.include("mydisplayname"); }); it("passes uploadFile metadata and formats file name", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: fakeUploadJson, } as Response); @@ -92,11 +92,11 @@ describe("GoogleAIFileManager", () => { displayName: "mydisplayname", }); const bodyBlob = makeRequestStub.args[0][2]; - const blobText = await bodyBlob.text(); + const blobText = await (bodyBlob as Blob).text(); expect(blobText).to.include("files/customname"); }); it("passes uploadFile request info (with options)", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: fakeUploadJson, } as Response); @@ -116,7 +116,7 @@ describe("GoogleAIFileManager", () => { ); expect(makeRequestStub.args[0][2]).to.be.instanceOf(Blob); const bodyBlob = makeRequestStub.args[0][2]; - const blobText = await bodyBlob.text(); + const blobText = await (bodyBlob as Blob).text(); expect(blobText).to.include("Content-Type: image/png"); expect(makeRequestStub.args[0][0].toString()).to.include("v3000/files"); expect(makeRequestStub.args[0][0].toString()).to.match( @@ -124,7 +124,7 @@ describe("GoogleAIFileManager", () => { ); }); it("passes listFiles request info", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({ files: [{ uri: FAKE_URI }] }), } as Response); @@ -135,7 +135,7 @@ describe("GoogleAIFileManager", () => { expect(makeRequestStub.args[0][0].toString()).to.match(/\/files$/); }); it("passes listFiles request info with params", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({ files: [{ uri: FAKE_URI }] }), } as Response); @@ -150,7 +150,7 @@ describe("GoogleAIFileManager", () => { expect(makeRequestStub.args[0][0].toString()).to.include("pageToken=abc"); }); it("passes listFiles request info with options", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({ files: [{ uri: FAKE_URI }] }), } as Response); @@ -168,7 +168,7 @@ describe("GoogleAIFileManager", () => { ); }); it("passes getFile request info", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({ uri: FAKE_URI }), } as Response); @@ -181,7 +181,7 @@ describe("GoogleAIFileManager", () => { ); }); it("passes getFile request info", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({ uri: FAKE_URI }), } as Response); @@ -193,7 +193,7 @@ describe("GoogleAIFileManager", () => { ); }); it("passes getFile request info (with options)", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({ uri: FAKE_URI }), } as Response); @@ -211,7 +211,7 @@ describe("GoogleAIFileManager", () => { ); }); it("getFile throws on bad fileId", async () => { - stub(request, "makeFilesRequest").resolves({ + stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({ uri: FAKE_URI }), } as Response); @@ -219,7 +219,7 @@ describe("GoogleAIFileManager", () => { await expect(fileManager.getFile("")).to.be.rejectedWith("Invalid fileId"); }); it("passes deleteFile request info", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({}), } as Response); @@ -229,7 +229,7 @@ describe("GoogleAIFileManager", () => { expect(makeRequestStub.args[0][0].toString()).to.include("/nameoffile"); }); it("passes deleteFile request info (with options)", async () => { - const makeRequestStub = stub(request, "makeFilesRequest").resolves({ + const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({}), } as Response); @@ -246,7 +246,7 @@ describe("GoogleAIFileManager", () => { ); }); it("deleteFile throws on bad fileId", async () => { - stub(request, "makeFilesRequest").resolves({ + stub(request, "makeServerRequest").resolves({ ok: true, json: () => Promise.resolve({}), } as Response); From c1283bfaf49d5e8dd70ff1053e06de67d69e3e68 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Thu, 6 Jun 2024 14:17:22 -0700 Subject: [PATCH 08/14] address PR comments, fix rollup config --- common/api-review/generative-ai-server.api.md | 19 ++++++++---- common/api-review/generative-ai.api.md | 4 +-- packages/main/rollup.config.mjs | 5 +-- packages/main/server/package.json | 2 +- packages/main/src/gen-ai.ts | 15 ++++++++- packages/main/src/requests/request.ts | 4 +-- packages/main/src/server/cache-manager.ts | 31 +++++++++++-------- packages/main/types/server/index.ts | 1 + 8 files changed, 51 insertions(+), 30 deletions(-) diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md index e54f275f..d69b6d61 100644 --- a/common/api-review/generative-ai-server.api.md +++ b/common/api-review/generative-ai-server.api.md @@ -6,13 +6,11 @@ // @public export interface CachedContent extends CachedContentBase { - // (undocumented) createTime?: string; + expireTime?: string; // (undocumented) name?: string; - // (undocumented) ttl?: string; - // (undocumented) updateTime?: string; } @@ -32,7 +30,6 @@ export interface CachedContentBase { // @public export interface CachedContentCreateParams extends CachedContentBase { - // (undocumented) ttlSeconds?: number; } @@ -147,12 +144,22 @@ export interface FunctionCall { export interface FunctionCallingConfig { // (undocumented) allowedFunctionNames?: string[]; - // Warning: (ae-forgotten-export) The symbol "FunctionCallingMode" needs to be exported by the entry point index.d.ts - // // (undocumented) mode?: FunctionCallingMode; } +// @public (undocumented) +export enum FunctionCallingMode { + // (undocumented) + ANY = "ANY", + // (undocumented) + AUTO = "AUTO", + // (undocumented) + MODE_UNSPECIFIED = "MODE_UNSPECIFIED", + // (undocumented) + NONE = "NONE" +} + // @public export interface FunctionCallPart { // (undocumented) diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index d2481acc..fa7daaab 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -36,13 +36,11 @@ export enum BlockReason { // @public export interface CachedContent extends CachedContentBase { - // (undocumented) createTime?: string; + expireTime?: string; // (undocumented) name?: string; - // (undocumented) ttl?: string; - // (undocumented) updateTime?: string; } diff --git a/packages/main/rollup.config.mjs b/packages/main/rollup.config.mjs index 9367f59d..13e1efb9 100644 --- a/packages/main/rollup.config.mjs +++ b/packages/main/rollup.config.mjs @@ -23,6 +23,7 @@ import pkg from "./package.json" assert { type: "json" }; const es2017BuildPlugins = [ typescriptPlugin({ + clean: true, typescript, tsconfigOverride: { compilerOptions: { @@ -41,7 +42,6 @@ const es2017BuildPlugins = [ const esmBuilds = [ { - clean: true, input: "src/index.ts", output: { file: pkg.module, @@ -55,7 +55,6 @@ const esmBuilds = [ const cjsBuilds = [ { - clean: true, input: "src/index.ts", output: [{ file: pkg.main, format: "cjs", sourcemap: true }], external: ["fs"], @@ -65,7 +64,6 @@ const cjsBuilds = [ const serverBuilds = [ { - clean: true, input: "src/server/index.ts", output: [ { file: pkg.exports["./server"].import, format: "es", sourcemap: true }, @@ -74,7 +72,6 @@ const serverBuilds = [ plugins: [...es2017BuildPlugins], }, { - clean: true, input: "src/server/index.ts", output: [ { file: pkg.exports["./server"].require, format: "cjs", sourcemap: true }, diff --git a/packages/main/server/package.json b/packages/main/server/package.json index 68af6537..f4a801ec 100644 --- a/packages/main/server/package.json +++ b/packages/main/server/package.json @@ -1,6 +1,6 @@ { "name": "@google/generative-ai-server", - "description": "GoogleAI file upload manager", + "description": "GoogleAI JS server-environment-only features", "main": "../dist/server/index.js", "browser": "../dist/server/index.mjs", "module": "../dist/server/index.mjs", diff --git a/packages/main/src/gen-ai.ts b/packages/main/src/gen-ai.ts index 5aea6dfa..2cc34703 100644 --- a/packages/main/src/gen-ai.ts +++ b/packages/main/src/gen-ai.ts @@ -15,7 +15,10 @@ * limitations under the License. */ -import { GoogleGenerativeAIError } from "./errors"; +import { + GoogleGenerativeAIError, + GoogleGenerativeAIRequestInputError, +} from "./errors"; import { CachedContent, ModelParams, RequestOptions } from "../types"; import { GenerativeModel } from "./models/generative-model"; @@ -52,6 +55,16 @@ export class GoogleGenerativeAI { cachedContent: CachedContent, requestOptions?: RequestOptions, ): GenerativeModel { + if (!cachedContent.name) { + throw new GoogleGenerativeAIRequestInputError( + "Cached content must contain a `name` field.", + ); + } + if (!cachedContent.model) { + throw new GoogleGenerativeAIRequestInputError( + "Cached content must contain a `model` field.", + ); + } const modelParamsFromCache: ModelParams = { model: cachedContent.model, tools: cachedContent.tools, diff --git a/packages/main/src/requests/request.ts b/packages/main/src/requests/request.ts index 9eeeadcf..9249aba0 100644 --- a/packages/main/src/requests/request.ts +++ b/packages/main/src/requests/request.ts @@ -170,7 +170,7 @@ export async function makeRequest( return response; } -export function handleResponseError(e: Error, url: string): void { +function handleResponseError(e: Error, url: string): void { let err = e; if ( !( @@ -186,7 +186,7 @@ export function handleResponseError(e: Error, url: string): void { throw err; } -export async function handleResponseNotOk( +async function handleResponseNotOk( response: Response, url: string, ): Promise { diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts index 775f7350..5b73c068 100644 --- a/packages/main/src/server/cache-manager.ts +++ b/packages/main/src/server/cache-manager.ts @@ -36,10 +36,10 @@ import { ListParams, } from "../../types/server"; import { RpcTask } from "./constants"; -import { GoogleGenerativeAIError } from "../errors"; +import { GoogleGenerativeAIError, GoogleGenerativeAIRequestInputError } from "../errors"; /** - * Class for managing GoogleAI file uploads. + * Class for managing GoogleAI content caches. * @public */ export class GoogleAICacheManager { @@ -65,6 +65,11 @@ export class GoogleAICacheManager { newCachedContent.ttl = createOptions.ttlSeconds.toString() + "s"; delete (newCachedContent as CachedContentCreateParams).ttlSeconds; } + if (!newCachedContent.model) { + throw new GoogleGenerativeAIRequestInputError( + "Cached content must contain a `model` field.", + ); + } if (!newCachedContent.model.includes("/")) { // If path is not included, assume it's a non-tuned model. newCachedContent.model = `models/${newCachedContent.model}`; @@ -75,11 +80,11 @@ export class GoogleAICacheManager { this._requestOptions, ); - const uploadHeaders = getHeaders(url); + const headers = getHeaders(url); const response = await makeServerRequest( url, - uploadHeaders, + headers, JSON.stringify(newCachedContent), ); return response.json(); @@ -100,8 +105,8 @@ export class GoogleAICacheManager { if (listParams?.pageToken) { url.appendParam("pageToken", listParams.pageToken); } - const uploadHeaders = getHeaders(url); - const response = await makeServerRequest(url, uploadHeaders); + const headers = getHeaders(url); + const response = await makeServerRequest(url, headers); return response.json(); } @@ -115,8 +120,8 @@ export class GoogleAICacheManager { this._requestOptions, ); url.appendPath(parseCacheName(name)); - const uploadHeaders = getHeaders(url); - const response = await makeServerRequest(url, uploadHeaders); + const headers = getHeaders(url); + const response = await makeServerRequest(url, headers); return response.json(); } @@ -133,10 +138,10 @@ export class GoogleAICacheManager { this._requestOptions, ); url.appendPath(parseCacheName(name)); - const uploadHeaders = getHeaders(url); + const headers = getHeaders(url); const response = await makeServerRequest( url, - uploadHeaders, + headers, JSON.stringify(updateParams), ); return response.json(); @@ -152,13 +157,13 @@ export class GoogleAICacheManager { this._requestOptions, ); url.appendPath(parseCacheName(name)); - const uploadHeaders = getHeaders(url); - await makeServerRequest(url, uploadHeaders); + const headers = getHeaders(url); + await makeServerRequest(url, headers); } } /** - * If fileId is prepended with "files/", remove prefix + * If cache name is prepended with "cachedContents/", remove prefix */ function parseCacheName(name: string): string { if (name.startsWith("cachedContents/")) { diff --git a/packages/main/types/server/index.ts b/packages/main/types/server/index.ts index 2bc04922..cb4cfabe 100644 --- a/packages/main/types/server/index.ts +++ b/packages/main/types/server/index.ts @@ -21,3 +21,4 @@ export * from "./shared"; export { RequestOptions } from "../../types/requests"; export * from "../../types/content"; +export { FunctionCallingMode } from '../../types/enums'; From 6779a372c851094f8c15548db3d273a2345b9d64 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Thu, 6 Jun 2024 14:17:49 -0700 Subject: [PATCH 09/14] format --- packages/main/src/server/cache-manager.ts | 5 ++++- packages/main/types/server/index.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts index 5b73c068..893b8524 100644 --- a/packages/main/src/server/cache-manager.ts +++ b/packages/main/src/server/cache-manager.ts @@ -36,7 +36,10 @@ import { ListParams, } from "../../types/server"; import { RpcTask } from "./constants"; -import { GoogleGenerativeAIError, GoogleGenerativeAIRequestInputError } from "../errors"; +import { + GoogleGenerativeAIError, + GoogleGenerativeAIRequestInputError, +} from "../errors"; /** * Class for managing GoogleAI content caches. diff --git a/packages/main/types/server/index.ts b/packages/main/types/server/index.ts index cb4cfabe..6a71c968 100644 --- a/packages/main/types/server/index.ts +++ b/packages/main/types/server/index.ts @@ -21,4 +21,4 @@ export * from "./shared"; export { RequestOptions } from "../../types/requests"; export * from "../../types/content"; -export { FunctionCallingMode } from '../../types/enums'; +export { FunctionCallingMode } from "../../types/enums"; From ba626a634f9f771d3dc13d095b2e2e18b3722e79 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 7 Jun 2024 14:28:52 -0700 Subject: [PATCH 10/14] add unit tests and sample --- common/api-review/generative-ai-server.api.md | 15 +- common/api-review/generative-ai.api.md | 2 +- .../main/src/server/cache-manager.test.ts | 302 ++++++++++++++++++ packages/main/src/server/cache-manager.ts | 35 +- packages/main/types/server/caching.ts | 22 +- samples/node/content-caching.js | 70 ++++ samples/node/file-upload.js | 4 +- 7 files changed, 428 insertions(+), 22 deletions(-) create mode 100644 packages/main/src/server/cache-manager.test.ts create mode 100644 samples/node/content-caching.js diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md index d69b6d61..10cecbfa 100644 --- a/common/api-review/generative-ai-server.api.md +++ b/common/api-review/generative-ai-server.api.md @@ -7,7 +7,6 @@ // @public export interface CachedContent extends CachedContentBase { createTime?: string; - expireTime?: string; // (undocumented) name?: string; ttl?: string; @@ -18,6 +17,7 @@ export interface CachedContent extends CachedContentBase { export interface CachedContentBase { // (undocumented) contents: Content[]; + expireTime?: string; // (undocumented) model?: string; // (undocumented) @@ -37,7 +37,16 @@ export interface CachedContentCreateParams extends CachedContentBase { export interface CachedContentUpdateParams { // (undocumented) cachedContent: CachedContentCreateParams; - updateMask: string[]; + updateMask?: string[]; +} + +// Warning: (ae-internal-missing-underscore) The name "CachedContentUpdateRequest" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal +export interface CachedContentUpdateRequest { + // (undocumented) + cachedContent: CachedContent; + updateMask?: string[]; } // @public @@ -241,7 +250,7 @@ export interface GenerativeContentBlob { // @public export class GoogleAICacheManager { - constructor(apiKey: string, _requestOptions: RequestOptions); + constructor(apiKey: string, _requestOptions?: RequestOptions); // (undocumented) apiKey: string; create(createOptions: CachedContentCreateParams): Promise; diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index fa7daaab..26eaa630 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -37,7 +37,6 @@ export enum BlockReason { // @public export interface CachedContent extends CachedContentBase { createTime?: string; - expireTime?: string; // (undocumented) name?: string; ttl?: string; @@ -48,6 +47,7 @@ export interface CachedContent extends CachedContentBase { export interface CachedContentBase { // (undocumented) contents: Content[]; + expireTime?: string; // (undocumented) model?: string; // (undocumented) diff --git a/packages/main/src/server/cache-manager.test.ts b/packages/main/src/server/cache-manager.test.ts new file mode 100644 index 00000000..a0671666 --- /dev/null +++ b/packages/main/src/server/cache-manager.test.ts @@ -0,0 +1,302 @@ +/** + * @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. + */ +import { expect, use } from "chai"; +import { GoogleAICacheManager } from "./cache-manager"; +import * as sinonChai from "sinon-chai"; +import * as chaiAsPromised from "chai-as-promised"; +import { restore, stub } from "sinon"; +import * as request from "./request"; +import { RpcTask } from "./constants"; +import { DEFAULT_API_VERSION } from "../requests/request"; + +use(sinonChai); +use(chaiAsPromised); + +const FAKE_CONTENTS = [{ role: "user", parts: [{ text: "some text" }] }]; +const FAKE_CACHE_NAME = "cachedContents/hash1234"; +const fakeResponseJson: () => Promise<{}> = () => + Promise.resolve({ name: FAKE_CACHE_NAME }); + +describe("GoogleAICacheManager", () => { + afterEach(() => { + restore(); + }); + + it("stores api key", () => { + const cacheManager = new GoogleAICacheManager("apiKey"); + expect(cacheManager.apiKey).to.equal("apiKey"); + }); + it("passes create request info", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + const result = await cacheManager.create({ + model: "models/gemini-1.5-pro", + contents: FAKE_CONTENTS, + ttlSeconds: 30, + systemInstruction: "talk like a cat", + tools: [{ functionDeclarations: [{ name: "myFn" }] }], + toolConfig: { functionCallingConfig: {} }, + }); + expect(result.name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.CREATE); + expect(makeRequestStub.args[0][1]).to.be.instanceOf(Headers); + const requestBody = JSON.parse(makeRequestStub.args[0][2] as string); + expect(requestBody.model).to.equal("models/gemini-1.5-pro"); + expect(requestBody.contents).to.deep.equal(FAKE_CONTENTS); + expect(requestBody.ttl).to.deep.equal("30s"); + expect(requestBody.systemInstruction).to.deep.equal("talk like a cat"); + expect(requestBody.tools[0].functionDeclarations[0].name).to.equal("myFn"); + expect(requestBody.toolConfig.functionCallingConfig).to.exist; + }); + it("create() formats unprefixed model name", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + await cacheManager.create({ + model: "gemini-1.5-pro", + contents: FAKE_CONTENTS, + }); + const requestBody = JSON.parse(makeRequestStub.args[0][2] as string); + expect(requestBody.model).to.equal("models/gemini-1.5-pro"); + }); + it("create() errors without a model name", async () => { + const cacheManager = new GoogleAICacheManager("apiKey"); + await expect( + cacheManager.create({ + contents: FAKE_CONTENTS, + }), + ).to.be.rejectedWith("Cached content must contain a `model` field."); + }); + it("create() errors if ttlSeconds and expireTime are both provided", async () => { + const cacheManager = new GoogleAICacheManager("apiKey"); + await expect( + cacheManager.create({ + model: "gemini-1.5-pro", + contents: FAKE_CONTENTS, + ttlSeconds: 40, + expireTime: new Date().toISOString(), + }), + ).to.be.rejectedWith("You cannot specify"); + }); + it("passes create request info (with options)", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey", { + apiVersion: "v3000", + baseUrl: "http://mysite.com", + }); + await cacheManager.create({ + model: "gemini-1.5-pro", + contents: FAKE_CONTENTS, + }); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.CREATE); + expect(makeRequestStub.args[0][1]).to.be.instanceOf(Headers); + expect(makeRequestStub.args[0][0].toString()).to.include( + "v3000/cachedContents", + ); + expect(makeRequestStub.args[0][0].toString()).to.match( + /^http:\/\/mysite\.com/, + ); + }); + it("passes update request info", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + const result = await cacheManager.update(FAKE_CACHE_NAME, { + cachedContent: { + model: "models/gemini-1.5-pro", + contents: FAKE_CONTENTS, + ttlSeconds: 30, + systemInstruction: "talk like a cat", + tools: [{ functionDeclarations: [{ name: "myFn" }] }], + toolConfig: { functionCallingConfig: {} }, + }, + }); + expect(result.name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.UPDATE); + expect(makeRequestStub.args[0][1]).to.be.instanceOf(Headers); + const requestBody = JSON.parse(makeRequestStub.args[0][2] as string); + const requestCache = requestBody.cachedContent; + expect(requestCache.model).to.equal("models/gemini-1.5-pro"); + expect(requestCache.contents).to.deep.equal(FAKE_CONTENTS); + expect(requestCache.ttl).to.deep.equal("30s"); + expect(requestCache.systemInstruction).to.deep.equal("talk like a cat"); + expect(requestCache.tools[0].functionDeclarations[0].name).to.equal("myFn"); + expect(requestCache.toolConfig.functionCallingConfig).to.exist; + }); + it("passes list request info", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: () => + Promise.resolve({ cachedContents: [{ name: FAKE_CACHE_NAME }] }), + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + const result = await cacheManager.list(); + expect(result.cachedContents[0].name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.LIST); + expect(makeRequestStub.args[0][0].toString()).to.match(/\/cachedContents$/); + }); + it("passes list request info with params", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: () => + Promise.resolve({ cachedContents: [{ name: FAKE_CACHE_NAME }] }), + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + const result = await cacheManager.list({ + pageSize: 3, + pageToken: "abc", + }); + expect(result.cachedContents[0].name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.LIST); + expect(makeRequestStub.args[0][0].toString()).to.include("pageSize=3"); + expect(makeRequestStub.args[0][0].toString()).to.include("pageToken=abc"); + }); + it("passes list request info with options", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: () => + Promise.resolve({ cachedContents: [{ name: FAKE_CACHE_NAME }] }), + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey", { + apiVersion: "v3000", + baseUrl: "http://mysite.com", + }); + const result = await cacheManager.list(); + expect(result.cachedContents[0].name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.LIST); + expect(makeRequestStub.args[0][0].toString()).to.match(/\/cachedContents$/); + expect(makeRequestStub.args[0][0].toString()).to.include( + "v3000/cachedContents", + ); + expect(makeRequestStub.args[0][0].toString()).to.match( + /^http:\/\/mysite\.com/, + ); + }); + it("passes get request info with name prefix provided", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + const result = await cacheManager.get("cachedContents/hash1234"); + expect(result.name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.GET); + expect(makeRequestStub.args[0][0].toString()).to.include( + `${DEFAULT_API_VERSION}/cachedContents/hash1234`, + ); + }); + it("passes get request info with no name prefix", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + const result = await cacheManager.get("hash1234"); + expect(result.name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.GET); + expect(makeRequestStub.args[0][0].toString()).to.include( + `${DEFAULT_API_VERSION}/cachedContents/hash1234`, + ); + }); + it("passes getFile request info (with options)", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey", { + apiVersion: "v3000", + baseUrl: "http://mysite.com", + }); + const result = await cacheManager.get("hash1234"); + expect(result.name).to.equal(FAKE_CACHE_NAME); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.GET); + expect(makeRequestStub.args[0][0].toString()).to.include( + "v3000/cachedContents/hash1234", + ); + expect(makeRequestStub.args[0][0].toString()).to.match( + /^http:\/\/mysite\.com/, + ); + }); + it("get throws on bad name", async () => { + stub(request, "makeServerRequest").resolves({ + ok: true, + json: fakeResponseJson, + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + await expect(cacheManager.get("")).to.be.rejectedWith("Invalid name"); + }); + it("passes delete request info (no prefix)", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: () => Promise.resolve({}), + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + await cacheManager.delete("hash1234"); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.DELETE); + expect(makeRequestStub.args[0][0].toString()).to.include( + `${DEFAULT_API_VERSION}/cachedContents/hash1234`, + ); + }); + it("passes delete request info (prefix)", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: () => Promise.resolve({}), + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + await cacheManager.delete("cachedContents/hash1234"); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.DELETE); + expect(makeRequestStub.args[0][0].toString()).to.include( + `${DEFAULT_API_VERSION}/cachedContents/hash1234`, + ); + }); + it("passes delete request info (with options)", async () => { + const makeRequestStub = stub(request, "makeServerRequest").resolves({ + ok: true, + json: () => Promise.resolve({}), + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey", { + apiVersion: "v3000", + baseUrl: "http://mysite.com", + }); + await cacheManager.delete("hash1234"); + expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.DELETE); + expect(makeRequestStub.args[0][0].toString()).to.include( + "v3000/cachedContents/hash1234", + ); + expect(makeRequestStub.args[0][0].toString()).to.match( + /^http:\/\/mysite\.com/, + ); + }); + it("delete throws on bad name", async () => { + stub(request, "makeServerRequest").resolves({ + ok: true, + json: () => Promise.resolve({}), + } as Response); + const cacheManager = new GoogleAICacheManager("apiKey"); + await expect(cacheManager.delete("")).to.be.rejectedWith("Invalid name"); + }); +}); diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts index 893b8524..8ea7dfad 100644 --- a/packages/main/src/server/cache-manager.ts +++ b/packages/main/src/server/cache-manager.ts @@ -23,15 +23,11 @@ import { Tool, ToolConfig, } from "../../types"; -import { - CachedContentUrl, - FilesRequestUrl, - getHeaders, - makeServerRequest, -} from "./request"; +import { CachedContentUrl, getHeaders, makeServerRequest } from "./request"; import { CachedContentCreateParams, CachedContentUpdateParams, + CachedContentUpdateRequest, ListCacheResponse, ListParams, } from "../../types/server"; @@ -54,7 +50,7 @@ export class GoogleAICacheManager { constructor( public apiKey: string, - private _requestOptions: RequestOptions, + private _requestOptions?: RequestOptions, ) {} /** @@ -65,6 +61,12 @@ export class GoogleAICacheManager { ): Promise { const newCachedContent: CachedContent = { ...createOptions }; if (createOptions.ttlSeconds) { + if (createOptions.expireTime) { + throw new GoogleGenerativeAIRequestInputError( + "You cannot specify both `ttlSeconds` and `expireTime` when creating" + + " a content cache. You must choose one.", + ); + } newCachedContent.ttl = createOptions.ttlSeconds.toString() + "s"; delete (newCachedContent as CachedContentCreateParams).ttlSeconds; } @@ -78,7 +80,7 @@ export class GoogleAICacheManager { newCachedContent.model = `models/${newCachedContent.model}`; } const url = new CachedContentUrl( - RpcTask.UPLOAD, + RpcTask.CREATE, this.apiKey, this._requestOptions, ); @@ -142,10 +144,22 @@ export class GoogleAICacheManager { ); url.appendPath(parseCacheName(name)); const headers = getHeaders(url); + const formattedCachedContent: CachedContent = { + ...updateParams.cachedContent, + }; + if (updateParams.cachedContent.ttlSeconds) { + formattedCachedContent.ttl = + updateParams.cachedContent.ttlSeconds.toString() + "s"; + delete (formattedCachedContent as CachedContentCreateParams).ttlSeconds; + } + const updateRequest: CachedContentUpdateRequest = { + cachedContent: formattedCachedContent, + updateMask: updateParams.updateMask, + }; const response = await makeServerRequest( url, headers, - JSON.stringify(updateParams), + JSON.stringify(updateRequest), ); return response.json(); } @@ -154,7 +168,7 @@ export class GoogleAICacheManager { * Delete content cache with given name */ async delete(name: string): Promise { - const url = new FilesRequestUrl( + const url = new CachedContentUrl( RpcTask.DELETE, this.apiKey, this._requestOptions, @@ -178,6 +192,5 @@ function parseCacheName(name: string): string { `Must be in the format "cachedContents/name" or "name"`, ); } - return name; } diff --git a/packages/main/types/server/caching.ts b/packages/main/types/server/caching.ts index 696e0443..6f55605e 100644 --- a/packages/main/types/server/caching.ts +++ b/packages/main/types/server/caching.ts @@ -26,6 +26,10 @@ export interface CachedContentBase { tools?: Tool[]; toolConfig?: ToolConfig; systemInstruction?: string | Part | Content; + /** + * Expiration time in ISO string format. Specify either this or `ttl`. + */ + expireTime?: string; } /** @@ -40,10 +44,6 @@ export interface CachedContent extends CachedContentBase { * `expireTime`. */ ttl?: string; - /** - * Expiration time in ISO string format. Specify either this or `ttl`. - */ - expireTime?: string; /** * CachedContent creation time in ISO string format */ @@ -74,7 +74,19 @@ export interface CachedContentUpdateParams { /** * protobuf FieldMask */ - updateMask: string[]; + updateMask?: string[]; +} + +/** + * Params as sent to the backend (ttl instead of ttlSeconds) + * @internal + */ +export interface CachedContentUpdateRequest { + cachedContent: CachedContent; + /** + * protobuf FieldMask + */ + updateMask?: string[]; } /** diff --git a/samples/node/content-caching.js b/samples/node/content-caching.js new file mode 100644 index 00000000..fb70cee6 --- /dev/null +++ b/samples/node/content-caching.js @@ -0,0 +1,70 @@ +/** + * @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. + */ + +/** + * Example of uploading a content cache and referencing it in a call to + * generateContent(). + * + * NOTE: Creating and modifying content caches is a feature only available for + * use in Node. + */ + +import { GoogleAICacheManager } from "@google/generative-ai/server"; +import { genAI } from "./utils/common.js"; + +async function run() { + const cacheManager = new GoogleAICacheManager(process.env.API_KEY); + + // Generate a very long string + let longContentString = ""; + for (let i = 0; i < 32001; i++) { + longContentString += "Purple cats drink gatorade."; + longContentString += i % 8 === 7 ? "\n" : " "; + } + + const cacheResult = await cacheManager.create({ + ttlSeconds: 600, + model: "models/gemini-1.5-pro", + contents: [ + { + role: "user", + parts: [{ text: longContentString }], + }, + ], + }); + + const cache = await cacheManager.get(cacheResult.name); + + const model = genAI.getGenerativeModelFromCachedContent({ + cache, + }); + + const result = await model.generateContent({ + contents: [ + { + role: "user", + parts: [{ text: "What do purple cats drink?" }], + }, + ], + }); + + const response = result.response; + const text = response.text(); + console.log(text); +} + +run(); diff --git a/samples/node/file-upload.js b/samples/node/file-upload.js index d5162c05..8deccb9b 100644 --- a/samples/node/file-upload.js +++ b/samples/node/file-upload.js @@ -20,11 +20,11 @@ * generateContent(). * * NOTE: The Files API is only available for use in Node. - * Importing from `@google/generative-ai/files` will crash in the + * Importing GoogleAIFileManager will crash in the * browser. */ -import { GoogleAIFileManager } from "@google/generative-ai/files"; +import { GoogleAIFileManager } from "@google/generative-ai/server"; import { genAI } from "./utils/common.js"; async function run() { From ff297e03e93fdb03aa922f0ba247e62a2a39c3e0 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Fri, 7 Jun 2024 16:04:58 -0700 Subject: [PATCH 11/14] fix update method --- common/api-review/generative-ai-server.api.md | 32 +++++++++------ .../main/src/server/cache-manager.test.ts | 17 ++------ packages/main/src/server/cache-manager.ts | 40 +++++++++---------- packages/main/types/server/caching.ts | 24 +++++++++-- 4 files changed, 64 insertions(+), 49 deletions(-) diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md index 10cecbfa..d94aa993 100644 --- a/common/api-review/generative-ai-server.api.md +++ b/common/api-review/generative-ai-server.api.md @@ -33,10 +33,18 @@ export interface CachedContentCreateParams extends CachedContentBase { ttlSeconds?: number; } +// @public +export interface CachedContentUpdateInputFields { + // (undocumented) + expireTime?: string; + // (undocumented) + ttlSeconds?: number; +} + // @public export interface CachedContentUpdateParams { // (undocumented) - cachedContent: CachedContentCreateParams; + cachedContent: CachedContentUpdateInputFields; updateMask?: string[]; } @@ -45,10 +53,20 @@ export interface CachedContentUpdateParams { // @internal export interface CachedContentUpdateRequest { // (undocumented) - cachedContent: CachedContent; + 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 { + // (undocumented) + expireTime?: string; + // (undocumented) + ttl?: string; +} + // @public export interface Content { // (undocumented) @@ -257,16 +275,6 @@ export class GoogleAICacheManager { delete(name: string): Promise; get(name: string): Promise; list(listParams?: ListParams): Promise; - // (undocumented) - model: string; - // (undocumented) - systemInstruction?: string | Part | Content; - // (undocumented) - toolConfig?: ToolConfig; - // (undocumented) - tools?: Tool[]; - // (undocumented) - ttl?: string; update(name: string, updateParams: CachedContentUpdateParams): Promise; } diff --git a/packages/main/src/server/cache-manager.test.ts b/packages/main/src/server/cache-manager.test.ts index a0671666..7506f7b0 100644 --- a/packages/main/src/server/cache-manager.test.ts +++ b/packages/main/src/server/cache-manager.test.ts @@ -61,7 +61,9 @@ describe("GoogleAICacheManager", () => { expect(requestBody.model).to.equal("models/gemini-1.5-pro"); expect(requestBody.contents).to.deep.equal(FAKE_CONTENTS); expect(requestBody.ttl).to.deep.equal("30s"); - expect(requestBody.systemInstruction).to.deep.equal("talk like a cat"); + expect(requestBody.systemInstruction.parts[0].text).to.equal( + "talk like a cat", + ); expect(requestBody.tools[0].functionDeclarations[0].name).to.equal("myFn"); expect(requestBody.toolConfig.functionCallingConfig).to.exist; }); @@ -127,25 +129,14 @@ describe("GoogleAICacheManager", () => { const cacheManager = new GoogleAICacheManager("apiKey"); const result = await cacheManager.update(FAKE_CACHE_NAME, { cachedContent: { - model: "models/gemini-1.5-pro", - contents: FAKE_CONTENTS, ttlSeconds: 30, - systemInstruction: "talk like a cat", - tools: [{ functionDeclarations: [{ name: "myFn" }] }], - toolConfig: { functionCallingConfig: {} }, }, }); expect(result.name).to.equal(FAKE_CACHE_NAME); expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.UPDATE); expect(makeRequestStub.args[0][1]).to.be.instanceOf(Headers); const requestBody = JSON.parse(makeRequestStub.args[0][2] as string); - const requestCache = requestBody.cachedContent; - expect(requestCache.model).to.equal("models/gemini-1.5-pro"); - expect(requestCache.contents).to.deep.equal(FAKE_CONTENTS); - expect(requestCache.ttl).to.deep.equal("30s"); - expect(requestCache.systemInstruction).to.deep.equal("talk like a cat"); - expect(requestCache.tools[0].functionDeclarations[0].name).to.equal("myFn"); - expect(requestCache.toolConfig.functionCallingConfig).to.exist; + expect(requestBody.ttl).to.deep.equal("30s"); }); it("passes list request info", async () => { const makeRequestStub = stub(request, "makeServerRequest").resolves({ diff --git a/packages/main/src/server/cache-manager.ts b/packages/main/src/server/cache-manager.ts index 8ea7dfad..5ba63448 100644 --- a/packages/main/src/server/cache-manager.ts +++ b/packages/main/src/server/cache-manager.ts @@ -15,19 +15,12 @@ * limitations under the License. */ -import { - CachedContent, - Content, - Part, - RequestOptions, - Tool, - ToolConfig, -} from "../../types"; +import { CachedContent, RequestOptions } from "../../types"; import { CachedContentUrl, getHeaders, makeServerRequest } from "./request"; import { CachedContentCreateParams, CachedContentUpdateParams, - CachedContentUpdateRequest, + CachedContentUpdateRequestFields, ListCacheResponse, ListParams, } from "../../types/server"; @@ -36,18 +29,13 @@ import { GoogleGenerativeAIError, GoogleGenerativeAIRequestInputError, } from "../errors"; +import { formatSystemInstruction } from "../requests/request-helpers"; /** * Class for managing GoogleAI content caches. * @public */ export class GoogleAICacheManager { - model: string; - ttl?: string; - tools?: Tool[]; - toolConfig?: ToolConfig; - systemInstruction?: string | Part | Content; - constructor( public apiKey: string, private _requestOptions?: RequestOptions, @@ -67,6 +55,11 @@ export class GoogleAICacheManager { " a content cache. You must choose one.", ); } + if (createOptions.systemInstruction) { + newCachedContent.systemInstruction = formatSystemInstruction( + createOptions.systemInstruction, + ); + } newCachedContent.ttl = createOptions.ttlSeconds.toString() + "s"; delete (newCachedContent as CachedContentCreateParams).ttlSeconds; } @@ -144,7 +137,7 @@ export class GoogleAICacheManager { ); url.appendPath(parseCacheName(name)); const headers = getHeaders(url); - const formattedCachedContent: CachedContent = { + const formattedCachedContent: CachedContentUpdateRequestFields = { ...updateParams.cachedContent, }; if (updateParams.cachedContent.ttlSeconds) { @@ -152,14 +145,16 @@ export class GoogleAICacheManager { updateParams.cachedContent.ttlSeconds.toString() + "s"; delete (formattedCachedContent as CachedContentCreateParams).ttlSeconds; } - const updateRequest: CachedContentUpdateRequest = { - cachedContent: formattedCachedContent, - updateMask: updateParams.updateMask, - }; + if (updateParams.updateMask) { + url.appendParam( + "update_mask", + updateParams.updateMask.map((prop) => camelToSnake(prop)).join(","), + ); + } const response = await makeServerRequest( url, headers, - JSON.stringify(updateRequest), + JSON.stringify(formattedCachedContent), ); return response.json(); } @@ -194,3 +189,6 @@ function parseCacheName(name: string): string { } return name; } +function camelToSnake(str: string): string { + return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`); +} diff --git a/packages/main/types/server/caching.ts b/packages/main/types/server/caching.ts index 6f55605e..5d33f5a4 100644 --- a/packages/main/types/server/caching.ts +++ b/packages/main/types/server/caching.ts @@ -65,24 +65,42 @@ export interface CachedContentCreateParams extends CachedContentBase { ttlSeconds?: number; } +/** + * Fields that can be updated in an existing content cache. + * @public + */ +export interface CachedContentUpdateInputFields { + ttlSeconds?: number; + expireTime?: string; +} + /** * Params to pass to {@link GoogleAICacheManager.update} * @public */ export interface CachedContentUpdateParams { - cachedContent: CachedContentCreateParams; + cachedContent: CachedContentUpdateInputFields; /** - * protobuf FieldMask + * protobuf FieldMask. If not specified, updates all provided fields. */ updateMask?: string[]; } +/** + * Fields that can be updated in an existing content cache. + * @internal + */ +export interface CachedContentUpdateRequestFields { + ttl?: string; + expireTime?: string; +} + /** * Params as sent to the backend (ttl instead of ttlSeconds) * @internal */ export interface CachedContentUpdateRequest { - cachedContent: CachedContent; + cachedContent: CachedContentUpdateRequestFields; /** * protobuf FieldMask */ From 39a4f8d73864448b84001f7aacefe2dfb1245bf6 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Mon, 17 Jun 2024 15:34:47 -0400 Subject: [PATCH 12/14] Add Integration Tests for Content Caching (#171) Updates to the Content Caching feature in development. - adds integration tests - adds display name to the creation of content caching. - fixes the use of a context cache in the sample implementation. Documentation PR is separate: #172 --- common/api-review/generative-ai-server.api.md | 2 + common/api-review/generative-ai.api.md | 2 + .../main/src/server/cache-manager.test.ts | 16 +- .../node/cache-content.test.ts | 258 ++++++++++++++++++ packages/main/types/server/caching.ts | 22 +- samples/node/content-caching.js | 6 +- 6 files changed, 286 insertions(+), 20 deletions(-) create mode 100644 packages/main/test-integration/node/cache-content.test.ts diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md index d94aa993..90bf503e 100644 --- a/common/api-review/generative-ai-server.api.md +++ b/common/api-review/generative-ai-server.api.md @@ -17,6 +17,8 @@ export interface CachedContent extends CachedContentBase { export interface CachedContentBase { // (undocumented) contents: Content[]; + // (undocumented) + displayName?: string; expireTime?: string; // (undocumented) model?: string; diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index 26eaa630..2e4edbbd 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -47,6 +47,8 @@ export interface CachedContent extends CachedContentBase { export interface CachedContentBase { // (undocumented) contents: Content[]; + // (undocumented) + displayName?: string; expireTime?: string; // (undocumented) model?: string; diff --git a/packages/main/src/server/cache-manager.test.ts b/packages/main/src/server/cache-manager.test.ts index 7506f7b0..727e1b00 100644 --- a/packages/main/src/server/cache-manager.test.ts +++ b/packages/main/src/server/cache-manager.test.ts @@ -30,6 +30,7 @@ const FAKE_CONTENTS = [{ role: "user", parts: [{ text: "some text" }] }]; const FAKE_CACHE_NAME = "cachedContents/hash1234"; const fakeResponseJson: () => Promise<{}> = () => Promise.resolve({ name: FAKE_CACHE_NAME }); +const model = "models/gemini-1.5-pro-001"; describe("GoogleAICacheManager", () => { afterEach(() => { @@ -41,26 +42,29 @@ describe("GoogleAICacheManager", () => { expect(cacheManager.apiKey).to.equal("apiKey"); }); it("passes create request info", async () => { + const displayName = "a display name."; const makeRequestStub = stub(request, "makeServerRequest").resolves({ ok: true, json: fakeResponseJson, } as Response); const cacheManager = new GoogleAICacheManager("apiKey"); const result = await cacheManager.create({ - model: "models/gemini-1.5-pro", + model, contents: FAKE_CONTENTS, ttlSeconds: 30, systemInstruction: "talk like a cat", tools: [{ functionDeclarations: [{ name: "myFn" }] }], toolConfig: { functionCallingConfig: {} }, + displayName, }); expect(result.name).to.equal(FAKE_CACHE_NAME); expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.CREATE); expect(makeRequestStub.args[0][1]).to.be.instanceOf(Headers); const requestBody = JSON.parse(makeRequestStub.args[0][2] as string); - expect(requestBody.model).to.equal("models/gemini-1.5-pro"); + expect(requestBody.model).to.equal(model); expect(requestBody.contents).to.deep.equal(FAKE_CONTENTS); expect(requestBody.ttl).to.deep.equal("30s"); + expect(requestBody.displayName).to.equal(displayName); expect(requestBody.systemInstruction.parts[0].text).to.equal( "talk like a cat", ); @@ -74,11 +78,11 @@ describe("GoogleAICacheManager", () => { } as Response); const cacheManager = new GoogleAICacheManager("apiKey"); await cacheManager.create({ - model: "gemini-1.5-pro", + model, contents: FAKE_CONTENTS, }); const requestBody = JSON.parse(makeRequestStub.args[0][2] as string); - expect(requestBody.model).to.equal("models/gemini-1.5-pro"); + expect(requestBody.model).to.equal(model); }); it("create() errors without a model name", async () => { const cacheManager = new GoogleAICacheManager("apiKey"); @@ -92,7 +96,7 @@ describe("GoogleAICacheManager", () => { const cacheManager = new GoogleAICacheManager("apiKey"); await expect( cacheManager.create({ - model: "gemini-1.5-pro", + model, contents: FAKE_CONTENTS, ttlSeconds: 40, expireTime: new Date().toISOString(), @@ -109,7 +113,7 @@ describe("GoogleAICacheManager", () => { baseUrl: "http://mysite.com", }); await cacheManager.create({ - model: "gemini-1.5-pro", + model, contents: FAKE_CONTENTS, }); expect(makeRequestStub.args[0][0].task).to.equal(RpcTask.CREATE); diff --git a/packages/main/test-integration/node/cache-content.test.ts b/packages/main/test-integration/node/cache-content.test.ts new file mode 100644 index 00000000..b6982a01 --- /dev/null +++ b/packages/main/test-integration/node/cache-content.test.ts @@ -0,0 +1,258 @@ +/** + * @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. + */ + +import { expect, use } from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import { GoogleGenerativeAI } from "../.."; +import { GoogleAICacheManager } from "../../server"; //= require("@google/generative-ai/server"); + +use(chaiAsPromised); + +/** + * Integration tests against live backend. + */ + +describe("cacheContent", function () { + this.timeout(60e3); + this.slow(10e3); + const model = "models/gemini-1.5-pro-001"; + let text: string = ""; + + // Minimum cache size is 32768 tokens. + for (let i = 0; i < 6554; i++) { + text += "Purple cats drink chicken soup."; + text += i % 8 === 7 ? "\n" : " "; + } + it("createCache", async () => { + // cacheManager create + const ttlSeconds = 5; + const displayName = "A display name."; + const cacheManager = new GoogleAICacheManager( + process.env.GEMINI_API_KEY || "", + ); + const createCacheResult = await cacheManager.create({ + ttlSeconds, + model, + contents: [ + { + role: "user", + parts: [{ text }], + }, + ], + displayName, + }); + expect(createCacheResult.name).to.exist; + expect(createCacheResult.model).to.exist; + expect(createCacheResult.createTime).to.exist; + expect(createCacheResult.updateTime).to.exist; + expect(createCacheResult.expireTime).to.exist; + expect(createCacheResult.displayName).to.exist.and.equal(displayName); + expect(createCacheResult.name.startsWith("cachedContents/")).to.be.true; + const createdTime = Date.parse(createCacheResult.createTime); + const expireTime = Date.parse(createCacheResult.expireTime); + expect(expireTime - createdTime).to.be.lessThanOrEqual(ttlSeconds * 1000); + }); + it("cacheManager list", async () => { + // cacheManager create + const displayName = new Date().toISOString(); + const cacheManager = new GoogleAICacheManager( + process.env.GEMINI_API_KEY || "", + ); + const createCacheResult = await cacheManager.create({ + ttlSeconds: 5, + model, + contents: [ + { + role: "user", + parts: [{ text }], + }, + ], + displayName, + }); + expect(createCacheResult.name).to.exist; + expect(createCacheResult.displayName).to.exist.and.equal(displayName); + expect(createCacheResult.name.startsWith("cachedContents/")).to.be.true; + + // List + const listResult = await cacheManager.list(); + expect(listResult.cachedContents).to.exist; + expect( + listResult.cachedContents.map((e) => ({ name: e.name })), + ).to.deep.include({ name: createCacheResult.name }); + expect( + listResult.cachedContents.map((e) => ({ displayName: e.displayName })), + ).to.deep.include({ displayName }); + }); + it("cacheManager get", async () => { + // cacheManager create + const displayName = new Date().toISOString(); + const cacheManager = new GoogleAICacheManager( + process.env.GEMINI_API_KEY || "", + ); + const createCacheResult = await cacheManager.create({ + ttlSeconds: 5, + model, + contents: [ + { + role: "user", + parts: [{ text }], + }, + ], + displayName, + }); + expect(createCacheResult.name).to.exist; + expect(createCacheResult.displayName).to.exist.and.equal(displayName); + expect(createCacheResult.name.startsWith("cachedContents/")).to.be.true; + + // cacheManager.get + const cache = await cacheManager.get(createCacheResult.name); + expect(cache.name).to.equal(createCacheResult.name); + expect(cache.model).to.equal(createCacheResult.model); + expect(cache.createTime).to.equal(createCacheResult.createTime); + expect(cache.updateTime).to.equal(createCacheResult.updateTime); + expect(cache.expireTime).to.equal(createCacheResult.expireTime); + expect(cache.displayName).to.exist.and.equal(displayName); + }); + it("cacheManager update ttl then get", async () => { + // cacheManager create + const displayName = new Date().toISOString(); + const originalTtlSeconds = 20; + const cacheManager = new GoogleAICacheManager( + process.env.GEMINI_API_KEY || "", + ); + const createCacheResult = await cacheManager.create({ + ttlSeconds: originalTtlSeconds, + model, + contents: [ + { + role: "user", + parts: [{ text }], + }, + ], + displayName, + }); + expect(createCacheResult.name).to.exist; + expect(createCacheResult.name.startsWith("cachedContents/")).to.be.true; + expect(createCacheResult.displayName).to.exist.and.equal(displayName); + + // cacheManager.update + const newTtlSeconds = originalTtlSeconds + 10; + const updateParams = { cachedContent: { ttlSeconds: newTtlSeconds } }; + const updateResult = await cacheManager.update( + createCacheResult.name, + updateParams, + ); + + // cacheManager.get + const cache = await cacheManager.get(createCacheResult.name); + expect(cache.name).to.equal(createCacheResult.name); + expect(cache.name).to.equal(updateResult.name); + expect(cache.model).to.equal(createCacheResult.model); + expect(cache.model).to.equal(updateResult.model); + expect(cache.createTime).to.equal(createCacheResult.createTime); + expect(cache.updateTime).to.not.equal(createCacheResult.updateTime); + expect(cache.updateTime).to.equal(updateResult.updateTime); + expect(cache.expireTime).to.not.equal(createCacheResult.expireTime); + expect(cache.expireTime).to.equal(updateResult.expireTime); + expect(cache.displayName).to.exist.and.equal(displayName); + const createdTime = Date.parse(createCacheResult.createTime); + const expireTime = Date.parse(createCacheResult.expireTime); + const updatedTime = Date.parse(cache.updateTime); + expect(expireTime - createdTime).to.be.lessThanOrEqual( + originalTtlSeconds * 1000, + ); + expect(expireTime - updatedTime).to.be.lessThanOrEqual( + newTtlSeconds * 1000, + ); + }); + it("cacheManager update expireTime then get", async () => { + // cacheManager create + const cacheManager = new GoogleAICacheManager( + process.env.GEMINI_API_KEY || "", + ); + const createCacheResult = await cacheManager.create({ + ttlSeconds: 20, + model, + contents: [ + { + role: "user", + parts: [{ text }], + }, + ], + }); + expect(createCacheResult.name).to.exist; + expect(createCacheResult.name.startsWith("cachedContents/")).to.be.true; + expect(createCacheResult.displayName).to.equal(""); + + // cacheManager.update + const newExpirationTime = new Date(new Date().getTime() + 30 * 1000); + const updateParams = { + cachedContent: { expireTime: newExpirationTime.toISOString() }, + }; + const updateResult = await cacheManager.update( + createCacheResult.name, + updateParams, + ); + + // cacheManager.get + const cache = await cacheManager.get(createCacheResult.name); + expect(cache.name).to.equal(createCacheResult.name); + expect(cache.name).to.equal(updateResult.name); + expect(cache.model).to.equal(createCacheResult.model); + expect(cache.model).to.equal(updateResult.model); + expect(cache.createTime).to.equal(createCacheResult.createTime); + expect(cache.updateTime).to.not.equal(createCacheResult.updateTime); + expect(cache.updateTime).to.equal(updateResult.updateTime); + expect(cache.expireTime).to.not.equal(createCacheResult.expireTime); + expect(cache.expireTime).to.equal(updateResult.expireTime); + }); + it("generateContentWithCache", async () => { + const cacheManager = new GoogleAICacheManager( + process.env.GEMINI_API_KEY || "", + ); + const createCacheResult = await cacheManager.create({ + ttlSeconds: 20, + model, + contents: [ + { + role: "user", + parts: [{ text }], + }, + ], + }); + expect(createCacheResult.name).to.exist; + const cacheName = createCacheResult.name; + expect(cacheName.startsWith("cachedContents/")).to.be.true; + + // cacheManager.get + const cache = await cacheManager.get(cacheName); + + // generate content. + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY); + const genAiModel = genAI.getGenerativeModelFromCachedContent(cache); + const result = await genAiModel.generateContent({ + contents: [ + { + role: "user", + parts: [{ text: "What do purple cats drink?" }], + }, + ], + }); + const response = await result.response; + expect(response.text().toLowerCase().includes("chicken soup")).to.be.true; + }); +}); diff --git a/packages/main/types/server/caching.ts b/packages/main/types/server/caching.ts index 5d33f5a4..bd5ce829 100644 --- a/packages/main/types/server/caching.ts +++ b/packages/main/types/server/caching.ts @@ -27,40 +27,42 @@ export interface CachedContentBase { toolConfig?: ToolConfig; systemInstruction?: string | Part | Content; /** - * Expiration time in ISO string format. Specify either this or `ttl`. + * Expiration time in ISO string format. Specify either this or `ttlSeconds` + * when creating a `CachedContent`. */ expireTime?: string; + displayName?: string; } /** - * Describes CachedContent interface for sending to the server (if creating) + * Describes `CachedContent` interface for sending to the server (if creating) * or received from the server (using getters or list methods). * @public */ export interface CachedContent extends CachedContentBase { name?: string; /** - * protobuf.Duration format (ex. "3.0001s"). Specify either this or - * `expireTime`. + * protobuf.Duration format (ex. "3.0001s"). */ ttl?: string; /** - * CachedContent creation time in ISO string format + * `CachedContent` creation time in ISO string format. */ createTime?: string; /** - * CachedContent update time in ISO string format + * `CachedContent` update time in ISO string format. */ updateTime?: string; } /** - * Params to pass to {@link GoogleAICacheManager.create} + * Params to pass to {@link GoogleAICacheManager.create}. * @public */ export interface CachedContentCreateParams extends CachedContentBase { /** - * CachedContent ttl in seconds. + * `CachedContent` ttl in seconds. Specify either this or `expireTime` + * when creating a `CachedContent`. */ ttlSeconds?: number; } @@ -75,7 +77,7 @@ export interface CachedContentUpdateInputFields { } /** - * Params to pass to {@link GoogleAICacheManager.update} + * Params to pass to {@link GoogleAICacheManager.update}. * @public */ export interface CachedContentUpdateParams { @@ -96,7 +98,7 @@ export interface CachedContentUpdateRequestFields { } /** - * Params as sent to the backend (ttl instead of ttlSeconds) + * Params as sent to the backend (ttl instead of ttlSeconds). * @internal */ export interface CachedContentUpdateRequest { diff --git a/samples/node/content-caching.js b/samples/node/content-caching.js index fb70cee6..a2dbd670 100644 --- a/samples/node/content-caching.js +++ b/samples/node/content-caching.js @@ -38,7 +38,7 @@ async function run() { const cacheResult = await cacheManager.create({ ttlSeconds: 600, - model: "models/gemini-1.5-pro", + model: "models/gemini-1.5-pro-001", contents: [ { role: "user", @@ -49,9 +49,7 @@ async function run() { const cache = await cacheManager.get(cacheResult.name); - const model = genAI.getGenerativeModelFromCachedContent({ - cache, - }); + const model = genAI.getGenerativeModelFromCachedContent(cache); const result = await model.generateContent({ contents: [ From 8f5c338af523d715b94d68f5e4b73e1ff545a10c Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Mon, 17 Jun 2024 15:38:05 -0400 Subject: [PATCH 13/14] Cached Content generated documentation (#172) An isolated pull request with the Cached Content documentation. --- .../generative-ai.cachedcontent.createtime.md | 13 ++++ .../main/generative-ai.cachedcontent.md | 24 +++++++ .../main/generative-ai.cachedcontent.name.md | 11 ++++ .../main/generative-ai.cachedcontent.ttl.md | 13 ++++ .../generative-ai.cachedcontent.updatetime.md | 13 ++++ ...enerative-ai.cachedcontentbase.contents.md | 11 ++++ ...rative-ai.cachedcontentbase.displayname.md | 11 ++++ ...erative-ai.cachedcontentbase.expiretime.md | 13 ++++ .../main/generative-ai.cachedcontentbase.md | 25 +++++++ .../generative-ai.cachedcontentbase.model.md | 11 ++++ ...-ai.cachedcontentbase.systeminstruction.md | 11 ++++ ...erative-ai.cachedcontentbase.toolconfig.md | 11 ++++ .../generative-ai.cachedcontentbase.tools.md | 11 ++++ ...ai.generatecontentrequest.cachedcontent.md | 13 ++++ .../generative-ai.generatecontentrequest.md | 1 + ...rative-ai.generativemodel.cachedcontent.md | 11 ++++ .../main/generative-ai.generativemodel.md | 1 + ...eai.getgenerativemodelfromcachedcontent.md | 25 +++++++ .../main/generative-ai.googlegenerativeai.md | 1 + docs/reference/main/generative-ai.md | 4 +- ...generative-ai.modelparams.cachedcontent.md | 11 ++++ .../main/generative-ai.modelparams.md | 1 + .../main/generative-ai.responseschema.md | 2 +- ...rative-ai.startchatparams.cachedcontent.md | 13 ++++ .../main/generative-ai.startchatparams.md | 1 + .../generative-ai.cachedcontent.createtime.md | 13 ++++ .../server/generative-ai.cachedcontent.md | 24 +++++++ .../generative-ai.cachedcontent.name.md | 11 ++++ .../server/generative-ai.cachedcontent.ttl.md | 13 ++++ .../generative-ai.cachedcontent.updatetime.md | 13 ++++ ...enerative-ai.cachedcontentbase.contents.md | 11 ++++ ...rative-ai.cachedcontentbase.displayname.md | 11 ++++ ...erative-ai.cachedcontentbase.expiretime.md | 13 ++++ .../server/generative-ai.cachedcontentbase.md | 25 +++++++ .../generative-ai.cachedcontentbase.model.md | 11 ++++ ...-ai.cachedcontentbase.systeminstruction.md | 11 ++++ ...erative-ai.cachedcontentbase.toolconfig.md | 11 ++++ .../generative-ai.cachedcontentbase.tools.md | 11 ++++ ...generative-ai.cachedcontentcreateparams.md | 21 ++++++ ...ai.cachedcontentcreateparams.ttlseconds.md | 13 ++++ ...chedcontentupdateinputfields.expiretime.md | 11 ++++ ...ative-ai.cachedcontentupdateinputfields.md | 21 ++++++ ...chedcontentupdateinputfields.ttlseconds.md | 11 ++++ ...cachedcontentupdateparams.cachedcontent.md | 11 ++++ ...generative-ai.cachedcontentupdateparams.md | 21 ++++++ ...ai.cachedcontentupdateparams.updatemask.md | 13 ++++ .../reference/server/generative-ai.content.md | 21 ++++++ .../server/generative-ai.content.parts.md | 11 ++++ .../server/generative-ai.content.role.md | 11 ++++ .../generative-ai.errordetails.__type_.md | 11 ++++ .../generative-ai.errordetails.domain.md | 11 ++++ .../server/generative-ai.errordetails.md | 23 +++++++ .../generative-ai.errordetails.metadata.md | 11 ++++ .../generative-ai.errordetails.reason.md | 11 ++++ .../server/generative-ai.filedata.fileuri.md | 11 ++++ .../server/generative-ai.filedata.md | 21 ++++++ .../server/generative-ai.filedata.mimetype.md | 11 ++++ .../generative-ai.filedatapart.filedata.md | 11 ++++ ...generative-ai.filedatapart.functioncall.md | 11 ++++ ...rative-ai.filedatapart.functionresponse.md | 11 ++++ .../generative-ai.filedatapart.inlinedata.md | 11 ++++ .../server/generative-ai.filedatapart.md | 24 +++++++ .../server/generative-ai.filedatapart.text.md | 11 ++++ .../generative-ai.filemetadata.displayname.md | 11 ++++ .../server/generative-ai.filemetadata.md | 22 +++++++ .../generative-ai.filemetadata.mimetype.md | 11 ++++ .../server/generative-ai.filemetadata.name.md | 11 ++++ ...tive-ai.filemetadataresponse.createtime.md | 11 ++++ ...ive-ai.filemetadataresponse.displayname.md | 11 ++++ ...enerative-ai.filemetadataresponse.error.md | 13 ++++ ...-ai.filemetadataresponse.expirationtime.md | 11 ++++ .../generative-ai.filemetadataresponse.md | 31 +++++++++ ...rative-ai.filemetadataresponse.mimetype.md | 11 ++++ ...generative-ai.filemetadataresponse.name.md | 11 ++++ ...tive-ai.filemetadataresponse.sha256hash.md | 11 ++++ ...ative-ai.filemetadataresponse.sizebytes.md | 11 ++++ ...enerative-ai.filemetadataresponse.state.md | 11 ++++ ...tive-ai.filemetadataresponse.updatetime.md | 11 ++++ .../generative-ai.filemetadataresponse.uri.md | 11 ++++ ...e-ai.filemetadataresponse.videometadata.md | 13 ++++ .../server/generative-ai.filestate.md | 23 +++++++ .../server/generative-ai.functioncall.args.md | 11 ++++ .../server/generative-ai.functioncall.md | 21 ++++++ .../server/generative-ai.functioncall.name.md | 11 ++++ ...ctioncallingconfig.allowedfunctionnames.md | 11 ++++ .../generative-ai.functioncallingconfig.md | 20 ++++++ ...enerative-ai.functioncallingconfig.mode.md | 11 ++++ .../generative-ai.functioncallingmode.md | 22 +++++++ ...generative-ai.functioncallpart.filedata.md | 11 ++++ ...rative-ai.functioncallpart.functioncall.md | 11 ++++ ...ve-ai.functioncallpart.functionresponse.md | 11 ++++ ...nerative-ai.functioncallpart.inlinedata.md | 11 ++++ .../server/generative-ai.functioncallpart.md | 24 +++++++ .../generative-ai.functioncallpart.text.md | 11 ++++ ...tive-ai.functiondeclaration.description.md | 13 ++++ .../generative-ai.functiondeclaration.md | 22 +++++++ .../generative-ai.functiondeclaration.name.md | 13 ++++ ...ative-ai.functiondeclaration.parameters.md | 30 +++++++++ ...i.functiondeclarationschema.description.md | 13 ++++ ...generative-ai.functiondeclarationschema.md | 23 +++++++ ...ai.functiondeclarationschema.properties.md | 15 +++++ ...e-ai.functiondeclarationschema.required.md | 13 ++++ ...ative-ai.functiondeclarationschema.type.md | 13 ++++ ...ve-ai.functiondeclarationschemaproperty.md | 15 +++++ ...rative-ai.functiondeclarationschematype.md | 25 +++++++ ...ondeclarationstool.functiondeclarations.md | 13 ++++ .../generative-ai.functiondeclarationstool.md | 20 ++++++ .../server/generative-ai.functionresponse.md | 21 ++++++ .../generative-ai.functionresponse.name.md | 11 ++++ ...generative-ai.functionresponse.response.md | 11 ++++ ...rative-ai.functionresponsepart.filedata.md | 11 ++++ ...ve-ai.functionresponsepart.functioncall.md | 11 ++++ ...i.functionresponsepart.functionresponse.md | 11 ++++ ...tive-ai.functionresponsepart.inlinedata.md | 11 ++++ .../generative-ai.functionresponsepart.md | 24 +++++++ ...generative-ai.functionresponsepart.text.md | 11 ++++ ...enerative-ai.generativecontentblob.data.md | 13 ++++ .../generative-ai.generativecontentblob.md | 21 ++++++ ...ative-ai.generativecontentblob.mimetype.md | 11 ++++ ...e-ai.googleaicachemanager._constructor_.md | 21 ++++++ ...nerative-ai.googleaicachemanager.apikey.md | 11 ++++ ...nerative-ai.googleaicachemanager.create.md | 24 +++++++ ...nerative-ai.googleaicachemanager.delete.md | 24 +++++++ .../generative-ai.googleaicachemanager.get.md | 24 +++++++ ...generative-ai.googleaicachemanager.list.md | 24 +++++++ .../generative-ai.googleaicachemanager.md | 36 ++++++++++ ...nerative-ai.googleaicachemanager.update.md | 25 +++++++ ...ve-ai.googleaifilemanager._constructor_.md | 21 ++++++ ...enerative-ai.googleaifilemanager.apikey.md | 11 ++++ ...ative-ai.googleaifilemanager.deletefile.md | 24 +++++++ ...nerative-ai.googleaifilemanager.getfile.md | 24 +++++++ ...rative-ai.googleaifilemanager.listfiles.md | 24 +++++++ .../generative-ai.googleaifilemanager.md | 35 ++++++++++ ...ative-ai.googleaifilemanager.uploadfile.md | 25 +++++++ .../generative-ai.inlinedatapart.filedata.md | 11 ++++ ...nerative-ai.inlinedatapart.functioncall.md | 11 ++++ ...tive-ai.inlinedatapart.functionresponse.md | 11 ++++ ...generative-ai.inlinedatapart.inlinedata.md | 11 ++++ .../server/generative-ai.inlinedatapart.md | 24 +++++++ .../generative-ai.inlinedatapart.text.md | 11 ++++ ...ive-ai.listcacheresponse.cachedcontents.md | 11 ++++ .../server/generative-ai.listcacheresponse.md | 20 ++++++ ...tive-ai.listcacheresponse.nextpagetoken.md | 11 ++++ .../generative-ai.listfilesresponse.files.md | 11 ++++ .../server/generative-ai.listfilesresponse.md | 21 ++++++ ...tive-ai.listfilesresponse.nextpagetoken.md | 11 ++++ .../server/generative-ai.listparams.md | 21 ++++++ .../generative-ai.listparams.pagesize.md | 11 ++++ .../generative-ai.listparams.pagetoken.md | 11 ++++ docs/reference/server/generative-ai.md | 66 +++++++++++++++++++ docs/reference/server/generative-ai.part.md | 15 +++++ .../generative-ai.requestoptions.apiclient.md | 13 ++++ ...generative-ai.requestoptions.apiversion.md | 13 ++++ .../generative-ai.requestoptions.baseurl.md | 13 ++++ ...erative-ai.requestoptions.customheaders.md | 13 ++++ .../server/generative-ai.requestoptions.md | 24 +++++++ .../generative-ai.requestoptions.timeout.md | 13 ++++ .../server/generative-ai.responseschema.md | 15 +++++ .../server/generative-ai.rpcstatus.code.md | 13 ++++ .../server/generative-ai.rpcstatus.details.md | 13 ++++ .../server/generative-ai.rpcstatus.md | 22 +++++++ .../server/generative-ai.rpcstatus.message.md | 13 ++++ .../generative-ai.schema.description.md | 13 ++++ .../server/generative-ai.schema.enum.md | 13 ++++ .../server/generative-ai.schema.example.md | 13 ++++ .../server/generative-ai.schema.format.md | 13 ++++ .../server/generative-ai.schema.items.md | 13 ++++ docs/reference/server/generative-ai.schema.md | 28 ++++++++ .../server/generative-ai.schema.nullable.md | 13 ++++ .../server/generative-ai.schema.properties.md | 15 +++++ .../server/generative-ai.schema.required.md | 13 ++++ .../server/generative-ai.schema.type.md | 13 ++++ .../server/generative-ai.textpart.filedata.md | 11 ++++ .../generative-ai.textpart.functioncall.md | 11 ++++ ...generative-ai.textpart.functionresponse.md | 11 ++++ .../generative-ai.textpart.inlinedata.md | 11 ++++ .../server/generative-ai.textpart.md | 24 +++++++ .../server/generative-ai.textpart.text.md | 11 ++++ docs/reference/server/generative-ai.tool.md | 15 +++++ ...ive-ai.toolconfig.functioncallingconfig.md | 11 ++++ .../server/generative-ai.toolconfig.md | 20 ++++++ .../generative-ai.uploadfileresponse.file.md | 11 ++++ .../generative-ai.uploadfileresponse.md | 20 ++++++ .../server/generative-ai.videometadata.md | 20 ++++++ ...nerative-ai.videometadata.videoduration.md | 13 ++++ docs/reference/server/index.md | 12 ++++ 186 files changed, 2772 insertions(+), 2 deletions(-) create mode 100644 docs/reference/main/generative-ai.cachedcontent.createtime.md create mode 100644 docs/reference/main/generative-ai.cachedcontent.md create mode 100644 docs/reference/main/generative-ai.cachedcontent.name.md create mode 100644 docs/reference/main/generative-ai.cachedcontent.ttl.md create mode 100644 docs/reference/main/generative-ai.cachedcontent.updatetime.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.contents.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.displayname.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.expiretime.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.model.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.systeminstruction.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.toolconfig.md create mode 100644 docs/reference/main/generative-ai.cachedcontentbase.tools.md create mode 100644 docs/reference/main/generative-ai.generatecontentrequest.cachedcontent.md create mode 100644 docs/reference/main/generative-ai.generativemodel.cachedcontent.md create mode 100644 docs/reference/main/generative-ai.googlegenerativeai.getgenerativemodelfromcachedcontent.md create mode 100644 docs/reference/main/generative-ai.modelparams.cachedcontent.md create mode 100644 docs/reference/main/generative-ai.startchatparams.cachedcontent.md create mode 100644 docs/reference/server/generative-ai.cachedcontent.createtime.md create mode 100644 docs/reference/server/generative-ai.cachedcontent.md create mode 100644 docs/reference/server/generative-ai.cachedcontent.name.md create mode 100644 docs/reference/server/generative-ai.cachedcontent.ttl.md create mode 100644 docs/reference/server/generative-ai.cachedcontent.updatetime.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.contents.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.displayname.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.expiretime.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.model.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.systeminstruction.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.toolconfig.md create mode 100644 docs/reference/server/generative-ai.cachedcontentbase.tools.md create mode 100644 docs/reference/server/generative-ai.cachedcontentcreateparams.md create mode 100644 docs/reference/server/generative-ai.cachedcontentcreateparams.ttlseconds.md create mode 100644 docs/reference/server/generative-ai.cachedcontentupdateinputfields.expiretime.md create mode 100644 docs/reference/server/generative-ai.cachedcontentupdateinputfields.md create mode 100644 docs/reference/server/generative-ai.cachedcontentupdateinputfields.ttlseconds.md create mode 100644 docs/reference/server/generative-ai.cachedcontentupdateparams.cachedcontent.md create mode 100644 docs/reference/server/generative-ai.cachedcontentupdateparams.md create mode 100644 docs/reference/server/generative-ai.cachedcontentupdateparams.updatemask.md create mode 100644 docs/reference/server/generative-ai.content.md create mode 100644 docs/reference/server/generative-ai.content.parts.md create mode 100644 docs/reference/server/generative-ai.content.role.md create mode 100644 docs/reference/server/generative-ai.errordetails.__type_.md create mode 100644 docs/reference/server/generative-ai.errordetails.domain.md create mode 100644 docs/reference/server/generative-ai.errordetails.md create mode 100644 docs/reference/server/generative-ai.errordetails.metadata.md create mode 100644 docs/reference/server/generative-ai.errordetails.reason.md create mode 100644 docs/reference/server/generative-ai.filedata.fileuri.md create mode 100644 docs/reference/server/generative-ai.filedata.md create mode 100644 docs/reference/server/generative-ai.filedata.mimetype.md create mode 100644 docs/reference/server/generative-ai.filedatapart.filedata.md create mode 100644 docs/reference/server/generative-ai.filedatapart.functioncall.md create mode 100644 docs/reference/server/generative-ai.filedatapart.functionresponse.md create mode 100644 docs/reference/server/generative-ai.filedatapart.inlinedata.md create mode 100644 docs/reference/server/generative-ai.filedatapart.md create mode 100644 docs/reference/server/generative-ai.filedatapart.text.md create mode 100644 docs/reference/server/generative-ai.filemetadata.displayname.md create mode 100644 docs/reference/server/generative-ai.filemetadata.md create mode 100644 docs/reference/server/generative-ai.filemetadata.mimetype.md create mode 100644 docs/reference/server/generative-ai.filemetadata.name.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.createtime.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.displayname.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.error.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.expirationtime.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.mimetype.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.name.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.sha256hash.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.sizebytes.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.state.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.updatetime.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.uri.md create mode 100644 docs/reference/server/generative-ai.filemetadataresponse.videometadata.md create mode 100644 docs/reference/server/generative-ai.filestate.md create mode 100644 docs/reference/server/generative-ai.functioncall.args.md create mode 100644 docs/reference/server/generative-ai.functioncall.md create mode 100644 docs/reference/server/generative-ai.functioncall.name.md create mode 100644 docs/reference/server/generative-ai.functioncallingconfig.allowedfunctionnames.md create mode 100644 docs/reference/server/generative-ai.functioncallingconfig.md create mode 100644 docs/reference/server/generative-ai.functioncallingconfig.mode.md create mode 100644 docs/reference/server/generative-ai.functioncallingmode.md create mode 100644 docs/reference/server/generative-ai.functioncallpart.filedata.md create mode 100644 docs/reference/server/generative-ai.functioncallpart.functioncall.md create mode 100644 docs/reference/server/generative-ai.functioncallpart.functionresponse.md create mode 100644 docs/reference/server/generative-ai.functioncallpart.inlinedata.md create mode 100644 docs/reference/server/generative-ai.functioncallpart.md create mode 100644 docs/reference/server/generative-ai.functioncallpart.text.md create mode 100644 docs/reference/server/generative-ai.functiondeclaration.description.md create mode 100644 docs/reference/server/generative-ai.functiondeclaration.md create mode 100644 docs/reference/server/generative-ai.functiondeclaration.name.md create mode 100644 docs/reference/server/generative-ai.functiondeclaration.parameters.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationschema.description.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationschema.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationschema.properties.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationschema.required.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationschema.type.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationschemaproperty.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationschematype.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationstool.functiondeclarations.md create mode 100644 docs/reference/server/generative-ai.functiondeclarationstool.md create mode 100644 docs/reference/server/generative-ai.functionresponse.md create mode 100644 docs/reference/server/generative-ai.functionresponse.name.md create mode 100644 docs/reference/server/generative-ai.functionresponse.response.md create mode 100644 docs/reference/server/generative-ai.functionresponsepart.filedata.md create mode 100644 docs/reference/server/generative-ai.functionresponsepart.functioncall.md create mode 100644 docs/reference/server/generative-ai.functionresponsepart.functionresponse.md create mode 100644 docs/reference/server/generative-ai.functionresponsepart.inlinedata.md create mode 100644 docs/reference/server/generative-ai.functionresponsepart.md create mode 100644 docs/reference/server/generative-ai.functionresponsepart.text.md create mode 100644 docs/reference/server/generative-ai.generativecontentblob.data.md create mode 100644 docs/reference/server/generative-ai.generativecontentblob.md create mode 100644 docs/reference/server/generative-ai.generativecontentblob.mimetype.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager._constructor_.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager.apikey.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager.create.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager.delete.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager.get.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager.list.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager.md create mode 100644 docs/reference/server/generative-ai.googleaicachemanager.update.md create mode 100644 docs/reference/server/generative-ai.googleaifilemanager._constructor_.md create mode 100644 docs/reference/server/generative-ai.googleaifilemanager.apikey.md create mode 100644 docs/reference/server/generative-ai.googleaifilemanager.deletefile.md create mode 100644 docs/reference/server/generative-ai.googleaifilemanager.getfile.md create mode 100644 docs/reference/server/generative-ai.googleaifilemanager.listfiles.md create mode 100644 docs/reference/server/generative-ai.googleaifilemanager.md create mode 100644 docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md create mode 100644 docs/reference/server/generative-ai.inlinedatapart.filedata.md create mode 100644 docs/reference/server/generative-ai.inlinedatapart.functioncall.md create mode 100644 docs/reference/server/generative-ai.inlinedatapart.functionresponse.md create mode 100644 docs/reference/server/generative-ai.inlinedatapart.inlinedata.md create mode 100644 docs/reference/server/generative-ai.inlinedatapart.md create mode 100644 docs/reference/server/generative-ai.inlinedatapart.text.md create mode 100644 docs/reference/server/generative-ai.listcacheresponse.cachedcontents.md create mode 100644 docs/reference/server/generative-ai.listcacheresponse.md create mode 100644 docs/reference/server/generative-ai.listcacheresponse.nextpagetoken.md create mode 100644 docs/reference/server/generative-ai.listfilesresponse.files.md create mode 100644 docs/reference/server/generative-ai.listfilesresponse.md create mode 100644 docs/reference/server/generative-ai.listfilesresponse.nextpagetoken.md create mode 100644 docs/reference/server/generative-ai.listparams.md create mode 100644 docs/reference/server/generative-ai.listparams.pagesize.md create mode 100644 docs/reference/server/generative-ai.listparams.pagetoken.md create mode 100644 docs/reference/server/generative-ai.md create mode 100644 docs/reference/server/generative-ai.part.md create mode 100644 docs/reference/server/generative-ai.requestoptions.apiclient.md create mode 100644 docs/reference/server/generative-ai.requestoptions.apiversion.md create mode 100644 docs/reference/server/generative-ai.requestoptions.baseurl.md create mode 100644 docs/reference/server/generative-ai.requestoptions.customheaders.md create mode 100644 docs/reference/server/generative-ai.requestoptions.md create mode 100644 docs/reference/server/generative-ai.requestoptions.timeout.md create mode 100644 docs/reference/server/generative-ai.responseschema.md create mode 100644 docs/reference/server/generative-ai.rpcstatus.code.md create mode 100644 docs/reference/server/generative-ai.rpcstatus.details.md create mode 100644 docs/reference/server/generative-ai.rpcstatus.md create mode 100644 docs/reference/server/generative-ai.rpcstatus.message.md create mode 100644 docs/reference/server/generative-ai.schema.description.md create mode 100644 docs/reference/server/generative-ai.schema.enum.md create mode 100644 docs/reference/server/generative-ai.schema.example.md create mode 100644 docs/reference/server/generative-ai.schema.format.md create mode 100644 docs/reference/server/generative-ai.schema.items.md create mode 100644 docs/reference/server/generative-ai.schema.md create mode 100644 docs/reference/server/generative-ai.schema.nullable.md create mode 100644 docs/reference/server/generative-ai.schema.properties.md create mode 100644 docs/reference/server/generative-ai.schema.required.md create mode 100644 docs/reference/server/generative-ai.schema.type.md create mode 100644 docs/reference/server/generative-ai.textpart.filedata.md create mode 100644 docs/reference/server/generative-ai.textpart.functioncall.md create mode 100644 docs/reference/server/generative-ai.textpart.functionresponse.md create mode 100644 docs/reference/server/generative-ai.textpart.inlinedata.md create mode 100644 docs/reference/server/generative-ai.textpart.md create mode 100644 docs/reference/server/generative-ai.textpart.text.md create mode 100644 docs/reference/server/generative-ai.tool.md create mode 100644 docs/reference/server/generative-ai.toolconfig.functioncallingconfig.md create mode 100644 docs/reference/server/generative-ai.toolconfig.md create mode 100644 docs/reference/server/generative-ai.uploadfileresponse.file.md create mode 100644 docs/reference/server/generative-ai.uploadfileresponse.md create mode 100644 docs/reference/server/generative-ai.videometadata.md create mode 100644 docs/reference/server/generative-ai.videometadata.videoduration.md create mode 100644 docs/reference/server/index.md diff --git a/docs/reference/main/generative-ai.cachedcontent.createtime.md b/docs/reference/main/generative-ai.cachedcontent.createtime.md new file mode 100644 index 00000000..c290b139 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontent.createtime.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [createTime](./generative-ai.cachedcontent.createtime.md) + +## CachedContent.createTime property + +`CachedContent` creation time in ISO string format. + +**Signature:** + +```typescript +createTime?: string; +``` diff --git a/docs/reference/main/generative-ai.cachedcontent.md b/docs/reference/main/generative-ai.cachedcontent.md new file mode 100644 index 00000000..da023f7a --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontent.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) + +## CachedContent interface + +Describes `CachedContent` interface for sending to the server (if creating) or received from the server (using getters or list methods). + +**Signature:** + +```typescript +export interface CachedContent extends CachedContentBase +``` +**Extends:** [CachedContentBase](./generative-ai.cachedcontentbase.md) + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [createTime?](./generative-ai.cachedcontent.createtime.md) | | string | _(Optional)_ CachedContent creation time in ISO string format. | +| [name?](./generative-ai.cachedcontent.name.md) | | string | _(Optional)_ | +| [ttl?](./generative-ai.cachedcontent.ttl.md) | | string | _(Optional)_ protobuf.Duration format (ex. "3.0001s"). | +| [updateTime?](./generative-ai.cachedcontent.updatetime.md) | | string | _(Optional)_ CachedContent update time in ISO string format. | + diff --git a/docs/reference/main/generative-ai.cachedcontent.name.md b/docs/reference/main/generative-ai.cachedcontent.name.md new file mode 100644 index 00000000..2f089cca --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontent.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [name](./generative-ai.cachedcontent.name.md) + +## CachedContent.name property + +**Signature:** + +```typescript +name?: string; +``` diff --git a/docs/reference/main/generative-ai.cachedcontent.ttl.md b/docs/reference/main/generative-ai.cachedcontent.ttl.md new file mode 100644 index 00000000..958f58c0 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontent.ttl.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [ttl](./generative-ai.cachedcontent.ttl.md) + +## CachedContent.ttl property + +protobuf.Duration format (ex. "3.0001s"). + +**Signature:** + +```typescript +ttl?: string; +``` diff --git a/docs/reference/main/generative-ai.cachedcontent.updatetime.md b/docs/reference/main/generative-ai.cachedcontent.updatetime.md new file mode 100644 index 00000000..668ac4e9 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontent.updatetime.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [updateTime](./generative-ai.cachedcontent.updatetime.md) + +## CachedContent.updateTime property + +`CachedContent` update time in ISO string format. + +**Signature:** + +```typescript +updateTime?: string; +``` diff --git a/docs/reference/main/generative-ai.cachedcontentbase.contents.md b/docs/reference/main/generative-ai.cachedcontentbase.contents.md new file mode 100644 index 00000000..62b3ee23 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.contents.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [contents](./generative-ai.cachedcontentbase.contents.md) + +## CachedContentBase.contents property + +**Signature:** + +```typescript +contents: Content[]; +``` diff --git a/docs/reference/main/generative-ai.cachedcontentbase.displayname.md b/docs/reference/main/generative-ai.cachedcontentbase.displayname.md new file mode 100644 index 00000000..d0b4e9e5 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.displayname.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [displayName](./generative-ai.cachedcontentbase.displayname.md) + +## CachedContentBase.displayName property + +**Signature:** + +```typescript +displayName?: string; +``` diff --git a/docs/reference/main/generative-ai.cachedcontentbase.expiretime.md b/docs/reference/main/generative-ai.cachedcontentbase.expiretime.md new file mode 100644 index 00000000..53cb07c2 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.expiretime.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [expireTime](./generative-ai.cachedcontentbase.expiretime.md) + +## CachedContentBase.expireTime property + +Expiration time in ISO string format. Specify either this or `ttlSeconds` when creating a `CachedContent`. + +**Signature:** + +```typescript +expireTime?: string; +``` diff --git a/docs/reference/main/generative-ai.cachedcontentbase.md b/docs/reference/main/generative-ai.cachedcontentbase.md new file mode 100644 index 00000000..36d11403 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) + +## CachedContentBase interface + + +**Signature:** + +```typescript +export interface CachedContentBase +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [contents](./generative-ai.cachedcontentbase.contents.md) | | [Content](./generative-ai.content.md)\[\] | | +| [displayName?](./generative-ai.cachedcontentbase.displayname.md) | | string | _(Optional)_ | +| [expireTime?](./generative-ai.cachedcontentbase.expiretime.md) | | string | _(Optional)_ Expiration time in ISO string format. Specify either this or ttlSeconds when creating a CachedContent. | +| [model?](./generative-ai.cachedcontentbase.model.md) | | string | _(Optional)_ | +| [systemInstruction?](./generative-ai.cachedcontentbase.systeminstruction.md) | | string \| [Part](./generative-ai.part.md) \| [Content](./generative-ai.content.md) | _(Optional)_ | +| [toolConfig?](./generative-ai.cachedcontentbase.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ | +| [tools?](./generative-ai.cachedcontentbase.tools.md) | | [Tool](./generative-ai.tool.md)\[\] | _(Optional)_ | + diff --git a/docs/reference/main/generative-ai.cachedcontentbase.model.md b/docs/reference/main/generative-ai.cachedcontentbase.model.md new file mode 100644 index 00000000..fdad6d67 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.model.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [model](./generative-ai.cachedcontentbase.model.md) + +## CachedContentBase.model property + +**Signature:** + +```typescript +model?: string; +``` diff --git a/docs/reference/main/generative-ai.cachedcontentbase.systeminstruction.md b/docs/reference/main/generative-ai.cachedcontentbase.systeminstruction.md new file mode 100644 index 00000000..7694441b --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.systeminstruction.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [systemInstruction](./generative-ai.cachedcontentbase.systeminstruction.md) + +## CachedContentBase.systemInstruction property + +**Signature:** + +```typescript +systemInstruction?: string | Part | Content; +``` diff --git a/docs/reference/main/generative-ai.cachedcontentbase.toolconfig.md b/docs/reference/main/generative-ai.cachedcontentbase.toolconfig.md new file mode 100644 index 00000000..b3c26cd7 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.toolconfig.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [toolConfig](./generative-ai.cachedcontentbase.toolconfig.md) + +## CachedContentBase.toolConfig property + +**Signature:** + +```typescript +toolConfig?: ToolConfig; +``` diff --git a/docs/reference/main/generative-ai.cachedcontentbase.tools.md b/docs/reference/main/generative-ai.cachedcontentbase.tools.md new file mode 100644 index 00000000..7219b9b5 --- /dev/null +++ b/docs/reference/main/generative-ai.cachedcontentbase.tools.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [tools](./generative-ai.cachedcontentbase.tools.md) + +## CachedContentBase.tools property + +**Signature:** + +```typescript +tools?: Tool[]; +``` diff --git a/docs/reference/main/generative-ai.generatecontentrequest.cachedcontent.md b/docs/reference/main/generative-ai.generatecontentrequest.cachedcontent.md new file mode 100644 index 00000000..6174bb46 --- /dev/null +++ b/docs/reference/main/generative-ai.generatecontentrequest.cachedcontent.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GenerateContentRequest](./generative-ai.generatecontentrequest.md) > [cachedContent](./generative-ai.generatecontentrequest.cachedcontent.md) + +## GenerateContentRequest.cachedContent property + +This is the name of a `CachedContent` and not the cache object itself. + +**Signature:** + +```typescript +cachedContent?: string; +``` diff --git a/docs/reference/main/generative-ai.generatecontentrequest.md b/docs/reference/main/generative-ai.generatecontentrequest.md index 97fe934f..e58eb2f8 100644 --- a/docs/reference/main/generative-ai.generatecontentrequest.md +++ b/docs/reference/main/generative-ai.generatecontentrequest.md @@ -17,6 +17,7 @@ export interface GenerateContentRequest extends BaseParams | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [cachedContent?](./generative-ai.generatecontentrequest.cachedcontent.md) | | string | _(Optional)_ This is the name of a CachedContent and not the cache object itself. | | [contents](./generative-ai.generatecontentrequest.contents.md) | | [Content](./generative-ai.content.md)\[\] | | | [systemInstruction?](./generative-ai.generatecontentrequest.systeminstruction.md) | | string \| [Part](./generative-ai.part.md) \| [Content](./generative-ai.content.md) | _(Optional)_ | | [toolConfig?](./generative-ai.generatecontentrequest.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ | diff --git a/docs/reference/main/generative-ai.generativemodel.cachedcontent.md b/docs/reference/main/generative-ai.generativemodel.cachedcontent.md new file mode 100644 index 00000000..f743fe8c --- /dev/null +++ b/docs/reference/main/generative-ai.generativemodel.cachedcontent.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GenerativeModel](./generative-ai.generativemodel.md) > [cachedContent](./generative-ai.generativemodel.cachedcontent.md) + +## GenerativeModel.cachedContent property + +**Signature:** + +```typescript +cachedContent: CachedContent; +``` diff --git a/docs/reference/main/generative-ai.generativemodel.md b/docs/reference/main/generative-ai.generativemodel.md index fe992467..f78e6b8a 100644 --- a/docs/reference/main/generative-ai.generativemodel.md +++ b/docs/reference/main/generative-ai.generativemodel.md @@ -23,6 +23,7 @@ export declare class GenerativeModel | Property | Modifiers | Type | Description | | --- | --- | --- | --- | | [apiKey](./generative-ai.generativemodel.apikey.md) | | string | | +| [cachedContent](./generative-ai.generativemodel.cachedcontent.md) | | [CachedContent](./generative-ai.cachedcontent.md) | | | [generationConfig](./generative-ai.generativemodel.generationconfig.md) | | [GenerationConfig](./generative-ai.generationconfig.md) | | | [model](./generative-ai.generativemodel.model.md) | | string | | | [requestOptions](./generative-ai.generativemodel.requestoptions.md) | | [RequestOptions](./generative-ai.requestoptions.md) | | diff --git a/docs/reference/main/generative-ai.googlegenerativeai.getgenerativemodelfromcachedcontent.md b/docs/reference/main/generative-ai.googlegenerativeai.getgenerativemodelfromcachedcontent.md new file mode 100644 index 00000000..1f24640f --- /dev/null +++ b/docs/reference/main/generative-ai.googlegenerativeai.getgenerativemodelfromcachedcontent.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleGenerativeAI](./generative-ai.googlegenerativeai.md) > [getGenerativeModelFromCachedContent](./generative-ai.googlegenerativeai.getgenerativemodelfromcachedcontent.md) + +## GoogleGenerativeAI.getGenerativeModelFromCachedContent() method + +Creates a [GenerativeModel](./generative-ai.generativemodel.md) instance from provided content cache. + +**Signature:** + +```typescript +getGenerativeModelFromCachedContent(cachedContent: CachedContent, requestOptions?: RequestOptions): GenerativeModel; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| cachedContent | [CachedContent](./generative-ai.cachedcontent.md) | | +| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | + +**Returns:** + +[GenerativeModel](./generative-ai.generativemodel.md) + diff --git a/docs/reference/main/generative-ai.googlegenerativeai.md b/docs/reference/main/generative-ai.googlegenerativeai.md index 3851c0cb..0f3aa381 100644 --- a/docs/reference/main/generative-ai.googlegenerativeai.md +++ b/docs/reference/main/generative-ai.googlegenerativeai.md @@ -29,4 +29,5 @@ export declare class GoogleGenerativeAI | Method | Modifiers | Description | | --- | --- | --- | | [getGenerativeModel(modelParams, requestOptions)](./generative-ai.googlegenerativeai.getgenerativemodel.md) | | Gets a [GenerativeModel](./generative-ai.generativemodel.md) instance for the provided model name. | +| [getGenerativeModelFromCachedContent(cachedContent, requestOptions)](./generative-ai.googlegenerativeai.getgenerativemodelfromcachedcontent.md) | | Creates a [GenerativeModel](./generative-ai.generativemodel.md) instance from provided content cache. | diff --git a/docs/reference/main/generative-ai.md b/docs/reference/main/generative-ai.md index d25ff956..48e347e1 100644 --- a/docs/reference/main/generative-ai.md +++ b/docs/reference/main/generative-ai.md @@ -36,6 +36,8 @@ | [BaseParams](./generative-ai.baseparams.md) | Base parameters for a number of methods. | | [BatchEmbedContentsRequest](./generative-ai.batchembedcontentsrequest.md) | Params for calling [GenerativeModel.batchEmbedContents()](./generative-ai.generativemodel.batchembedcontents.md) | | [BatchEmbedContentsResponse](./generative-ai.batchembedcontentsresponse.md) | Response from calling [GenerativeModel.batchEmbedContents()](./generative-ai.generativemodel.batchembedcontents.md). | +| [CachedContent](./generative-ai.cachedcontent.md) | Describes CachedContent interface for sending to the server (if creating) or received from the server (using getters or list methods). | +| [CachedContentBase](./generative-ai.cachedcontentbase.md) | | | [CitationMetadata](./generative-ai.citationmetadata.md) | Citation metadata that may be found on a [GenerateContentCandidate](./generative-ai.generatecontentcandidate.md). | | [CitationSource](./generative-ai.citationsource.md) | A single citation source. | | [Content](./generative-ai.content.md) | Content type for both prompts and response candidates. | @@ -68,7 +70,7 @@ | [ModelParams](./generative-ai.modelparams.md) | Params passed to [GoogleGenerativeAI.getGenerativeModel()](./generative-ai.googlegenerativeai.getgenerativemodel.md). | | [PromptFeedback](./generative-ai.promptfeedback.md) | If the prompt was blocked, this will be populated with blockReason and the relevant safetyRatings. | | [RequestOptions](./generative-ai.requestoptions.md) | Params passed to getGenerativeModel() or GoogleAIFileManager(). | -| [ResponseSchema](./generative-ai.responseschema.md) | Schema passed to [GenerationConfig.responseSchema](./generative-ai.generationconfig.responseschema.md) | +| [ResponseSchema](./generative-ai.responseschema.md) | Schema passed to GenerationConfig.responseSchema | | [SafetyRating](./generative-ai.safetyrating.md) | A safety rating associated with a [GenerateContentCandidate](./generative-ai.generatecontentcandidate.md) | | [SafetySetting](./generative-ai.safetysetting.md) | Safety setting that can be sent as part of request parameters. | | [Schema](./generative-ai.schema.md) | Schema is used to define the format of input/output data. Represents a select subset of an OpenAPI 3.0 schema object. More fields may be added in the future as needed. | diff --git a/docs/reference/main/generative-ai.modelparams.cachedcontent.md b/docs/reference/main/generative-ai.modelparams.cachedcontent.md new file mode 100644 index 00000000..eaf69cc4 --- /dev/null +++ b/docs/reference/main/generative-ai.modelparams.cachedcontent.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ModelParams](./generative-ai.modelparams.md) > [cachedContent](./generative-ai.modelparams.cachedcontent.md) + +## ModelParams.cachedContent property + +**Signature:** + +```typescript +cachedContent?: CachedContent; +``` diff --git a/docs/reference/main/generative-ai.modelparams.md b/docs/reference/main/generative-ai.modelparams.md index 4231423d..e60cbd39 100644 --- a/docs/reference/main/generative-ai.modelparams.md +++ b/docs/reference/main/generative-ai.modelparams.md @@ -17,6 +17,7 @@ export interface ModelParams extends BaseParams | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [cachedContent?](./generative-ai.modelparams.cachedcontent.md) | | [CachedContent](./generative-ai.cachedcontent.md) | _(Optional)_ | | [model](./generative-ai.modelparams.model.md) | | string | | | [systemInstruction?](./generative-ai.modelparams.systeminstruction.md) | | string \| [Part](./generative-ai.part.md) \| [Content](./generative-ai.content.md) | _(Optional)_ | | [toolConfig?](./generative-ai.modelparams.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ | diff --git a/docs/reference/main/generative-ai.responseschema.md b/docs/reference/main/generative-ai.responseschema.md index 9629e564..ad848a6e 100644 --- a/docs/reference/main/generative-ai.responseschema.md +++ b/docs/reference/main/generative-ai.responseschema.md @@ -4,7 +4,7 @@ ## ResponseSchema interface -Schema passed to [GenerationConfig.responseSchema](./generative-ai.generationconfig.responseschema.md) +Schema passed to `GenerationConfig.responseSchema` **Signature:** diff --git a/docs/reference/main/generative-ai.startchatparams.cachedcontent.md b/docs/reference/main/generative-ai.startchatparams.cachedcontent.md new file mode 100644 index 00000000..4d079e03 --- /dev/null +++ b/docs/reference/main/generative-ai.startchatparams.cachedcontent.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [StartChatParams](./generative-ai.startchatparams.md) > [cachedContent](./generative-ai.startchatparams.cachedcontent.md) + +## StartChatParams.cachedContent property + +This is the name of a `CachedContent` and not the cache object itself. + +**Signature:** + +```typescript +cachedContent?: string; +``` diff --git a/docs/reference/main/generative-ai.startchatparams.md b/docs/reference/main/generative-ai.startchatparams.md index b8beb560..500507ec 100644 --- a/docs/reference/main/generative-ai.startchatparams.md +++ b/docs/reference/main/generative-ai.startchatparams.md @@ -17,6 +17,7 @@ export interface StartChatParams extends BaseParams | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [cachedContent?](./generative-ai.startchatparams.cachedcontent.md) | | string | _(Optional)_ This is the name of a CachedContent and not the cache object itself. | | [history?](./generative-ai.startchatparams.history.md) | | [Content](./generative-ai.content.md)\[\] | _(Optional)_ | | [systemInstruction?](./generative-ai.startchatparams.systeminstruction.md) | | string \| [Part](./generative-ai.part.md) \| [Content](./generative-ai.content.md) | _(Optional)_ | | [toolConfig?](./generative-ai.startchatparams.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ | diff --git a/docs/reference/server/generative-ai.cachedcontent.createtime.md b/docs/reference/server/generative-ai.cachedcontent.createtime.md new file mode 100644 index 00000000..c290b139 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontent.createtime.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [createTime](./generative-ai.cachedcontent.createtime.md) + +## CachedContent.createTime property + +`CachedContent` creation time in ISO string format. + +**Signature:** + +```typescript +createTime?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontent.md b/docs/reference/server/generative-ai.cachedcontent.md new file mode 100644 index 00000000..da023f7a --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontent.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) + +## CachedContent interface + +Describes `CachedContent` interface for sending to the server (if creating) or received from the server (using getters or list methods). + +**Signature:** + +```typescript +export interface CachedContent extends CachedContentBase +``` +**Extends:** [CachedContentBase](./generative-ai.cachedcontentbase.md) + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [createTime?](./generative-ai.cachedcontent.createtime.md) | | string | _(Optional)_ CachedContent creation time in ISO string format. | +| [name?](./generative-ai.cachedcontent.name.md) | | string | _(Optional)_ | +| [ttl?](./generative-ai.cachedcontent.ttl.md) | | string | _(Optional)_ protobuf.Duration format (ex. "3.0001s"). | +| [updateTime?](./generative-ai.cachedcontent.updatetime.md) | | string | _(Optional)_ CachedContent update time in ISO string format. | + diff --git a/docs/reference/server/generative-ai.cachedcontent.name.md b/docs/reference/server/generative-ai.cachedcontent.name.md new file mode 100644 index 00000000..2f089cca --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontent.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [name](./generative-ai.cachedcontent.name.md) + +## CachedContent.name property + +**Signature:** + +```typescript +name?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontent.ttl.md b/docs/reference/server/generative-ai.cachedcontent.ttl.md new file mode 100644 index 00000000..958f58c0 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontent.ttl.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [ttl](./generative-ai.cachedcontent.ttl.md) + +## CachedContent.ttl property + +protobuf.Duration format (ex. "3.0001s"). + +**Signature:** + +```typescript +ttl?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontent.updatetime.md b/docs/reference/server/generative-ai.cachedcontent.updatetime.md new file mode 100644 index 00000000..668ac4e9 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontent.updatetime.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContent](./generative-ai.cachedcontent.md) > [updateTime](./generative-ai.cachedcontent.updatetime.md) + +## CachedContent.updateTime property + +`CachedContent` update time in ISO string format. + +**Signature:** + +```typescript +updateTime?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentbase.contents.md b/docs/reference/server/generative-ai.cachedcontentbase.contents.md new file mode 100644 index 00000000..62b3ee23 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.contents.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [contents](./generative-ai.cachedcontentbase.contents.md) + +## CachedContentBase.contents property + +**Signature:** + +```typescript +contents: Content[]; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentbase.displayname.md b/docs/reference/server/generative-ai.cachedcontentbase.displayname.md new file mode 100644 index 00000000..d0b4e9e5 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.displayname.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [displayName](./generative-ai.cachedcontentbase.displayname.md) + +## CachedContentBase.displayName property + +**Signature:** + +```typescript +displayName?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentbase.expiretime.md b/docs/reference/server/generative-ai.cachedcontentbase.expiretime.md new file mode 100644 index 00000000..53cb07c2 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.expiretime.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [expireTime](./generative-ai.cachedcontentbase.expiretime.md) + +## CachedContentBase.expireTime property + +Expiration time in ISO string format. Specify either this or `ttlSeconds` when creating a `CachedContent`. + +**Signature:** + +```typescript +expireTime?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentbase.md b/docs/reference/server/generative-ai.cachedcontentbase.md new file mode 100644 index 00000000..36d11403 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) + +## CachedContentBase interface + + +**Signature:** + +```typescript +export interface CachedContentBase +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [contents](./generative-ai.cachedcontentbase.contents.md) | | [Content](./generative-ai.content.md)\[\] | | +| [displayName?](./generative-ai.cachedcontentbase.displayname.md) | | string | _(Optional)_ | +| [expireTime?](./generative-ai.cachedcontentbase.expiretime.md) | | string | _(Optional)_ Expiration time in ISO string format. Specify either this or ttlSeconds when creating a CachedContent. | +| [model?](./generative-ai.cachedcontentbase.model.md) | | string | _(Optional)_ | +| [systemInstruction?](./generative-ai.cachedcontentbase.systeminstruction.md) | | string \| [Part](./generative-ai.part.md) \| [Content](./generative-ai.content.md) | _(Optional)_ | +| [toolConfig?](./generative-ai.cachedcontentbase.toolconfig.md) | | [ToolConfig](./generative-ai.toolconfig.md) | _(Optional)_ | +| [tools?](./generative-ai.cachedcontentbase.tools.md) | | [Tool](./generative-ai.tool.md)\[\] | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.cachedcontentbase.model.md b/docs/reference/server/generative-ai.cachedcontentbase.model.md new file mode 100644 index 00000000..fdad6d67 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.model.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [model](./generative-ai.cachedcontentbase.model.md) + +## CachedContentBase.model property + +**Signature:** + +```typescript +model?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentbase.systeminstruction.md b/docs/reference/server/generative-ai.cachedcontentbase.systeminstruction.md new file mode 100644 index 00000000..7694441b --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.systeminstruction.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [systemInstruction](./generative-ai.cachedcontentbase.systeminstruction.md) + +## CachedContentBase.systemInstruction property + +**Signature:** + +```typescript +systemInstruction?: string | Part | Content; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentbase.toolconfig.md b/docs/reference/server/generative-ai.cachedcontentbase.toolconfig.md new file mode 100644 index 00000000..b3c26cd7 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.toolconfig.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [toolConfig](./generative-ai.cachedcontentbase.toolconfig.md) + +## CachedContentBase.toolConfig property + +**Signature:** + +```typescript +toolConfig?: ToolConfig; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentbase.tools.md b/docs/reference/server/generative-ai.cachedcontentbase.tools.md new file mode 100644 index 00000000..7219b9b5 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentbase.tools.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentBase](./generative-ai.cachedcontentbase.md) > [tools](./generative-ai.cachedcontentbase.tools.md) + +## CachedContentBase.tools property + +**Signature:** + +```typescript +tools?: Tool[]; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentcreateparams.md b/docs/reference/server/generative-ai.cachedcontentcreateparams.md new file mode 100644 index 00000000..9f78311c --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentcreateparams.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentCreateParams](./generative-ai.cachedcontentcreateparams.md) + +## CachedContentCreateParams interface + +Params to pass to [GoogleAICacheManager.create()](./generative-ai.googleaicachemanager.create.md). + +**Signature:** + +```typescript +export interface CachedContentCreateParams extends CachedContentBase +``` +**Extends:** [CachedContentBase](./generative-ai.cachedcontentbase.md) + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [ttlSeconds?](./generative-ai.cachedcontentcreateparams.ttlseconds.md) | | number | _(Optional)_ CachedContent ttl in seconds. Specify either this or expireTime when creating a CachedContent. | + diff --git a/docs/reference/server/generative-ai.cachedcontentcreateparams.ttlseconds.md b/docs/reference/server/generative-ai.cachedcontentcreateparams.ttlseconds.md new file mode 100644 index 00000000..a6d740b6 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentcreateparams.ttlseconds.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentCreateParams](./generative-ai.cachedcontentcreateparams.md) > [ttlSeconds](./generative-ai.cachedcontentcreateparams.ttlseconds.md) + +## CachedContentCreateParams.ttlSeconds property + +`CachedContent` ttl in seconds. Specify either this or `expireTime` when creating a `CachedContent`. + +**Signature:** + +```typescript +ttlSeconds?: number; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentupdateinputfields.expiretime.md b/docs/reference/server/generative-ai.cachedcontentupdateinputfields.expiretime.md new file mode 100644 index 00000000..a1deda82 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentupdateinputfields.expiretime.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentUpdateInputFields](./generative-ai.cachedcontentupdateinputfields.md) > [expireTime](./generative-ai.cachedcontentupdateinputfields.expiretime.md) + +## CachedContentUpdateInputFields.expireTime property + +**Signature:** + +```typescript +expireTime?: string; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentupdateinputfields.md b/docs/reference/server/generative-ai.cachedcontentupdateinputfields.md new file mode 100644 index 00000000..68d49334 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentupdateinputfields.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentUpdateInputFields](./generative-ai.cachedcontentupdateinputfields.md) + +## CachedContentUpdateInputFields interface + +Fields that can be updated in an existing content cache. + +**Signature:** + +```typescript +export interface CachedContentUpdateInputFields +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [expireTime?](./generative-ai.cachedcontentupdateinputfields.expiretime.md) | | string | _(Optional)_ | +| [ttlSeconds?](./generative-ai.cachedcontentupdateinputfields.ttlseconds.md) | | number | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.cachedcontentupdateinputfields.ttlseconds.md b/docs/reference/server/generative-ai.cachedcontentupdateinputfields.ttlseconds.md new file mode 100644 index 00000000..f06f1329 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentupdateinputfields.ttlseconds.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentUpdateInputFields](./generative-ai.cachedcontentupdateinputfields.md) > [ttlSeconds](./generative-ai.cachedcontentupdateinputfields.ttlseconds.md) + +## CachedContentUpdateInputFields.ttlSeconds property + +**Signature:** + +```typescript +ttlSeconds?: number; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentupdateparams.cachedcontent.md b/docs/reference/server/generative-ai.cachedcontentupdateparams.cachedcontent.md new file mode 100644 index 00000000..64885c06 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentupdateparams.cachedcontent.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentUpdateParams](./generative-ai.cachedcontentupdateparams.md) > [cachedContent](./generative-ai.cachedcontentupdateparams.cachedcontent.md) + +## CachedContentUpdateParams.cachedContent property + +**Signature:** + +```typescript +cachedContent: CachedContentUpdateInputFields; +``` diff --git a/docs/reference/server/generative-ai.cachedcontentupdateparams.md b/docs/reference/server/generative-ai.cachedcontentupdateparams.md new file mode 100644 index 00000000..28fb1248 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentupdateparams.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentUpdateParams](./generative-ai.cachedcontentupdateparams.md) + +## CachedContentUpdateParams interface + +Params to pass to [GoogleAICacheManager.update()](./generative-ai.googleaicachemanager.update.md). + +**Signature:** + +```typescript +export interface CachedContentUpdateParams +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [cachedContent](./generative-ai.cachedcontentupdateparams.cachedcontent.md) | | [CachedContentUpdateInputFields](./generative-ai.cachedcontentupdateinputfields.md) | | +| [updateMask?](./generative-ai.cachedcontentupdateparams.updatemask.md) | | string\[\] | _(Optional)_ protobuf FieldMask. If not specified, updates all provided fields. | + diff --git a/docs/reference/server/generative-ai.cachedcontentupdateparams.updatemask.md b/docs/reference/server/generative-ai.cachedcontentupdateparams.updatemask.md new file mode 100644 index 00000000..bb7e5ba0 --- /dev/null +++ b/docs/reference/server/generative-ai.cachedcontentupdateparams.updatemask.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [CachedContentUpdateParams](./generative-ai.cachedcontentupdateparams.md) > [updateMask](./generative-ai.cachedcontentupdateparams.updatemask.md) + +## CachedContentUpdateParams.updateMask property + +protobuf FieldMask. If not specified, updates all provided fields. + +**Signature:** + +```typescript +updateMask?: string[]; +``` diff --git a/docs/reference/server/generative-ai.content.md b/docs/reference/server/generative-ai.content.md new file mode 100644 index 00000000..3f4e66b8 --- /dev/null +++ b/docs/reference/server/generative-ai.content.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Content](./generative-ai.content.md) + +## Content interface + +Content type for both prompts and response candidates. + +**Signature:** + +```typescript +export interface Content +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [parts](./generative-ai.content.parts.md) | | [Part](./generative-ai.part.md)\[\] | | +| [role](./generative-ai.content.role.md) | | string | | + diff --git a/docs/reference/server/generative-ai.content.parts.md b/docs/reference/server/generative-ai.content.parts.md new file mode 100644 index 00000000..93aa2ce2 --- /dev/null +++ b/docs/reference/server/generative-ai.content.parts.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Content](./generative-ai.content.md) > [parts](./generative-ai.content.parts.md) + +## Content.parts property + +**Signature:** + +```typescript +parts: Part[]; +``` diff --git a/docs/reference/server/generative-ai.content.role.md b/docs/reference/server/generative-ai.content.role.md new file mode 100644 index 00000000..07763381 --- /dev/null +++ b/docs/reference/server/generative-ai.content.role.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Content](./generative-ai.content.md) > [role](./generative-ai.content.role.md) + +## Content.role property + +**Signature:** + +```typescript +role: string; +``` diff --git a/docs/reference/server/generative-ai.errordetails.__type_.md b/docs/reference/server/generative-ai.errordetails.__type_.md new file mode 100644 index 00000000..82066ed0 --- /dev/null +++ b/docs/reference/server/generative-ai.errordetails.__type_.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ErrorDetails](./generative-ai.errordetails.md) > ["@type"](./generative-ai.errordetails.__type_.md) + +## ErrorDetails."@type" property + +**Signature:** + +```typescript +"@type"?: string; +``` diff --git a/docs/reference/server/generative-ai.errordetails.domain.md b/docs/reference/server/generative-ai.errordetails.domain.md new file mode 100644 index 00000000..ebb51031 --- /dev/null +++ b/docs/reference/server/generative-ai.errordetails.domain.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ErrorDetails](./generative-ai.errordetails.md) > [domain](./generative-ai.errordetails.domain.md) + +## ErrorDetails.domain property + +**Signature:** + +```typescript +domain?: string; +``` diff --git a/docs/reference/server/generative-ai.errordetails.md b/docs/reference/server/generative-ai.errordetails.md new file mode 100644 index 00000000..1b2301d2 --- /dev/null +++ b/docs/reference/server/generative-ai.errordetails.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ErrorDetails](./generative-ai.errordetails.md) + +## ErrorDetails interface + +Details object that may be included in an error response. + +**Signature:** + +```typescript +export interface ErrorDetails +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| ["@type"?](./generative-ai.errordetails.__type_.md) | | string | _(Optional)_ | +| [domain?](./generative-ai.errordetails.domain.md) | | string | _(Optional)_ | +| [metadata?](./generative-ai.errordetails.metadata.md) | | Record<string, unknown> | _(Optional)_ | +| [reason?](./generative-ai.errordetails.reason.md) | | string | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.errordetails.metadata.md b/docs/reference/server/generative-ai.errordetails.metadata.md new file mode 100644 index 00000000..4157c4e9 --- /dev/null +++ b/docs/reference/server/generative-ai.errordetails.metadata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ErrorDetails](./generative-ai.errordetails.md) > [metadata](./generative-ai.errordetails.metadata.md) + +## ErrorDetails.metadata property + +**Signature:** + +```typescript +metadata?: Record; +``` diff --git a/docs/reference/server/generative-ai.errordetails.reason.md b/docs/reference/server/generative-ai.errordetails.reason.md new file mode 100644 index 00000000..7719859c --- /dev/null +++ b/docs/reference/server/generative-ai.errordetails.reason.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ErrorDetails](./generative-ai.errordetails.md) > [reason](./generative-ai.errordetails.reason.md) + +## ErrorDetails.reason property + +**Signature:** + +```typescript +reason?: string; +``` diff --git a/docs/reference/server/generative-ai.filedata.fileuri.md b/docs/reference/server/generative-ai.filedata.fileuri.md new file mode 100644 index 00000000..2a22f1f0 --- /dev/null +++ b/docs/reference/server/generative-ai.filedata.fileuri.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileData](./generative-ai.filedata.md) > [fileUri](./generative-ai.filedata.fileuri.md) + +## FileData.fileUri property + +**Signature:** + +```typescript +fileUri: string; +``` diff --git a/docs/reference/server/generative-ai.filedata.md b/docs/reference/server/generative-ai.filedata.md new file mode 100644 index 00000000..f6df39cb --- /dev/null +++ b/docs/reference/server/generative-ai.filedata.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileData](./generative-ai.filedata.md) + +## FileData interface + +Data pointing to a file uploaded with the Files API. + +**Signature:** + +```typescript +export interface FileData +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [fileUri](./generative-ai.filedata.fileuri.md) | | string | | +| [mimeType](./generative-ai.filedata.mimetype.md) | | string | | + diff --git a/docs/reference/server/generative-ai.filedata.mimetype.md b/docs/reference/server/generative-ai.filedata.mimetype.md new file mode 100644 index 00000000..3904de53 --- /dev/null +++ b/docs/reference/server/generative-ai.filedata.mimetype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileData](./generative-ai.filedata.md) > [mimeType](./generative-ai.filedata.mimetype.md) + +## FileData.mimeType property + +**Signature:** + +```typescript +mimeType: string; +``` diff --git a/docs/reference/server/generative-ai.filedatapart.filedata.md b/docs/reference/server/generative-ai.filedatapart.filedata.md new file mode 100644 index 00000000..86761b38 --- /dev/null +++ b/docs/reference/server/generative-ai.filedatapart.filedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileDataPart](./generative-ai.filedatapart.md) > [fileData](./generative-ai.filedatapart.filedata.md) + +## FileDataPart.fileData property + +**Signature:** + +```typescript +fileData: FileData; +``` diff --git a/docs/reference/server/generative-ai.filedatapart.functioncall.md b/docs/reference/server/generative-ai.filedatapart.functioncall.md new file mode 100644 index 00000000..5beeec09 --- /dev/null +++ b/docs/reference/server/generative-ai.filedatapart.functioncall.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileDataPart](./generative-ai.filedatapart.md) > [functionCall](./generative-ai.filedatapart.functioncall.md) + +## FileDataPart.functionCall property + +**Signature:** + +```typescript +functionCall?: never; +``` diff --git a/docs/reference/server/generative-ai.filedatapart.functionresponse.md b/docs/reference/server/generative-ai.filedatapart.functionresponse.md new file mode 100644 index 00000000..81fae57c --- /dev/null +++ b/docs/reference/server/generative-ai.filedatapart.functionresponse.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileDataPart](./generative-ai.filedatapart.md) > [functionResponse](./generative-ai.filedatapart.functionresponse.md) + +## FileDataPart.functionResponse property + +**Signature:** + +```typescript +functionResponse?: never; +``` diff --git a/docs/reference/server/generative-ai.filedatapart.inlinedata.md b/docs/reference/server/generative-ai.filedatapart.inlinedata.md new file mode 100644 index 00000000..ce07379b --- /dev/null +++ b/docs/reference/server/generative-ai.filedatapart.inlinedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileDataPart](./generative-ai.filedatapart.md) > [inlineData](./generative-ai.filedatapart.inlinedata.md) + +## FileDataPart.inlineData property + +**Signature:** + +```typescript +inlineData?: never; +``` diff --git a/docs/reference/server/generative-ai.filedatapart.md b/docs/reference/server/generative-ai.filedatapart.md new file mode 100644 index 00000000..433786ea --- /dev/null +++ b/docs/reference/server/generative-ai.filedatapart.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileDataPart](./generative-ai.filedatapart.md) + +## FileDataPart interface + +Content part interface if the part represents FunctionResponse. + +**Signature:** + +```typescript +export interface FileDataPart +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [fileData](./generative-ai.filedatapart.filedata.md) | | [FileData](./generative-ai.filedata.md) | | +| [functionCall?](./generative-ai.filedatapart.functioncall.md) | | never | _(Optional)_ | +| [functionResponse?](./generative-ai.filedatapart.functionresponse.md) | | never | _(Optional)_ | +| [inlineData?](./generative-ai.filedatapart.inlinedata.md) | | never | _(Optional)_ | +| [text?](./generative-ai.filedatapart.text.md) | | never | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.filedatapart.text.md b/docs/reference/server/generative-ai.filedatapart.text.md new file mode 100644 index 00000000..9452b18e --- /dev/null +++ b/docs/reference/server/generative-ai.filedatapart.text.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileDataPart](./generative-ai.filedatapart.md) > [text](./generative-ai.filedatapart.text.md) + +## FileDataPart.text property + +**Signature:** + +```typescript +text?: never; +``` diff --git a/docs/reference/server/generative-ai.filemetadata.displayname.md b/docs/reference/server/generative-ai.filemetadata.displayname.md new file mode 100644 index 00000000..c3c30c01 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadata.displayname.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadata](./generative-ai.filemetadata.md) > [displayName](./generative-ai.filemetadata.displayname.md) + +## FileMetadata.displayName property + +**Signature:** + +```typescript +displayName?: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadata.md b/docs/reference/server/generative-ai.filemetadata.md new file mode 100644 index 00000000..1a0ae553 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadata.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadata](./generative-ai.filemetadata.md) + +## FileMetadata interface + +Metadata to provide alongside a file upload + +**Signature:** + +```typescript +export interface FileMetadata +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [displayName?](./generative-ai.filemetadata.displayname.md) | | string | _(Optional)_ | +| [mimeType](./generative-ai.filemetadata.mimetype.md) | | string | | +| [name?](./generative-ai.filemetadata.name.md) | | string | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.filemetadata.mimetype.md b/docs/reference/server/generative-ai.filemetadata.mimetype.md new file mode 100644 index 00000000..b5e104b6 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadata.mimetype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadata](./generative-ai.filemetadata.md) > [mimeType](./generative-ai.filemetadata.mimetype.md) + +## FileMetadata.mimeType property + +**Signature:** + +```typescript +mimeType: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadata.name.md b/docs/reference/server/generative-ai.filemetadata.name.md new file mode 100644 index 00000000..7b9a8f57 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadata.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadata](./generative-ai.filemetadata.md) > [name](./generative-ai.filemetadata.name.md) + +## FileMetadata.name property + +**Signature:** + +```typescript +name?: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.createtime.md b/docs/reference/server/generative-ai.filemetadataresponse.createtime.md new file mode 100644 index 00000000..69676d20 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.createtime.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [createTime](./generative-ai.filemetadataresponse.createtime.md) + +## FileMetadataResponse.createTime property + +**Signature:** + +```typescript +createTime: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.displayname.md b/docs/reference/server/generative-ai.filemetadataresponse.displayname.md new file mode 100644 index 00000000..c7229302 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.displayname.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [displayName](./generative-ai.filemetadataresponse.displayname.md) + +## FileMetadataResponse.displayName property + +**Signature:** + +```typescript +displayName?: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.error.md b/docs/reference/server/generative-ai.filemetadataresponse.error.md new file mode 100644 index 00000000..de26ed1c --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.error.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [error](./generative-ai.filemetadataresponse.error.md) + +## FileMetadataResponse.error property + +Error populated if file processing has failed. + +**Signature:** + +```typescript +error?: RpcStatus; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.expirationtime.md b/docs/reference/server/generative-ai.filemetadataresponse.expirationtime.md new file mode 100644 index 00000000..38c8c246 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.expirationtime.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [expirationTime](./generative-ai.filemetadataresponse.expirationtime.md) + +## FileMetadataResponse.expirationTime property + +**Signature:** + +```typescript +expirationTime: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.md b/docs/reference/server/generative-ai.filemetadataresponse.md new file mode 100644 index 00000000..1451515c --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) + +## FileMetadataResponse interface + +File metadata response from server. + +**Signature:** + +```typescript +export interface FileMetadataResponse +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [createTime](./generative-ai.filemetadataresponse.createtime.md) | | string | | +| [displayName?](./generative-ai.filemetadataresponse.displayname.md) | | string | _(Optional)_ | +| [error?](./generative-ai.filemetadataresponse.error.md) | | [RpcStatus](./generative-ai.rpcstatus.md) | _(Optional)_ Error populated if file processing has failed. | +| [expirationTime](./generative-ai.filemetadataresponse.expirationtime.md) | | string | | +| [mimeType](./generative-ai.filemetadataresponse.mimetype.md) | | string | | +| [name](./generative-ai.filemetadataresponse.name.md) | | string | | +| [sha256Hash](./generative-ai.filemetadataresponse.sha256hash.md) | | string | | +| [sizeBytes](./generative-ai.filemetadataresponse.sizebytes.md) | | string | | +| [state](./generative-ai.filemetadataresponse.state.md) | | [FileState](./generative-ai.filestate.md) | | +| [updateTime](./generative-ai.filemetadataresponse.updatetime.md) | | string | | +| [uri](./generative-ai.filemetadataresponse.uri.md) | | string | | +| [videoMetadata?](./generative-ai.filemetadataresponse.videometadata.md) | | [VideoMetadata](./generative-ai.videometadata.md) | _(Optional)_ Video metadata populated after processing is complete. | + diff --git a/docs/reference/server/generative-ai.filemetadataresponse.mimetype.md b/docs/reference/server/generative-ai.filemetadataresponse.mimetype.md new file mode 100644 index 00000000..8e46260c --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.mimetype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [mimeType](./generative-ai.filemetadataresponse.mimetype.md) + +## FileMetadataResponse.mimeType property + +**Signature:** + +```typescript +mimeType: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.name.md b/docs/reference/server/generative-ai.filemetadataresponse.name.md new file mode 100644 index 00000000..52e90945 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [name](./generative-ai.filemetadataresponse.name.md) + +## FileMetadataResponse.name property + +**Signature:** + +```typescript +name: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.sha256hash.md b/docs/reference/server/generative-ai.filemetadataresponse.sha256hash.md new file mode 100644 index 00000000..0dacfc22 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.sha256hash.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [sha256Hash](./generative-ai.filemetadataresponse.sha256hash.md) + +## FileMetadataResponse.sha256Hash property + +**Signature:** + +```typescript +sha256Hash: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.sizebytes.md b/docs/reference/server/generative-ai.filemetadataresponse.sizebytes.md new file mode 100644 index 00000000..82bf6635 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.sizebytes.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [sizeBytes](./generative-ai.filemetadataresponse.sizebytes.md) + +## FileMetadataResponse.sizeBytes property + +**Signature:** + +```typescript +sizeBytes: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.state.md b/docs/reference/server/generative-ai.filemetadataresponse.state.md new file mode 100644 index 00000000..4d92e589 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.state.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [state](./generative-ai.filemetadataresponse.state.md) + +## FileMetadataResponse.state property + +**Signature:** + +```typescript +state: FileState; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.updatetime.md b/docs/reference/server/generative-ai.filemetadataresponse.updatetime.md new file mode 100644 index 00000000..8037d571 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.updatetime.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [updateTime](./generative-ai.filemetadataresponse.updatetime.md) + +## FileMetadataResponse.updateTime property + +**Signature:** + +```typescript +updateTime: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.uri.md b/docs/reference/server/generative-ai.filemetadataresponse.uri.md new file mode 100644 index 00000000..c7668720 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.uri.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [uri](./generative-ai.filemetadataresponse.uri.md) + +## FileMetadataResponse.uri property + +**Signature:** + +```typescript +uri: string; +``` diff --git a/docs/reference/server/generative-ai.filemetadataresponse.videometadata.md b/docs/reference/server/generative-ai.filemetadataresponse.videometadata.md new file mode 100644 index 00000000..1357d4a0 --- /dev/null +++ b/docs/reference/server/generative-ai.filemetadataresponse.videometadata.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileMetadataResponse](./generative-ai.filemetadataresponse.md) > [videoMetadata](./generative-ai.filemetadataresponse.videometadata.md) + +## FileMetadataResponse.videoMetadata property + +Video metadata populated after processing is complete. + +**Signature:** + +```typescript +videoMetadata?: VideoMetadata; +``` diff --git a/docs/reference/server/generative-ai.filestate.md b/docs/reference/server/generative-ai.filestate.md new file mode 100644 index 00000000..55c475c6 --- /dev/null +++ b/docs/reference/server/generative-ai.filestate.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FileState](./generative-ai.filestate.md) + +## FileState enum + +Processing state of the `File`. + +**Signature:** + +```typescript +export declare enum FileState +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| ACTIVE | "ACTIVE" | | +| FAILED | "FAILED" | | +| PROCESSING | "PROCESSING" | | +| STATE\_UNSPECIFIED | "STATE_UNSPECIFIED" | | + diff --git a/docs/reference/server/generative-ai.functioncall.args.md b/docs/reference/server/generative-ai.functioncall.args.md new file mode 100644 index 00000000..f05c46b4 --- /dev/null +++ b/docs/reference/server/generative-ai.functioncall.args.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCall](./generative-ai.functioncall.md) > [args](./generative-ai.functioncall.args.md) + +## FunctionCall.args property + +**Signature:** + +```typescript +args: object; +``` diff --git a/docs/reference/server/generative-ai.functioncall.md b/docs/reference/server/generative-ai.functioncall.md new file mode 100644 index 00000000..b6f88eed --- /dev/null +++ b/docs/reference/server/generative-ai.functioncall.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCall](./generative-ai.functioncall.md) + +## FunctionCall interface + +A predicted \[FunctionCall\] returned from the model that contains a string representing the \[FunctionDeclaration.name\] and a structured JSON object containing the parameters and their values. + +**Signature:** + +```typescript +export interface FunctionCall +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [args](./generative-ai.functioncall.args.md) | | object | | +| [name](./generative-ai.functioncall.name.md) | | string | | + diff --git a/docs/reference/server/generative-ai.functioncall.name.md b/docs/reference/server/generative-ai.functioncall.name.md new file mode 100644 index 00000000..9375e8e8 --- /dev/null +++ b/docs/reference/server/generative-ai.functioncall.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCall](./generative-ai.functioncall.md) > [name](./generative-ai.functioncall.name.md) + +## FunctionCall.name property + +**Signature:** + +```typescript +name: string; +``` diff --git a/docs/reference/server/generative-ai.functioncallingconfig.allowedfunctionnames.md b/docs/reference/server/generative-ai.functioncallingconfig.allowedfunctionnames.md new file mode 100644 index 00000000..bb9ac0a1 --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallingconfig.allowedfunctionnames.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) > [allowedFunctionNames](./generative-ai.functioncallingconfig.allowedfunctionnames.md) + +## FunctionCallingConfig.allowedFunctionNames property + +**Signature:** + +```typescript +allowedFunctionNames?: string[]; +``` diff --git a/docs/reference/server/generative-ai.functioncallingconfig.md b/docs/reference/server/generative-ai.functioncallingconfig.md new file mode 100644 index 00000000..c41cd1e7 --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallingconfig.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) + +## FunctionCallingConfig interface + + +**Signature:** + +```typescript +export interface FunctionCallingConfig +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [allowedFunctionNames?](./generative-ai.functioncallingconfig.allowedfunctionnames.md) | | string\[\] | _(Optional)_ | +| [mode?](./generative-ai.functioncallingconfig.mode.md) | | [FunctionCallingMode](./generative-ai.functioncallingmode.md) | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.functioncallingconfig.mode.md b/docs/reference/server/generative-ai.functioncallingconfig.mode.md new file mode 100644 index 00000000..12b0ee0d --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallingconfig.mode.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) > [mode](./generative-ai.functioncallingconfig.mode.md) + +## FunctionCallingConfig.mode property + +**Signature:** + +```typescript +mode?: FunctionCallingMode; +``` diff --git a/docs/reference/server/generative-ai.functioncallingmode.md b/docs/reference/server/generative-ai.functioncallingmode.md new file mode 100644 index 00000000..1cd91165 --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallingmode.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallingMode](./generative-ai.functioncallingmode.md) + +## FunctionCallingMode enum + + +**Signature:** + +```typescript +export declare enum FunctionCallingMode +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| ANY | "ANY" | | +| AUTO | "AUTO" | | +| MODE\_UNSPECIFIED | "MODE_UNSPECIFIED" | | +| NONE | "NONE" | | + diff --git a/docs/reference/server/generative-ai.functioncallpart.filedata.md b/docs/reference/server/generative-ai.functioncallpart.filedata.md new file mode 100644 index 00000000..3a9fee1e --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallpart.filedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallPart](./generative-ai.functioncallpart.md) > [fileData](./generative-ai.functioncallpart.filedata.md) + +## FunctionCallPart.fileData property + +**Signature:** + +```typescript +fileData?: never; +``` diff --git a/docs/reference/server/generative-ai.functioncallpart.functioncall.md b/docs/reference/server/generative-ai.functioncallpart.functioncall.md new file mode 100644 index 00000000..578587aa --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallpart.functioncall.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallPart](./generative-ai.functioncallpart.md) > [functionCall](./generative-ai.functioncallpart.functioncall.md) + +## FunctionCallPart.functionCall property + +**Signature:** + +```typescript +functionCall: FunctionCall; +``` diff --git a/docs/reference/server/generative-ai.functioncallpart.functionresponse.md b/docs/reference/server/generative-ai.functioncallpart.functionresponse.md new file mode 100644 index 00000000..3a37c84c --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallpart.functionresponse.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallPart](./generative-ai.functioncallpart.md) > [functionResponse](./generative-ai.functioncallpart.functionresponse.md) + +## FunctionCallPart.functionResponse property + +**Signature:** + +```typescript +functionResponse?: never; +``` diff --git a/docs/reference/server/generative-ai.functioncallpart.inlinedata.md b/docs/reference/server/generative-ai.functioncallpart.inlinedata.md new file mode 100644 index 00000000..7dd9624b --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallpart.inlinedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallPart](./generative-ai.functioncallpart.md) > [inlineData](./generative-ai.functioncallpart.inlinedata.md) + +## FunctionCallPart.inlineData property + +**Signature:** + +```typescript +inlineData?: never; +``` diff --git a/docs/reference/server/generative-ai.functioncallpart.md b/docs/reference/server/generative-ai.functioncallpart.md new file mode 100644 index 00000000..76fce8fb --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallpart.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallPart](./generative-ai.functioncallpart.md) + +## FunctionCallPart interface + +Content part interface if the part represents FunctionResponse. + +**Signature:** + +```typescript +export interface FunctionCallPart +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [fileData?](./generative-ai.functioncallpart.filedata.md) | | never | _(Optional)_ | +| [functionCall](./generative-ai.functioncallpart.functioncall.md) | | [FunctionCall](./generative-ai.functioncall.md) | | +| [functionResponse?](./generative-ai.functioncallpart.functionresponse.md) | | never | _(Optional)_ | +| [inlineData?](./generative-ai.functioncallpart.inlinedata.md) | | never | _(Optional)_ | +| [text?](./generative-ai.functioncallpart.text.md) | | never | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.functioncallpart.text.md b/docs/reference/server/generative-ai.functioncallpart.text.md new file mode 100644 index 00000000..03daf162 --- /dev/null +++ b/docs/reference/server/generative-ai.functioncallpart.text.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionCallPart](./generative-ai.functioncallpart.md) > [text](./generative-ai.functioncallpart.text.md) + +## FunctionCallPart.text property + +**Signature:** + +```typescript +text?: never; +``` diff --git a/docs/reference/server/generative-ai.functiondeclaration.description.md b/docs/reference/server/generative-ai.functiondeclaration.description.md new file mode 100644 index 00000000..aea9a3f7 --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclaration.description.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclaration](./generative-ai.functiondeclaration.md) > [description](./generative-ai.functiondeclaration.description.md) + +## FunctionDeclaration.description property + +Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function. + +**Signature:** + +```typescript +description?: string; +``` diff --git a/docs/reference/server/generative-ai.functiondeclaration.md b/docs/reference/server/generative-ai.functiondeclaration.md new file mode 100644 index 00000000..1657ab4b --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclaration.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclaration](./generative-ai.functiondeclaration.md) + +## FunctionDeclaration interface + +Structured representation of a function declaration as defined by the \[OpenAPI 3.0 specification\](https://spec.openapis.org/oas/v3.0.3). Included in this declaration are the function name and parameters. This FunctionDeclaration is a representation of a block of code that can be used as a Tool by the model and executed by the client. + +**Signature:** + +```typescript +export declare interface FunctionDeclaration +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [description?](./generative-ai.functiondeclaration.description.md) | | string | _(Optional)_ Optional. Description and purpose of the function. Model uses it to decide how and whether to call the function. | +| [name](./generative-ai.functiondeclaration.name.md) | | string | The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a max length of 64. | +| [parameters?](./generative-ai.functiondeclaration.parameters.md) | | [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) | _(Optional)_ Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. | + diff --git a/docs/reference/server/generative-ai.functiondeclaration.name.md b/docs/reference/server/generative-ai.functiondeclaration.name.md new file mode 100644 index 00000000..8df84c9d --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclaration.name.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclaration](./generative-ai.functiondeclaration.md) > [name](./generative-ai.functiondeclaration.name.md) + +## FunctionDeclaration.name property + +The name of the function to call. Must start with a letter or an underscore. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a max length of 64. + +**Signature:** + +```typescript +name: string; +``` diff --git a/docs/reference/server/generative-ai.functiondeclaration.parameters.md b/docs/reference/server/generative-ai.functiondeclaration.parameters.md new file mode 100644 index 00000000..f6005c5b --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclaration.parameters.md @@ -0,0 +1,30 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclaration](./generative-ai.functiondeclaration.md) > [parameters](./generative-ai.functiondeclaration.parameters.md) + +## FunctionDeclaration.parameters property + +Optional. Describes the parameters to this function in JSON Schema Object format. Reflects the Open API 3.03 Parameter Object. string Key: the name of the parameter. Parameter names are case sensitive. Schema Value: the Schema defining the type used for the parameter. For function with no parameters, this can be left unset. + +**Signature:** + +```typescript +parameters?: FunctionDeclarationSchema; +``` + +## Example + +with 1 required and 1 optional parameter: type: OBJECT properties: + +``` +param1: + + type: STRING +param2: + + type: INTEGER +required: + + - param1 +``` + diff --git a/docs/reference/server/generative-ai.functiondeclarationschema.description.md b/docs/reference/server/generative-ai.functiondeclarationschema.description.md new file mode 100644 index 00000000..a8d37cec --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationschema.description.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) > [description](./generative-ai.functiondeclarationschema.description.md) + +## FunctionDeclarationSchema.description property + +Optional. Description of the parameter. + +**Signature:** + +```typescript +description?: string; +``` diff --git a/docs/reference/server/generative-ai.functiondeclarationschema.md b/docs/reference/server/generative-ai.functiondeclarationschema.md new file mode 100644 index 00000000..0af8377b --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationschema.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) + +## FunctionDeclarationSchema interface + +Schema for parameters passed to [FunctionDeclaration.parameters](./generative-ai.functiondeclaration.parameters.md). + +**Signature:** + +```typescript +export interface FunctionDeclarationSchema +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [description?](./generative-ai.functiondeclarationschema.description.md) | | string | _(Optional)_ Optional. Description of the parameter. | +| [properties](./generative-ai.functiondeclarationschema.properties.md) | | { \[k: string\]: [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md); } | The format of the parameter. | +| [required?](./generative-ai.functiondeclarationschema.required.md) | | string\[\] | _(Optional)_ Optional. Array of required parameters. | +| [type](./generative-ai.functiondeclarationschema.type.md) | | [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) | The type of the parameter. | + diff --git a/docs/reference/server/generative-ai.functiondeclarationschema.properties.md b/docs/reference/server/generative-ai.functiondeclarationschema.properties.md new file mode 100644 index 00000000..b1642c49 --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationschema.properties.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) > [properties](./generative-ai.functiondeclarationschema.properties.md) + +## FunctionDeclarationSchema.properties property + +The format of the parameter. + +**Signature:** + +```typescript +properties: { + [k: string]: FunctionDeclarationSchemaProperty; + }; +``` diff --git a/docs/reference/server/generative-ai.functiondeclarationschema.required.md b/docs/reference/server/generative-ai.functiondeclarationschema.required.md new file mode 100644 index 00000000..fdddab0b --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationschema.required.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) > [required](./generative-ai.functiondeclarationschema.required.md) + +## FunctionDeclarationSchema.required property + +Optional. Array of required parameters. + +**Signature:** + +```typescript +required?: string[]; +``` diff --git a/docs/reference/server/generative-ai.functiondeclarationschema.type.md b/docs/reference/server/generative-ai.functiondeclarationschema.type.md new file mode 100644 index 00000000..7d336a82 --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationschema.type.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) > [type](./generative-ai.functiondeclarationschema.type.md) + +## FunctionDeclarationSchema.type property + +The type of the parameter. + +**Signature:** + +```typescript +type: FunctionDeclarationSchemaType; +``` diff --git a/docs/reference/server/generative-ai.functiondeclarationschemaproperty.md b/docs/reference/server/generative-ai.functiondeclarationschemaproperty.md new file mode 100644 index 00000000..b0303af1 --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationschemaproperty.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md) + +## FunctionDeclarationSchemaProperty interface + +Schema for top-level function declaration + +**Signature:** + +```typescript +export interface FunctionDeclarationSchemaProperty extends Schema +``` +**Extends:** [Schema](./generative-ai.schema.md) + diff --git a/docs/reference/server/generative-ai.functiondeclarationschematype.md b/docs/reference/server/generative-ai.functiondeclarationschematype.md new file mode 100644 index 00000000..6d873939 --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationschematype.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) + +## FunctionDeclarationSchemaType enum + +Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ + +**Signature:** + +```typescript +export declare enum FunctionDeclarationSchemaType +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| ARRAY | "ARRAY" | Array type. | +| BOOLEAN | "BOOLEAN" | Boolean type. | +| INTEGER | "INTEGER" | Integer type. | +| NUMBER | "NUMBER" | Number type. | +| OBJECT | "OBJECT" | Object type. | +| STRING | "STRING" | String type. | + diff --git a/docs/reference/server/generative-ai.functiondeclarationstool.functiondeclarations.md b/docs/reference/server/generative-ai.functiondeclarationstool.functiondeclarations.md new file mode 100644 index 00000000..4d45fc5e --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationstool.functiondeclarations.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationsTool](./generative-ai.functiondeclarationstool.md) > [functionDeclarations](./generative-ai.functiondeclarationstool.functiondeclarations.md) + +## FunctionDeclarationsTool.functionDeclarations property + +Optional. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating \[FunctionCall\]\[content.part.functionCall\] in the response. User should provide a \[FunctionResponse\]\[content.part.functionResponse\] for each function call in the next turn. Based on the function responses, Model will generate the final response back to the user. Maximum 64 function declarations can be provided. + +**Signature:** + +```typescript +functionDeclarations?: FunctionDeclaration[]; +``` diff --git a/docs/reference/server/generative-ai.functiondeclarationstool.md b/docs/reference/server/generative-ai.functiondeclarationstool.md new file mode 100644 index 00000000..94dba378 --- /dev/null +++ b/docs/reference/server/generative-ai.functiondeclarationstool.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionDeclarationsTool](./generative-ai.functiondeclarationstool.md) + +## FunctionDeclarationsTool interface + +A FunctionDeclarationsTool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. + +**Signature:** + +```typescript +export declare interface FunctionDeclarationsTool +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [functionDeclarations?](./generative-ai.functiondeclarationstool.functiondeclarations.md) | | [FunctionDeclaration](./generative-ai.functiondeclaration.md)\[\] | _(Optional)_ Optional. One or more function declarations to be passed to the model along with the current user query. Model may decide to call a subset of these functions by populating \[FunctionCall\]\[content.part.functionCall\] in the response. User should provide a \[FunctionResponse\]\[content.part.functionResponse\] for each function call in the next turn. Based on the function responses, Model will generate the final response back to the user. Maximum 64 function declarations can be provided. | + diff --git a/docs/reference/server/generative-ai.functionresponse.md b/docs/reference/server/generative-ai.functionresponse.md new file mode 100644 index 00000000..ccf31158 --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponse.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponse](./generative-ai.functionresponse.md) + +## FunctionResponse interface + +The result output from a \[FunctionCall\] that contains a string representing the \[FunctionDeclaration.name\] and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a \[FunctionCall\] made based on model prediction. + +**Signature:** + +```typescript +export interface FunctionResponse +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [name](./generative-ai.functionresponse.name.md) | | string | | +| [response](./generative-ai.functionresponse.response.md) | | object | | + diff --git a/docs/reference/server/generative-ai.functionresponse.name.md b/docs/reference/server/generative-ai.functionresponse.name.md new file mode 100644 index 00000000..1660034a --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponse.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponse](./generative-ai.functionresponse.md) > [name](./generative-ai.functionresponse.name.md) + +## FunctionResponse.name property + +**Signature:** + +```typescript +name: string; +``` diff --git a/docs/reference/server/generative-ai.functionresponse.response.md b/docs/reference/server/generative-ai.functionresponse.response.md new file mode 100644 index 00000000..b2248dee --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponse.response.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponse](./generative-ai.functionresponse.md) > [response](./generative-ai.functionresponse.response.md) + +## FunctionResponse.response property + +**Signature:** + +```typescript +response: object; +``` diff --git a/docs/reference/server/generative-ai.functionresponsepart.filedata.md b/docs/reference/server/generative-ai.functionresponsepart.filedata.md new file mode 100644 index 00000000..4bc8cf98 --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponsepart.filedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponsePart](./generative-ai.functionresponsepart.md) > [fileData](./generative-ai.functionresponsepart.filedata.md) + +## FunctionResponsePart.fileData property + +**Signature:** + +```typescript +fileData?: never; +``` diff --git a/docs/reference/server/generative-ai.functionresponsepart.functioncall.md b/docs/reference/server/generative-ai.functionresponsepart.functioncall.md new file mode 100644 index 00000000..bf4c526b --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponsepart.functioncall.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponsePart](./generative-ai.functionresponsepart.md) > [functionCall](./generative-ai.functionresponsepart.functioncall.md) + +## FunctionResponsePart.functionCall property + +**Signature:** + +```typescript +functionCall?: never; +``` diff --git a/docs/reference/server/generative-ai.functionresponsepart.functionresponse.md b/docs/reference/server/generative-ai.functionresponsepart.functionresponse.md new file mode 100644 index 00000000..715c8327 --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponsepart.functionresponse.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponsePart](./generative-ai.functionresponsepart.md) > [functionResponse](./generative-ai.functionresponsepart.functionresponse.md) + +## FunctionResponsePart.functionResponse property + +**Signature:** + +```typescript +functionResponse: FunctionResponse; +``` diff --git a/docs/reference/server/generative-ai.functionresponsepart.inlinedata.md b/docs/reference/server/generative-ai.functionresponsepart.inlinedata.md new file mode 100644 index 00000000..f5186809 --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponsepart.inlinedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponsePart](./generative-ai.functionresponsepart.md) > [inlineData](./generative-ai.functionresponsepart.inlinedata.md) + +## FunctionResponsePart.inlineData property + +**Signature:** + +```typescript +inlineData?: never; +``` diff --git a/docs/reference/server/generative-ai.functionresponsepart.md b/docs/reference/server/generative-ai.functionresponsepart.md new file mode 100644 index 00000000..ad834102 --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponsepart.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponsePart](./generative-ai.functionresponsepart.md) + +## FunctionResponsePart interface + +Content part interface if the part represents FunctionResponse. + +**Signature:** + +```typescript +export interface FunctionResponsePart +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [fileData?](./generative-ai.functionresponsepart.filedata.md) | | never | _(Optional)_ | +| [functionCall?](./generative-ai.functionresponsepart.functioncall.md) | | never | _(Optional)_ | +| [functionResponse](./generative-ai.functionresponsepart.functionresponse.md) | | [FunctionResponse](./generative-ai.functionresponse.md) | | +| [inlineData?](./generative-ai.functionresponsepart.inlinedata.md) | | never | _(Optional)_ | +| [text?](./generative-ai.functionresponsepart.text.md) | | never | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.functionresponsepart.text.md b/docs/reference/server/generative-ai.functionresponsepart.text.md new file mode 100644 index 00000000..7aca2d41 --- /dev/null +++ b/docs/reference/server/generative-ai.functionresponsepart.text.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [FunctionResponsePart](./generative-ai.functionresponsepart.md) > [text](./generative-ai.functionresponsepart.text.md) + +## FunctionResponsePart.text property + +**Signature:** + +```typescript +text?: never; +``` diff --git a/docs/reference/server/generative-ai.generativecontentblob.data.md b/docs/reference/server/generative-ai.generativecontentblob.data.md new file mode 100644 index 00000000..91fcec71 --- /dev/null +++ b/docs/reference/server/generative-ai.generativecontentblob.data.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GenerativeContentBlob](./generative-ai.generativecontentblob.md) > [data](./generative-ai.generativecontentblob.data.md) + +## GenerativeContentBlob.data property + +Image as a base64 string. + +**Signature:** + +```typescript +data: string; +``` diff --git a/docs/reference/server/generative-ai.generativecontentblob.md b/docs/reference/server/generative-ai.generativecontentblob.md new file mode 100644 index 00000000..bf0ea806 --- /dev/null +++ b/docs/reference/server/generative-ai.generativecontentblob.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GenerativeContentBlob](./generative-ai.generativecontentblob.md) + +## GenerativeContentBlob interface + +Interface for sending an image. + +**Signature:** + +```typescript +export interface GenerativeContentBlob +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [data](./generative-ai.generativecontentblob.data.md) | | string | Image as a base64 string. | +| [mimeType](./generative-ai.generativecontentblob.mimetype.md) | | string | | + diff --git a/docs/reference/server/generative-ai.generativecontentblob.mimetype.md b/docs/reference/server/generative-ai.generativecontentblob.mimetype.md new file mode 100644 index 00000000..60ba3b65 --- /dev/null +++ b/docs/reference/server/generative-ai.generativecontentblob.mimetype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GenerativeContentBlob](./generative-ai.generativecontentblob.md) > [mimeType](./generative-ai.generativecontentblob.mimetype.md) + +## GenerativeContentBlob.mimeType property + +**Signature:** + +```typescript +mimeType: string; +``` diff --git a/docs/reference/server/generative-ai.googleaicachemanager._constructor_.md b/docs/reference/server/generative-ai.googleaicachemanager._constructor_.md new file mode 100644 index 00000000..dd12e51e --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager._constructor_.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) > [(constructor)](./generative-ai.googleaicachemanager._constructor_.md) + +## GoogleAICacheManager.(constructor) + +Constructs a new instance of the `GoogleAICacheManager` class + +**Signature:** + +```typescript +constructor(apiKey: string, _requestOptions?: RequestOptions); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| apiKey | string | | +| \_requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.googleaicachemanager.apikey.md b/docs/reference/server/generative-ai.googleaicachemanager.apikey.md new file mode 100644 index 00000000..300ae970 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager.apikey.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) > [apiKey](./generative-ai.googleaicachemanager.apikey.md) + +## GoogleAICacheManager.apiKey property + +**Signature:** + +```typescript +apiKey: string; +``` diff --git a/docs/reference/server/generative-ai.googleaicachemanager.create.md b/docs/reference/server/generative-ai.googleaicachemanager.create.md new file mode 100644 index 00000000..0cb3832a --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager.create.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) > [create](./generative-ai.googleaicachemanager.create.md) + +## GoogleAICacheManager.create() method + +Upload a new content cache + +**Signature:** + +```typescript +create(createOptions: CachedContentCreateParams): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| createOptions | [CachedContentCreateParams](./generative-ai.cachedcontentcreateparams.md) | | + +**Returns:** + +Promise<[CachedContent](./generative-ai.cachedcontent.md)> + diff --git a/docs/reference/server/generative-ai.googleaicachemanager.delete.md b/docs/reference/server/generative-ai.googleaicachemanager.delete.md new file mode 100644 index 00000000..0d176941 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager.delete.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) > [delete](./generative-ai.googleaicachemanager.delete.md) + +## GoogleAICacheManager.delete() method + +Delete content cache with given name + +**Signature:** + +```typescript +delete(name: string): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| name | string | | + +**Returns:** + +Promise<void> + diff --git a/docs/reference/server/generative-ai.googleaicachemanager.get.md b/docs/reference/server/generative-ai.googleaicachemanager.get.md new file mode 100644 index 00000000..c164cd46 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager.get.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) > [get](./generative-ai.googleaicachemanager.get.md) + +## GoogleAICacheManager.get() method + +Get a content cache + +**Signature:** + +```typescript +get(name: string): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| name | string | | + +**Returns:** + +Promise<[CachedContent](./generative-ai.cachedcontent.md)> + diff --git a/docs/reference/server/generative-ai.googleaicachemanager.list.md b/docs/reference/server/generative-ai.googleaicachemanager.list.md new file mode 100644 index 00000000..5b1e716a --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager.list.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) > [list](./generative-ai.googleaicachemanager.list.md) + +## GoogleAICacheManager.list() method + +List all uploaded content caches + +**Signature:** + +```typescript +list(listParams?: ListParams): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| listParams | [ListParams](./generative-ai.listparams.md) | _(Optional)_ | + +**Returns:** + +Promise<[ListCacheResponse](./generative-ai.listcacheresponse.md)> + diff --git a/docs/reference/server/generative-ai.googleaicachemanager.md b/docs/reference/server/generative-ai.googleaicachemanager.md new file mode 100644 index 00000000..47cc9b76 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager.md @@ -0,0 +1,36 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) + +## GoogleAICacheManager class + +Class for managing GoogleAI content caches. + +**Signature:** + +```typescript +export declare class GoogleAICacheManager +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(apiKey, \_requestOptions)](./generative-ai.googleaicachemanager._constructor_.md) | | Constructs a new instance of the GoogleAICacheManager class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [apiKey](./generative-ai.googleaicachemanager.apikey.md) | | string | | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [create(createOptions)](./generative-ai.googleaicachemanager.create.md) | | Upload a new content cache | +| [delete(name)](./generative-ai.googleaicachemanager.delete.md) | | Delete content cache with given name | +| [get(name)](./generative-ai.googleaicachemanager.get.md) | | Get a content cache | +| [list(listParams)](./generative-ai.googleaicachemanager.list.md) | | List all uploaded content caches | +| [update(name, updateParams)](./generative-ai.googleaicachemanager.update.md) | | Update an existing content cache | + diff --git a/docs/reference/server/generative-ai.googleaicachemanager.update.md b/docs/reference/server/generative-ai.googleaicachemanager.update.md new file mode 100644 index 00000000..d3dbbb75 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaicachemanager.update.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) > [update](./generative-ai.googleaicachemanager.update.md) + +## GoogleAICacheManager.update() method + +Update an existing content cache + +**Signature:** + +```typescript +update(name: string, updateParams: CachedContentUpdateParams): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| name | string | | +| updateParams | [CachedContentUpdateParams](./generative-ai.cachedcontentupdateparams.md) | | + +**Returns:** + +Promise<[CachedContent](./generative-ai.cachedcontent.md)> + diff --git a/docs/reference/server/generative-ai.googleaifilemanager._constructor_.md b/docs/reference/server/generative-ai.googleaifilemanager._constructor_.md new file mode 100644 index 00000000..5c49872e --- /dev/null +++ b/docs/reference/server/generative-ai.googleaifilemanager._constructor_.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) > [(constructor)](./generative-ai.googleaifilemanager._constructor_.md) + +## GoogleAIFileManager.(constructor) + +Constructs a new instance of the `GoogleAIFileManager` class + +**Signature:** + +```typescript +constructor(apiKey: string, _requestOptions?: RequestOptions); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| apiKey | string | | +| \_requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.googleaifilemanager.apikey.md b/docs/reference/server/generative-ai.googleaifilemanager.apikey.md new file mode 100644 index 00000000..78091bb5 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaifilemanager.apikey.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) > [apiKey](./generative-ai.googleaifilemanager.apikey.md) + +## GoogleAIFileManager.apiKey property + +**Signature:** + +```typescript +apiKey: string; +``` diff --git a/docs/reference/server/generative-ai.googleaifilemanager.deletefile.md b/docs/reference/server/generative-ai.googleaifilemanager.deletefile.md new file mode 100644 index 00000000..e5ecfdad --- /dev/null +++ b/docs/reference/server/generative-ai.googleaifilemanager.deletefile.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) > [deleteFile](./generative-ai.googleaifilemanager.deletefile.md) + +## GoogleAIFileManager.deleteFile() method + +Delete file with given ID + +**Signature:** + +```typescript +deleteFile(fileId: string): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fileId | string | | + +**Returns:** + +Promise<void> + diff --git a/docs/reference/server/generative-ai.googleaifilemanager.getfile.md b/docs/reference/server/generative-ai.googleaifilemanager.getfile.md new file mode 100644 index 00000000..613d6b6c --- /dev/null +++ b/docs/reference/server/generative-ai.googleaifilemanager.getfile.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) > [getFile](./generative-ai.googleaifilemanager.getfile.md) + +## GoogleAIFileManager.getFile() method + +Get metadata for file with given ID + +**Signature:** + +```typescript +getFile(fileId: string): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| fileId | string | | + +**Returns:** + +Promise<[FileMetadataResponse](./generative-ai.filemetadataresponse.md)> + diff --git a/docs/reference/server/generative-ai.googleaifilemanager.listfiles.md b/docs/reference/server/generative-ai.googleaifilemanager.listfiles.md new file mode 100644 index 00000000..ef116fb6 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaifilemanager.listfiles.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) > [listFiles](./generative-ai.googleaifilemanager.listfiles.md) + +## GoogleAIFileManager.listFiles() method + +List all uploaded files + +**Signature:** + +```typescript +listFiles(listParams?: ListParams): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| listParams | [ListParams](./generative-ai.listparams.md) | _(Optional)_ | + +**Returns:** + +Promise<[ListFilesResponse](./generative-ai.listfilesresponse.md)> + diff --git a/docs/reference/server/generative-ai.googleaifilemanager.md b/docs/reference/server/generative-ai.googleaifilemanager.md new file mode 100644 index 00000000..655c8d0c --- /dev/null +++ b/docs/reference/server/generative-ai.googleaifilemanager.md @@ -0,0 +1,35 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) + +## GoogleAIFileManager class + +Class for managing GoogleAI file uploads. + +**Signature:** + +```typescript +export declare class GoogleAIFileManager +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(apiKey, \_requestOptions)](./generative-ai.googleaifilemanager._constructor_.md) | | Constructs a new instance of the GoogleAIFileManager class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [apiKey](./generative-ai.googleaifilemanager.apikey.md) | | string | | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [deleteFile(fileId)](./generative-ai.googleaifilemanager.deletefile.md) | | Delete file with given ID | +| [getFile(fileId)](./generative-ai.googleaifilemanager.getfile.md) | | Get metadata for file with given ID | +| [listFiles(listParams)](./generative-ai.googleaifilemanager.listfiles.md) | | List all uploaded files | +| [uploadFile(filePath, fileMetadata)](./generative-ai.googleaifilemanager.uploadfile.md) | | Upload a file | + diff --git a/docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md b/docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md new file mode 100644 index 00000000..90648e90 --- /dev/null +++ b/docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) > [uploadFile](./generative-ai.googleaifilemanager.uploadfile.md) + +## GoogleAIFileManager.uploadFile() method + +Upload a file + +**Signature:** + +```typescript +uploadFile(filePath: string, fileMetadata: FileMetadata): Promise; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| filePath | string | | +| fileMetadata | [FileMetadata](./generative-ai.filemetadata.md) | | + +**Returns:** + +Promise<[UploadFileResponse](./generative-ai.uploadfileresponse.md)> + diff --git a/docs/reference/server/generative-ai.inlinedatapart.filedata.md b/docs/reference/server/generative-ai.inlinedatapart.filedata.md new file mode 100644 index 00000000..2e23c247 --- /dev/null +++ b/docs/reference/server/generative-ai.inlinedatapart.filedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [InlineDataPart](./generative-ai.inlinedatapart.md) > [fileData](./generative-ai.inlinedatapart.filedata.md) + +## InlineDataPart.fileData property + +**Signature:** + +```typescript +fileData?: never; +``` diff --git a/docs/reference/server/generative-ai.inlinedatapart.functioncall.md b/docs/reference/server/generative-ai.inlinedatapart.functioncall.md new file mode 100644 index 00000000..b1070992 --- /dev/null +++ b/docs/reference/server/generative-ai.inlinedatapart.functioncall.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [InlineDataPart](./generative-ai.inlinedatapart.md) > [functionCall](./generative-ai.inlinedatapart.functioncall.md) + +## InlineDataPart.functionCall property + +**Signature:** + +```typescript +functionCall?: never; +``` diff --git a/docs/reference/server/generative-ai.inlinedatapart.functionresponse.md b/docs/reference/server/generative-ai.inlinedatapart.functionresponse.md new file mode 100644 index 00000000..8b0bb928 --- /dev/null +++ b/docs/reference/server/generative-ai.inlinedatapart.functionresponse.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [InlineDataPart](./generative-ai.inlinedatapart.md) > [functionResponse](./generative-ai.inlinedatapart.functionresponse.md) + +## InlineDataPart.functionResponse property + +**Signature:** + +```typescript +functionResponse?: never; +``` diff --git a/docs/reference/server/generative-ai.inlinedatapart.inlinedata.md b/docs/reference/server/generative-ai.inlinedatapart.inlinedata.md new file mode 100644 index 00000000..d4a00791 --- /dev/null +++ b/docs/reference/server/generative-ai.inlinedatapart.inlinedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [InlineDataPart](./generative-ai.inlinedatapart.md) > [inlineData](./generative-ai.inlinedatapart.inlinedata.md) + +## InlineDataPart.inlineData property + +**Signature:** + +```typescript +inlineData: GenerativeContentBlob; +``` diff --git a/docs/reference/server/generative-ai.inlinedatapart.md b/docs/reference/server/generative-ai.inlinedatapart.md new file mode 100644 index 00000000..3a95731e --- /dev/null +++ b/docs/reference/server/generative-ai.inlinedatapart.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [InlineDataPart](./generative-ai.inlinedatapart.md) + +## InlineDataPart interface + +Content part interface if the part represents an image. + +**Signature:** + +```typescript +export interface InlineDataPart +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [fileData?](./generative-ai.inlinedatapart.filedata.md) | | never | _(Optional)_ | +| [functionCall?](./generative-ai.inlinedatapart.functioncall.md) | | never | _(Optional)_ | +| [functionResponse?](./generative-ai.inlinedatapart.functionresponse.md) | | never | _(Optional)_ | +| [inlineData](./generative-ai.inlinedatapart.inlinedata.md) | | [GenerativeContentBlob](./generative-ai.generativecontentblob.md) | | +| [text?](./generative-ai.inlinedatapart.text.md) | | never | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.inlinedatapart.text.md b/docs/reference/server/generative-ai.inlinedatapart.text.md new file mode 100644 index 00000000..2945c1b2 --- /dev/null +++ b/docs/reference/server/generative-ai.inlinedatapart.text.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [InlineDataPart](./generative-ai.inlinedatapart.md) > [text](./generative-ai.inlinedatapart.text.md) + +## InlineDataPart.text property + +**Signature:** + +```typescript +text?: never; +``` diff --git a/docs/reference/server/generative-ai.listcacheresponse.cachedcontents.md b/docs/reference/server/generative-ai.listcacheresponse.cachedcontents.md new file mode 100644 index 00000000..3b1a62ce --- /dev/null +++ b/docs/reference/server/generative-ai.listcacheresponse.cachedcontents.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListCacheResponse](./generative-ai.listcacheresponse.md) > [cachedContents](./generative-ai.listcacheresponse.cachedcontents.md) + +## ListCacheResponse.cachedContents property + +**Signature:** + +```typescript +cachedContents: CachedContent[]; +``` diff --git a/docs/reference/server/generative-ai.listcacheresponse.md b/docs/reference/server/generative-ai.listcacheresponse.md new file mode 100644 index 00000000..0c19d885 --- /dev/null +++ b/docs/reference/server/generative-ai.listcacheresponse.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListCacheResponse](./generative-ai.listcacheresponse.md) + +## ListCacheResponse interface + + +**Signature:** + +```typescript +export interface ListCacheResponse +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [cachedContents](./generative-ai.listcacheresponse.cachedcontents.md) | | [CachedContent](./generative-ai.cachedcontent.md)\[\] | | +| [nextPageToken?](./generative-ai.listcacheresponse.nextpagetoken.md) | | string | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.listcacheresponse.nextpagetoken.md b/docs/reference/server/generative-ai.listcacheresponse.nextpagetoken.md new file mode 100644 index 00000000..71a5059b --- /dev/null +++ b/docs/reference/server/generative-ai.listcacheresponse.nextpagetoken.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListCacheResponse](./generative-ai.listcacheresponse.md) > [nextPageToken](./generative-ai.listcacheresponse.nextpagetoken.md) + +## ListCacheResponse.nextPageToken property + +**Signature:** + +```typescript +nextPageToken?: string; +``` diff --git a/docs/reference/server/generative-ai.listfilesresponse.files.md b/docs/reference/server/generative-ai.listfilesresponse.files.md new file mode 100644 index 00000000..3760979f --- /dev/null +++ b/docs/reference/server/generative-ai.listfilesresponse.files.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListFilesResponse](./generative-ai.listfilesresponse.md) > [files](./generative-ai.listfilesresponse.files.md) + +## ListFilesResponse.files property + +**Signature:** + +```typescript +files: FileMetadataResponse[]; +``` diff --git a/docs/reference/server/generative-ai.listfilesresponse.md b/docs/reference/server/generative-ai.listfilesresponse.md new file mode 100644 index 00000000..eb90d5a6 --- /dev/null +++ b/docs/reference/server/generative-ai.listfilesresponse.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListFilesResponse](./generative-ai.listfilesresponse.md) + +## ListFilesResponse interface + +Response from calling [GoogleAIFileManager.listFiles()](./generative-ai.googleaifilemanager.listfiles.md) + +**Signature:** + +```typescript +export interface ListFilesResponse +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [files](./generative-ai.listfilesresponse.files.md) | | [FileMetadataResponse](./generative-ai.filemetadataresponse.md)\[\] | | +| [nextPageToken?](./generative-ai.listfilesresponse.nextpagetoken.md) | | string | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.listfilesresponse.nextpagetoken.md b/docs/reference/server/generative-ai.listfilesresponse.nextpagetoken.md new file mode 100644 index 00000000..bc906aab --- /dev/null +++ b/docs/reference/server/generative-ai.listfilesresponse.nextpagetoken.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListFilesResponse](./generative-ai.listfilesresponse.md) > [nextPageToken](./generative-ai.listfilesresponse.nextpagetoken.md) + +## ListFilesResponse.nextPageToken property + +**Signature:** + +```typescript +nextPageToken?: string; +``` diff --git a/docs/reference/server/generative-ai.listparams.md b/docs/reference/server/generative-ai.listparams.md new file mode 100644 index 00000000..d6dd32d6 --- /dev/null +++ b/docs/reference/server/generative-ai.listparams.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListParams](./generative-ai.listparams.md) + +## ListParams interface + +Params to pass to [GoogleAIFileManager.listFiles()](./generative-ai.googleaifilemanager.listfiles.md) or [GoogleAICacheManager.list()](./generative-ai.googleaicachemanager.list.md) + +**Signature:** + +```typescript +export interface ListParams +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [pageSize?](./generative-ai.listparams.pagesize.md) | | number | _(Optional)_ | +| [pageToken?](./generative-ai.listparams.pagetoken.md) | | string | _(Optional)_ | + diff --git a/docs/reference/server/generative-ai.listparams.pagesize.md b/docs/reference/server/generative-ai.listparams.pagesize.md new file mode 100644 index 00000000..a5fbfbff --- /dev/null +++ b/docs/reference/server/generative-ai.listparams.pagesize.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListParams](./generative-ai.listparams.md) > [pageSize](./generative-ai.listparams.pagesize.md) + +## ListParams.pageSize property + +**Signature:** + +```typescript +pageSize?: number; +``` diff --git a/docs/reference/server/generative-ai.listparams.pagetoken.md b/docs/reference/server/generative-ai.listparams.pagetoken.md new file mode 100644 index 00000000..374ad9ef --- /dev/null +++ b/docs/reference/server/generative-ai.listparams.pagetoken.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ListParams](./generative-ai.listparams.md) > [pageToken](./generative-ai.listparams.pagetoken.md) + +## ListParams.pageToken property + +**Signature:** + +```typescript +pageToken?: string; +``` diff --git a/docs/reference/server/generative-ai.md b/docs/reference/server/generative-ai.md new file mode 100644 index 00000000..ad9f6652 --- /dev/null +++ b/docs/reference/server/generative-ai.md @@ -0,0 +1,66 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) + +## generative-ai package + +## Classes + +| Class | Description | +| --- | --- | +| [GoogleAICacheManager](./generative-ai.googleaicachemanager.md) | Class for managing GoogleAI content caches. | +| [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) | Class for managing GoogleAI file uploads. | + +## Enumerations + +| Enumeration | Description | +| --- | --- | +| [FileState](./generative-ai.filestate.md) | Processing state of the File. | +| [FunctionCallingMode](./generative-ai.functioncallingmode.md) | | +| [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) | Contains the list of OpenAPI data types as defined by https://swagger.io/docs/specification/data-models/data-types/ | + +## Interfaces + +| Interface | Description | +| --- | --- | +| [CachedContent](./generative-ai.cachedcontent.md) | Describes CachedContent interface for sending to the server (if creating) or received from the server (using getters or list methods). | +| [CachedContentBase](./generative-ai.cachedcontentbase.md) | | +| [CachedContentCreateParams](./generative-ai.cachedcontentcreateparams.md) | Params to pass to [GoogleAICacheManager.create()](./generative-ai.googleaicachemanager.create.md). | +| [CachedContentUpdateInputFields](./generative-ai.cachedcontentupdateinputfields.md) | Fields that can be updated in an existing content cache. | +| [CachedContentUpdateParams](./generative-ai.cachedcontentupdateparams.md) | Params to pass to [GoogleAICacheManager.update()](./generative-ai.googleaicachemanager.update.md). | +| [Content](./generative-ai.content.md) | Content type for both prompts and response candidates. | +| [ErrorDetails](./generative-ai.errordetails.md) | Details object that may be included in an error response. | +| [FileData](./generative-ai.filedata.md) | Data pointing to a file uploaded with the Files API. | +| [FileDataPart](./generative-ai.filedatapart.md) | Content part interface if the part represents FunctionResponse. | +| [FileMetadata](./generative-ai.filemetadata.md) | Metadata to provide alongside a file upload | +| [FileMetadataResponse](./generative-ai.filemetadataresponse.md) | File metadata response from server. | +| [FunctionCall](./generative-ai.functioncall.md) | A predicted \[FunctionCall\] returned from the model that contains a string representing the \[FunctionDeclaration.name\] and a structured JSON object containing the parameters and their values. | +| [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) | | +| [FunctionCallPart](./generative-ai.functioncallpart.md) | Content part interface if the part represents FunctionResponse. | +| [FunctionDeclaration](./generative-ai.functiondeclaration.md) | Structured representation of a function declaration as defined by the \[OpenAPI 3.0 specification\](https://spec.openapis.org/oas/v3.0.3). Included in this declaration are the function name and parameters. This FunctionDeclaration is a representation of a block of code that can be used as a Tool by the model and executed by the client. | +| [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) | Schema for parameters passed to [FunctionDeclaration.parameters](./generative-ai.functiondeclaration.parameters.md). | +| [FunctionDeclarationSchemaProperty](./generative-ai.functiondeclarationschemaproperty.md) | Schema for top-level function declaration | +| [FunctionDeclarationsTool](./generative-ai.functiondeclarationstool.md) | A FunctionDeclarationsTool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. | +| [FunctionResponse](./generative-ai.functionresponse.md) | The result output from a \[FunctionCall\] that contains a string representing the \[FunctionDeclaration.name\] and a structured JSON object containing any output from the function is used as context to the model. This should contain the result of a \[FunctionCall\] made based on model prediction. | +| [FunctionResponsePart](./generative-ai.functionresponsepart.md) | Content part interface if the part represents FunctionResponse. | +| [GenerativeContentBlob](./generative-ai.generativecontentblob.md) | Interface for sending an image. | +| [InlineDataPart](./generative-ai.inlinedatapart.md) | Content part interface if the part represents an image. | +| [ListCacheResponse](./generative-ai.listcacheresponse.md) | | +| [ListFilesResponse](./generative-ai.listfilesresponse.md) | Response from calling [GoogleAIFileManager.listFiles()](./generative-ai.googleaifilemanager.listfiles.md) | +| [ListParams](./generative-ai.listparams.md) | Params to pass to [GoogleAIFileManager.listFiles()](./generative-ai.googleaifilemanager.listfiles.md) or [GoogleAICacheManager.list()](./generative-ai.googleaicachemanager.list.md) | +| [RequestOptions](./generative-ai.requestoptions.md) | Params passed to getGenerativeModel() or GoogleAIFileManager(). | +| [ResponseSchema](./generative-ai.responseschema.md) | Schema passed to GenerationConfig.responseSchema | +| [RpcStatus](./generative-ai.rpcstatus.md) | Standard RPC error status object. | +| [Schema](./generative-ai.schema.md) | Schema is used to define the format of input/output data. Represents a select subset of an OpenAPI 3.0 schema object. More fields may be added in the future as needed. | +| [TextPart](./generative-ai.textpart.md) | Content part interface if the part represents a text string. | +| [ToolConfig](./generative-ai.toolconfig.md) | Tool config. This config is shared for all tools provided in the request. | +| [UploadFileResponse](./generative-ai.uploadfileresponse.md) | Response from calling [GoogleAIFileManager.uploadFile()](./generative-ai.googleaifilemanager.uploadfile.md) | +| [VideoMetadata](./generative-ai.videometadata.md) | Metadata populated when video has been processed. | + +## Type Aliases + +| Type Alias | Description | +| --- | --- | +| [Part](./generative-ai.part.md) | Content part - includes text or image part types. | +| [Tool](./generative-ai.tool.md) | Defines a tool that model can call to access external knowledge. | + diff --git a/docs/reference/server/generative-ai.part.md b/docs/reference/server/generative-ai.part.md new file mode 100644 index 00000000..3ffb1baf --- /dev/null +++ b/docs/reference/server/generative-ai.part.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Part](./generative-ai.part.md) + +## Part type + +Content part - includes text or image part types. + +**Signature:** + +```typescript +export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart; +``` +**References:** [TextPart](./generative-ai.textpart.md), [InlineDataPart](./generative-ai.inlinedatapart.md), [FunctionCallPart](./generative-ai.functioncallpart.md), [FunctionResponsePart](./generative-ai.functionresponsepart.md), [FileDataPart](./generative-ai.filedatapart.md) + diff --git a/docs/reference/server/generative-ai.requestoptions.apiclient.md b/docs/reference/server/generative-ai.requestoptions.apiclient.md new file mode 100644 index 00000000..96f3d52a --- /dev/null +++ b/docs/reference/server/generative-ai.requestoptions.apiclient.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [apiClient](./generative-ai.requestoptions.apiclient.md) + +## RequestOptions.apiClient property + +Additional attribution information to include in the x-goog-api-client header. Used by wrapper SDKs. + +**Signature:** + +```typescript +apiClient?: string; +``` diff --git a/docs/reference/server/generative-ai.requestoptions.apiversion.md b/docs/reference/server/generative-ai.requestoptions.apiversion.md new file mode 100644 index 00000000..2edf5f19 --- /dev/null +++ b/docs/reference/server/generative-ai.requestoptions.apiversion.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [apiVersion](./generative-ai.requestoptions.apiversion.md) + +## RequestOptions.apiVersion property + +Version of API endpoint to call (e.g. "v1" or "v1beta"). If not specified, defaults to latest stable version. + +**Signature:** + +```typescript +apiVersion?: string; +``` diff --git a/docs/reference/server/generative-ai.requestoptions.baseurl.md b/docs/reference/server/generative-ai.requestoptions.baseurl.md new file mode 100644 index 00000000..412a0e9f --- /dev/null +++ b/docs/reference/server/generative-ai.requestoptions.baseurl.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [baseUrl](./generative-ai.requestoptions.baseurl.md) + +## RequestOptions.baseUrl property + +Base endpoint url. Defaults to "https://generativelanguage.googleapis.com" + +**Signature:** + +```typescript +baseUrl?: string; +``` diff --git a/docs/reference/server/generative-ai.requestoptions.customheaders.md b/docs/reference/server/generative-ai.requestoptions.customheaders.md new file mode 100644 index 00000000..e02ae8a9 --- /dev/null +++ b/docs/reference/server/generative-ai.requestoptions.customheaders.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [customHeaders](./generative-ai.requestoptions.customheaders.md) + +## RequestOptions.customHeaders property + +Custom HTTP request headers. + +**Signature:** + +```typescript +customHeaders?: Headers | Record; +``` diff --git a/docs/reference/server/generative-ai.requestoptions.md b/docs/reference/server/generative-ai.requestoptions.md new file mode 100644 index 00000000..44aba7de --- /dev/null +++ b/docs/reference/server/generative-ai.requestoptions.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) + +## RequestOptions interface + +Params passed to getGenerativeModel() or GoogleAIFileManager(). + +**Signature:** + +```typescript +export interface RequestOptions +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [apiClient?](./generative-ai.requestoptions.apiclient.md) | | string | _(Optional)_ Additional attribution information to include in the x-goog-api-client header. Used by wrapper SDKs. | +| [apiVersion?](./generative-ai.requestoptions.apiversion.md) | | string | _(Optional)_ Version of API endpoint to call (e.g. "v1" or "v1beta"). If not specified, defaults to latest stable version. | +| [baseUrl?](./generative-ai.requestoptions.baseurl.md) | | string | _(Optional)_ Base endpoint url. Defaults to "https://generativelanguage.googleapis.com" | +| [customHeaders?](./generative-ai.requestoptions.customheaders.md) | | Headers \| Record<string, string> | _(Optional)_ Custom HTTP request headers. | +| [timeout?](./generative-ai.requestoptions.timeout.md) | | number | _(Optional)_ Request timeout in milliseconds. | + diff --git a/docs/reference/server/generative-ai.requestoptions.timeout.md b/docs/reference/server/generative-ai.requestoptions.timeout.md new file mode 100644 index 00000000..60526d20 --- /dev/null +++ b/docs/reference/server/generative-ai.requestoptions.timeout.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [timeout](./generative-ai.requestoptions.timeout.md) + +## RequestOptions.timeout property + +Request timeout in milliseconds. + +**Signature:** + +```typescript +timeout?: number; +``` diff --git a/docs/reference/server/generative-ai.responseschema.md b/docs/reference/server/generative-ai.responseschema.md new file mode 100644 index 00000000..ad848a6e --- /dev/null +++ b/docs/reference/server/generative-ai.responseschema.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ResponseSchema](./generative-ai.responseschema.md) + +## ResponseSchema interface + +Schema passed to `GenerationConfig.responseSchema` + +**Signature:** + +```typescript +export interface ResponseSchema extends Schema +``` +**Extends:** [Schema](./generative-ai.schema.md) + diff --git a/docs/reference/server/generative-ai.rpcstatus.code.md b/docs/reference/server/generative-ai.rpcstatus.code.md new file mode 100644 index 00000000..f3d57a32 --- /dev/null +++ b/docs/reference/server/generative-ai.rpcstatus.code.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RpcStatus](./generative-ai.rpcstatus.md) > [code](./generative-ai.rpcstatus.code.md) + +## RpcStatus.code property + +Error status code + +**Signature:** + +```typescript +code: number; +``` diff --git a/docs/reference/server/generative-ai.rpcstatus.details.md b/docs/reference/server/generative-ai.rpcstatus.details.md new file mode 100644 index 00000000..30434b98 --- /dev/null +++ b/docs/reference/server/generative-ai.rpcstatus.details.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RpcStatus](./generative-ai.rpcstatus.md) > [details](./generative-ai.rpcstatus.details.md) + +## RpcStatus.details property + +A list of messages that carry the error details. + +**Signature:** + +```typescript +details?: ErrorDetails[]; +``` diff --git a/docs/reference/server/generative-ai.rpcstatus.md b/docs/reference/server/generative-ai.rpcstatus.md new file mode 100644 index 00000000..c89ad79e --- /dev/null +++ b/docs/reference/server/generative-ai.rpcstatus.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RpcStatus](./generative-ai.rpcstatus.md) + +## RpcStatus interface + +Standard RPC error status object. + +**Signature:** + +```typescript +export interface RpcStatus +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [code](./generative-ai.rpcstatus.code.md) | | number | Error status code | +| [details?](./generative-ai.rpcstatus.details.md) | | [ErrorDetails](./generative-ai.errordetails.md)\[\] | _(Optional)_ A list of messages that carry the error details. | +| [message](./generative-ai.rpcstatus.message.md) | | string | A developer-facing error message. | + diff --git a/docs/reference/server/generative-ai.rpcstatus.message.md b/docs/reference/server/generative-ai.rpcstatus.message.md new file mode 100644 index 00000000..11e34bbf --- /dev/null +++ b/docs/reference/server/generative-ai.rpcstatus.message.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RpcStatus](./generative-ai.rpcstatus.md) > [message](./generative-ai.rpcstatus.message.md) + +## RpcStatus.message property + +A developer-facing error message. + +**Signature:** + +```typescript +message: string; +``` diff --git a/docs/reference/server/generative-ai.schema.description.md b/docs/reference/server/generative-ai.schema.description.md new file mode 100644 index 00000000..cac0bf2f --- /dev/null +++ b/docs/reference/server/generative-ai.schema.description.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [description](./generative-ai.schema.description.md) + +## Schema.description property + +Optional. The description of the property. + +**Signature:** + +```typescript +description?: string; +``` diff --git a/docs/reference/server/generative-ai.schema.enum.md b/docs/reference/server/generative-ai.schema.enum.md new file mode 100644 index 00000000..309880a8 --- /dev/null +++ b/docs/reference/server/generative-ai.schema.enum.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [enum](./generative-ai.schema.enum.md) + +## Schema.enum property + +Optional. The enum of the property. + +**Signature:** + +```typescript +enum?: string[]; +``` diff --git a/docs/reference/server/generative-ai.schema.example.md b/docs/reference/server/generative-ai.schema.example.md new file mode 100644 index 00000000..8b4aef2c --- /dev/null +++ b/docs/reference/server/generative-ai.schema.example.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [example](./generative-ai.schema.example.md) + +## Schema.example property + +Optional. The example of the property. + +**Signature:** + +```typescript +example?: unknown; +``` diff --git a/docs/reference/server/generative-ai.schema.format.md b/docs/reference/server/generative-ai.schema.format.md new file mode 100644 index 00000000..088416d4 --- /dev/null +++ b/docs/reference/server/generative-ai.schema.format.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [format](./generative-ai.schema.format.md) + +## Schema.format property + +Optional. The format of the property. + +**Signature:** + +```typescript +format?: string; +``` diff --git a/docs/reference/server/generative-ai.schema.items.md b/docs/reference/server/generative-ai.schema.items.md new file mode 100644 index 00000000..4774e827 --- /dev/null +++ b/docs/reference/server/generative-ai.schema.items.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [items](./generative-ai.schema.items.md) + +## Schema.items property + +Optional. The items of the property. [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) + +**Signature:** + +```typescript +items?: FunctionDeclarationSchema; +``` diff --git a/docs/reference/server/generative-ai.schema.md b/docs/reference/server/generative-ai.schema.md new file mode 100644 index 00000000..27fddfb4 --- /dev/null +++ b/docs/reference/server/generative-ai.schema.md @@ -0,0 +1,28 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) + +## Schema interface + +Schema is used to define the format of input/output data. Represents a select subset of an OpenAPI 3.0 schema object. More fields may be added in the future as needed. + +**Signature:** + +```typescript +export interface Schema +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [description?](./generative-ai.schema.description.md) | | string | _(Optional)_ Optional. The description of the property. | +| [enum?](./generative-ai.schema.enum.md) | | string\[\] | _(Optional)_ Optional. The enum of the property. | +| [example?](./generative-ai.schema.example.md) | | unknown | _(Optional)_ Optional. The example of the property. | +| [format?](./generative-ai.schema.format.md) | | string | _(Optional)_ Optional. The format of the property. | +| [items?](./generative-ai.schema.items.md) | | [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) | _(Optional)_ Optional. The items of the property. [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md) | +| [nullable?](./generative-ai.schema.nullable.md) | | boolean | _(Optional)_ Optional. Whether the property is nullable. | +| [properties?](./generative-ai.schema.properties.md) | | { \[k: string\]: [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md); } | _(Optional)_ Optional. Map of [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md). | +| [required?](./generative-ai.schema.required.md) | | string\[\] | _(Optional)_ Optional. Array of required property. | +| [type?](./generative-ai.schema.type.md) | | [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md) | _(Optional)_ Optional. The type of the property. [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md). | + diff --git a/docs/reference/server/generative-ai.schema.nullable.md b/docs/reference/server/generative-ai.schema.nullable.md new file mode 100644 index 00000000..a0f2c808 --- /dev/null +++ b/docs/reference/server/generative-ai.schema.nullable.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [nullable](./generative-ai.schema.nullable.md) + +## Schema.nullable property + +Optional. Whether the property is nullable. + +**Signature:** + +```typescript +nullable?: boolean; +``` diff --git a/docs/reference/server/generative-ai.schema.properties.md b/docs/reference/server/generative-ai.schema.properties.md new file mode 100644 index 00000000..5e055570 --- /dev/null +++ b/docs/reference/server/generative-ai.schema.properties.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [properties](./generative-ai.schema.properties.md) + +## Schema.properties property + +Optional. Map of [FunctionDeclarationSchema](./generative-ai.functiondeclarationschema.md). + +**Signature:** + +```typescript +properties?: { + [k: string]: FunctionDeclarationSchema; + }; +``` diff --git a/docs/reference/server/generative-ai.schema.required.md b/docs/reference/server/generative-ai.schema.required.md new file mode 100644 index 00000000..63c1ea3e --- /dev/null +++ b/docs/reference/server/generative-ai.schema.required.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [required](./generative-ai.schema.required.md) + +## Schema.required property + +Optional. Array of required property. + +**Signature:** + +```typescript +required?: string[]; +``` diff --git a/docs/reference/server/generative-ai.schema.type.md b/docs/reference/server/generative-ai.schema.type.md new file mode 100644 index 00000000..fedaedac --- /dev/null +++ b/docs/reference/server/generative-ai.schema.type.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Schema](./generative-ai.schema.md) > [type](./generative-ai.schema.type.md) + +## Schema.type property + +Optional. The type of the property. [FunctionDeclarationSchemaType](./generative-ai.functiondeclarationschematype.md). + +**Signature:** + +```typescript +type?: FunctionDeclarationSchemaType; +``` diff --git a/docs/reference/server/generative-ai.textpart.filedata.md b/docs/reference/server/generative-ai.textpart.filedata.md new file mode 100644 index 00000000..b1c482bc --- /dev/null +++ b/docs/reference/server/generative-ai.textpart.filedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [TextPart](./generative-ai.textpart.md) > [fileData](./generative-ai.textpart.filedata.md) + +## TextPart.fileData property + +**Signature:** + +```typescript +fileData?: never; +``` diff --git a/docs/reference/server/generative-ai.textpart.functioncall.md b/docs/reference/server/generative-ai.textpart.functioncall.md new file mode 100644 index 00000000..acef3d14 --- /dev/null +++ b/docs/reference/server/generative-ai.textpart.functioncall.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [TextPart](./generative-ai.textpart.md) > [functionCall](./generative-ai.textpart.functioncall.md) + +## TextPart.functionCall property + +**Signature:** + +```typescript +functionCall?: never; +``` diff --git a/docs/reference/server/generative-ai.textpart.functionresponse.md b/docs/reference/server/generative-ai.textpart.functionresponse.md new file mode 100644 index 00000000..cfcffdda --- /dev/null +++ b/docs/reference/server/generative-ai.textpart.functionresponse.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [TextPart](./generative-ai.textpart.md) > [functionResponse](./generative-ai.textpart.functionresponse.md) + +## TextPart.functionResponse property + +**Signature:** + +```typescript +functionResponse?: never; +``` diff --git a/docs/reference/server/generative-ai.textpart.inlinedata.md b/docs/reference/server/generative-ai.textpart.inlinedata.md new file mode 100644 index 00000000..55b0bbf6 --- /dev/null +++ b/docs/reference/server/generative-ai.textpart.inlinedata.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [TextPart](./generative-ai.textpart.md) > [inlineData](./generative-ai.textpart.inlinedata.md) + +## TextPart.inlineData property + +**Signature:** + +```typescript +inlineData?: never; +``` diff --git a/docs/reference/server/generative-ai.textpart.md b/docs/reference/server/generative-ai.textpart.md new file mode 100644 index 00000000..1e8dd0e8 --- /dev/null +++ b/docs/reference/server/generative-ai.textpart.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [TextPart](./generative-ai.textpart.md) + +## TextPart interface + +Content part interface if the part represents a text string. + +**Signature:** + +```typescript +export interface TextPart +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [fileData?](./generative-ai.textpart.filedata.md) | | never | _(Optional)_ | +| [functionCall?](./generative-ai.textpart.functioncall.md) | | never | _(Optional)_ | +| [functionResponse?](./generative-ai.textpart.functionresponse.md) | | never | _(Optional)_ | +| [inlineData?](./generative-ai.textpart.inlinedata.md) | | never | _(Optional)_ | +| [text](./generative-ai.textpart.text.md) | | string | | + diff --git a/docs/reference/server/generative-ai.textpart.text.md b/docs/reference/server/generative-ai.textpart.text.md new file mode 100644 index 00000000..467b2722 --- /dev/null +++ b/docs/reference/server/generative-ai.textpart.text.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [TextPart](./generative-ai.textpart.md) > [text](./generative-ai.textpart.text.md) + +## TextPart.text property + +**Signature:** + +```typescript +text: string; +``` diff --git a/docs/reference/server/generative-ai.tool.md b/docs/reference/server/generative-ai.tool.md new file mode 100644 index 00000000..0f146f0c --- /dev/null +++ b/docs/reference/server/generative-ai.tool.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [Tool](./generative-ai.tool.md) + +## Tool type + +Defines a tool that model can call to access external knowledge. + +**Signature:** + +```typescript +export declare type Tool = FunctionDeclarationsTool; +``` +**References:** [FunctionDeclarationsTool](./generative-ai.functiondeclarationstool.md) + diff --git a/docs/reference/server/generative-ai.toolconfig.functioncallingconfig.md b/docs/reference/server/generative-ai.toolconfig.functioncallingconfig.md new file mode 100644 index 00000000..b89bbac6 --- /dev/null +++ b/docs/reference/server/generative-ai.toolconfig.functioncallingconfig.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ToolConfig](./generative-ai.toolconfig.md) > [functionCallingConfig](./generative-ai.toolconfig.functioncallingconfig.md) + +## ToolConfig.functionCallingConfig property + +**Signature:** + +```typescript +functionCallingConfig: FunctionCallingConfig; +``` diff --git a/docs/reference/server/generative-ai.toolconfig.md b/docs/reference/server/generative-ai.toolconfig.md new file mode 100644 index 00000000..ebfb8b0d --- /dev/null +++ b/docs/reference/server/generative-ai.toolconfig.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ToolConfig](./generative-ai.toolconfig.md) + +## ToolConfig interface + +Tool config. This config is shared for all tools provided in the request. + +**Signature:** + +```typescript +export interface ToolConfig +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [functionCallingConfig](./generative-ai.toolconfig.functioncallingconfig.md) | | [FunctionCallingConfig](./generative-ai.functioncallingconfig.md) | | + diff --git a/docs/reference/server/generative-ai.uploadfileresponse.file.md b/docs/reference/server/generative-ai.uploadfileresponse.file.md new file mode 100644 index 00000000..faf5574b --- /dev/null +++ b/docs/reference/server/generative-ai.uploadfileresponse.file.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [UploadFileResponse](./generative-ai.uploadfileresponse.md) > [file](./generative-ai.uploadfileresponse.file.md) + +## UploadFileResponse.file property + +**Signature:** + +```typescript +file: FileMetadataResponse; +``` diff --git a/docs/reference/server/generative-ai.uploadfileresponse.md b/docs/reference/server/generative-ai.uploadfileresponse.md new file mode 100644 index 00000000..3c2a055c --- /dev/null +++ b/docs/reference/server/generative-ai.uploadfileresponse.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [UploadFileResponse](./generative-ai.uploadfileresponse.md) + +## UploadFileResponse interface + +Response from calling [GoogleAIFileManager.uploadFile()](./generative-ai.googleaifilemanager.uploadfile.md) + +**Signature:** + +```typescript +export interface UploadFileResponse +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [file](./generative-ai.uploadfileresponse.file.md) | | [FileMetadataResponse](./generative-ai.filemetadataresponse.md) | | + diff --git a/docs/reference/server/generative-ai.videometadata.md b/docs/reference/server/generative-ai.videometadata.md new file mode 100644 index 00000000..08d09f6c --- /dev/null +++ b/docs/reference/server/generative-ai.videometadata.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [VideoMetadata](./generative-ai.videometadata.md) + +## VideoMetadata interface + +Metadata populated when video has been processed. + +**Signature:** + +```typescript +export interface VideoMetadata +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [videoDuration](./generative-ai.videometadata.videoduration.md) | | string | The video duration in protobuf [Duration](https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping) format. | + diff --git a/docs/reference/server/generative-ai.videometadata.videoduration.md b/docs/reference/server/generative-ai.videometadata.videoduration.md new file mode 100644 index 00000000..4d978053 --- /dev/null +++ b/docs/reference/server/generative-ai.videometadata.videoduration.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [VideoMetadata](./generative-ai.videometadata.md) > [videoDuration](./generative-ai.videometadata.videoduration.md) + +## VideoMetadata.videoDuration property + +The video duration in protobuf [Duration](https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping) format. + +**Signature:** + +```typescript +videoDuration: string; +``` diff --git a/docs/reference/server/index.md b/docs/reference/server/index.md new file mode 100644 index 00000000..cbcce1e9 --- /dev/null +++ b/docs/reference/server/index.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) + +## API Reference + +## Packages + +| Package | Description | +| --- | --- | +| [@google/generative-ai](./generative-ai.md) | | + From a95dfec78e0d0ea589a4ced75080d23b7e084a93 Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Mon, 17 Jun 2024 14:13:17 -0700 Subject: [PATCH 14/14] add changeset --- .changeset/tough-shirts-cheat.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-shirts-cheat.md diff --git a/.changeset/tough-shirts-cheat.md b/.changeset/tough-shirts-cheat.md new file mode 100644 index 00000000..c3011cde --- /dev/null +++ b/.changeset/tough-shirts-cheat.md @@ -0,0 +1,5 @@ +--- +"@google/generative-ai": minor +--- + +Added `GoogleAICacheManager` utility to allow caching large content to be used in inference. This class is exported from the `@google/generative-ai/server` subpath. Breaking change: The `GoogleAIFileManager` class has been moved to be exported from this subpath as well instead of the `/files` subpath.