From 44f4f583bdbfa312cc12dcacd782c6de278602ca Mon Sep 17 00:00:00 2001 From: Christina Holland Date: Thu, 14 Mar 2024 11:42:10 -0700 Subject: [PATCH] clean up API types --- common/api-review/generative-ai.api.md | 12 ++++------ ...generative-ai.chatsession._constructor_.md | 24 ------------------- docs/reference/generative-ai.chatsession.md | 6 ++--- packages/core/src/methods/chat-session.ts | 9 +++++-- .../core/src/methods/generate-content.test.ts | 16 ++++++------- packages/core/src/methods/generate-content.ts | 12 +++++----- packages/core/src/types/requests.ts | 6 ++--- packages/googleai/src/gen-ai.test.ts | 2 +- packages/googleai/src/gen-ai.ts | 1 - packages/googleai/src/index.ts | 7 +----- packages/googleai/src/requests/request.ts | 8 +++---- packages/googleai/src/types/index.ts | 9 ++++--- 12 files changed, 42 insertions(+), 70 deletions(-) delete mode 100644 docs/reference/generative-ai.chatsession._constructor_.md diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index 784e6616..7434ea87 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -36,8 +36,8 @@ export enum BlockReason { // @public export class ChatSession { - // Warning: (ae-incompatible-release-tags) The symbol "__constructor" is marked as @public, but its signature references "MakeRequestFunction" which is marked as @internal - constructor(apiKey: string, model: string, _makeRequest: MakeRequestFunction, params?: StartChatParams, requestOptions?: RequestOptions); + // @internal + constructor(apiKey: string, model: string, _makeRequest: _MakeRequestFunction, params?: StartChatParams, requestOptions?: RequestOptions); getHistory(): Promise; // (undocumented) model: string; @@ -373,10 +373,8 @@ export interface InlineDataPart { text?: never; } -// Warning: (ae-internal-missing-underscore) The name "MakeRequestFunction" should be prefixed with an underscore because the declaration is marked as @internal -// // @internal -export type MakeRequestFunction = (model: string, task: Task, apiKey: string, stream: boolean, body: string, requestOptions?: RequestOptions) => Promise; +export type _MakeRequestFunction = (model: string, task: _Task, apiKey: string, stream: boolean, body: string, requestOptions?: RequestOptions) => Promise; // @public export interface ModelParams extends BaseParams { @@ -435,10 +433,8 @@ export interface StartChatParams extends BaseParams { tools?: Tool[]; } -// Warning: (ae-internal-missing-underscore) The name "Task" should be prefixed with an underscore because the declaration is marked as @internal -// // @internal -export enum Task { +export enum _Task { // (undocumented) BATCH_EMBED_CONTENTS = "batchEmbedContents", // (undocumented) diff --git a/docs/reference/generative-ai.chatsession._constructor_.md b/docs/reference/generative-ai.chatsession._constructor_.md deleted file mode 100644 index 39d200b6..00000000 --- a/docs/reference/generative-ai.chatsession._constructor_.md +++ /dev/null @@ -1,24 +0,0 @@ - - -[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ChatSession](./generative-ai.chatsession.md) > [(constructor)](./generative-ai.chatsession._constructor_.md) - -## ChatSession.(constructor) - -Constructs a new instance of the `ChatSession` class - -**Signature:** - -```typescript -constructor(apiKey: string, model: string, _makeRequest: MakeRequestFunction, params?: StartChatParams, requestOptions?: RequestOptions); -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| apiKey | string | | -| model | string | | -| \_makeRequest | MakeRequestFunction | | -| params | [StartChatParams](./generative-ai.startchatparams.md) | _(Optional)_ | -| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | - diff --git a/docs/reference/generative-ai.chatsession.md b/docs/reference/generative-ai.chatsession.md index ff69a180..86af1963 100644 --- a/docs/reference/generative-ai.chatsession.md +++ b/docs/reference/generative-ai.chatsession.md @@ -12,11 +12,9 @@ ChatSession class that enables sending chat messages and stores history of sent export declare class ChatSession ``` -## Constructors +## Remarks -| Constructor | Modifiers | Description | -| --- | --- | --- | -| [(constructor)(apiKey, model, \_makeRequest, params, requestOptions)](./generative-ai.chatsession._constructor_.md) | | Constructs a new instance of the ChatSession class | +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `ChatSession` class. ## Properties diff --git a/packages/core/src/methods/chat-session.ts b/packages/core/src/methods/chat-session.ts index 82ca6647..1b8f2db3 100644 --- a/packages/core/src/methods/chat-session.ts +++ b/packages/core/src/methods/chat-session.ts @@ -20,10 +20,10 @@ import { GenerateContentRequest, GenerateContentResult, GenerateContentStreamResult, - MakeRequestFunction, Part, RequestOptions, StartChatParams, + _MakeRequestFunction, } from "../types"; import { formatNewContent } from "../requests/request-helpers"; import { formatBlockErrorMessage } from "../requests/response-helpers"; @@ -47,10 +47,15 @@ export class ChatSession { private _history: Content[] = []; private _sendPromise: Promise = Promise.resolve(); + /** + * Prevents the constructor, and _makeRequest, from going into public docs. + * Users should not be calling this constructor directly anyway. + * @internal + */ constructor( apiKey: string, public model: string, - private _makeRequest: MakeRequestFunction, + private _makeRequest: _MakeRequestFunction, public params?: StartChatParams, public requestOptions?: RequestOptions, ) { diff --git a/packages/core/src/methods/generate-content.test.ts b/packages/core/src/methods/generate-content.test.ts index 53c8562c..647327b0 100644 --- a/packages/core/src/methods/generate-content.test.ts +++ b/packages/core/src/methods/generate-content.test.ts @@ -25,7 +25,7 @@ import { GenerateContentRequest, HarmBlockThreshold, HarmCategory, - Task, + _Task, } from "../types"; use(sinonChai); @@ -62,7 +62,7 @@ describe("generateContent()", () => { expect(result.response.text()).to.include("Helena"); expect(makeRequestStub).to.be.calledWith( "model", - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, "key", false, match((value: string) => { @@ -83,7 +83,7 @@ describe("generateContent()", () => { expect(result.response.text()).to.include("30 minutes of brewing"); expect(makeRequestStub).to.be.calledWith( "model", - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, "key", false, match.any, @@ -104,7 +104,7 @@ describe("generateContent()", () => { ).to.equal(1); expect(makeRequestStub).to.be.calledWith( "model", - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, "key", false, match.any, @@ -124,7 +124,7 @@ describe("generateContent()", () => { expect(result.response.text).to.throw("SAFETY"); expect(makeRequestStub).to.be.calledWith( "model", - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, "key", false, match.any, @@ -144,7 +144,7 @@ describe("generateContent()", () => { expect(result.response.text).to.throw("SAFETY"); expect(makeRequestStub).to.be.calledWith( "model", - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, "key", false, match.any, @@ -162,7 +162,7 @@ describe("generateContent()", () => { expect(result.response.text()).to.equal(""); expect(makeRequestStub).to.be.calledWith( "model", - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, "key", false, match.any, @@ -180,7 +180,7 @@ describe("generateContent()", () => { expect(result.response.text()).to.include("30 minutes of brewing"); expect(makeRequestStub).to.be.calledWith( "model", - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, "key", false, match.any, diff --git a/packages/core/src/methods/generate-content.ts b/packages/core/src/methods/generate-content.ts index f1d851b7..9ecc1924 100644 --- a/packages/core/src/methods/generate-content.ts +++ b/packages/core/src/methods/generate-content.ts @@ -20,9 +20,9 @@ import { GenerateContentResponse, GenerateContentResult, GenerateContentStreamResult, - MakeRequestFunction, RequestOptions, - Task, + _MakeRequestFunction, + _Task, } from "../types"; import { addHelpers } from "../requests/response-helpers"; import { processStream } from "../requests/stream-reader"; @@ -31,12 +31,12 @@ export async function generateContentStream( apiKey: string, model: string, params: GenerateContentRequest, - makeRequest: MakeRequestFunction, + makeRequest: _MakeRequestFunction, requestOptions?: RequestOptions, ): Promise { const response = await makeRequest( model, - Task.STREAM_GENERATE_CONTENT, + _Task.STREAM_GENERATE_CONTENT, apiKey, /* stream */ true, JSON.stringify(params), @@ -51,7 +51,7 @@ export async function generateContent( params: GenerateContentRequest, makeRequest: ( model: string, - task: Task, + task: _Task, apiKey: string, stream: boolean, body: string, @@ -61,7 +61,7 @@ export async function generateContent( ): Promise { const response = await makeRequest( model, - Task.GENERATE_CONTENT, + _Task.GENERATE_CONTENT, apiKey, /* stream */ false, JSON.stringify(params), diff --git a/packages/core/src/types/requests.ts b/packages/core/src/types/requests.ts index 5aa9f5be..b09e006a 100644 --- a/packages/core/src/types/requests.ts +++ b/packages/core/src/types/requests.ts @@ -246,7 +246,7 @@ export interface FunctionDeclarationSchemaProperty { * Possible endpoint tasks. * @internal */ -export enum Task { +export enum _Task { GENERATE_CONTENT = "generateContent", STREAM_GENERATE_CONTENT = "streamGenerateContent", COUNT_TOKENS = "countTokens", @@ -258,9 +258,9 @@ export enum Task { * Function for making a request to the endpoint given the parameters. * @internal */ -export type MakeRequestFunction = ( +export type _MakeRequestFunction = ( model: string, - task: Task, + task: _Task, apiKey: string, stream: boolean, body: string, diff --git a/packages/googleai/src/gen-ai.test.ts b/packages/googleai/src/gen-ai.test.ts index 9ee8bdd4..ff2dab3c 100644 --- a/packages/googleai/src/gen-ai.test.ts +++ b/packages/googleai/src/gen-ai.test.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ModelParams } from "../../core/src/types"; +import { ModelParams } from "./types"; import { GenerativeModel, GoogleGenerativeAI } from "./gen-ai"; import { expect } from "chai"; diff --git a/packages/googleai/src/gen-ai.ts b/packages/googleai/src/gen-ai.ts index dc6b0ee2..07285124 100644 --- a/packages/googleai/src/gen-ai.ts +++ b/packages/googleai/src/gen-ai.ts @@ -19,7 +19,6 @@ import { GoogleGenerativeAIError, RequestOptions } from "../../core/src"; import { GenerativeModel } from "./models/generative-model"; import { ModelParams } from "./types"; -export { ChatSession } from "../../core/src"; export { GenerativeModel }; /** diff --git a/packages/googleai/src/index.ts b/packages/googleai/src/index.ts index 021d7e80..9a7437d1 100644 --- a/packages/googleai/src/index.ts +++ b/packages/googleai/src/index.ts @@ -15,11 +15,6 @@ * limitations under the License. */ -export { - ChatSession, - GenerationConfig, - SafetySetting, - Tool, -} from "../../core/src"; +export { ChatSession } from "../../core/src"; export * from "./gen-ai"; export * from "./types"; diff --git a/packages/googleai/src/requests/request.ts b/packages/googleai/src/requests/request.ts index 4b6313f5..6738b6e8 100644 --- a/packages/googleai/src/requests/request.ts +++ b/packages/googleai/src/requests/request.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { RequestOptions, Task } from "../../../core/src/types"; +import { RequestOptions, _Task } from "../../../core/src/types"; import { GoogleGenerativeAIError } from "../../../core/src/errors"; const BASE_URL = "https://generativelanguage.googleapis.com"; @@ -32,7 +32,7 @@ const PACKAGE_LOG_HEADER = "genai-js"; export class RequestUrl { constructor( public model: string, - public task: Task, + public task: _Task, public apiKey: string, public stream: boolean, public requestOptions: RequestOptions, @@ -56,7 +56,7 @@ function getClientHeaders(): string { export async function makeRequest( model: string, - task: Task, + task: _Task, apiKey: string, stream: boolean, body: string, @@ -113,4 +113,4 @@ function buildFetchOptions(requestOptions?: RequestOptions): RequestInit { } return fetchOptions; } -export { Task }; +export { _Task as Task }; diff --git a/packages/googleai/src/types/index.ts b/packages/googleai/src/types/index.ts index f1e20f2b..5737f7d6 100644 --- a/packages/googleai/src/types/index.ts +++ b/packages/googleai/src/types/index.ts @@ -31,6 +31,9 @@ export interface ModelParams extends BaseParams { */ export { BaseParams, + GenerationConfig, + SafetySetting, + Tool, RequestOptions, CountTokensRequest, EmbedContentRequest, @@ -52,7 +55,7 @@ export { EmbedContentResponse, BatchEmbedContentsResponse, StartChatParams, - MakeRequestFunction, + _MakeRequestFunction, Content, TextPart, InlineDataPart, @@ -72,6 +75,6 @@ export { CitationSource, FunctionDeclarationSchemaProperty, FunctionDeclarationSchemaType, - Task, - POSSIBLE_ROLES + _Task, + POSSIBLE_ROLES, } from "../../../core/src";