Skip to content

Commit

Permalink
clean up API types
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Mar 14, 2024
1 parent 132401a commit 44f4f58
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 70 deletions.
12 changes: 4 additions & 8 deletions common/api-review/generative-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Content[]>;
// (undocumented)
model: string;
Expand Down Expand Up @@ -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<Response>;
export type _MakeRequestFunction = (model: string, task: _Task, apiKey: string, stream: boolean, body: string, requestOptions?: RequestOptions) => Promise<Response>;

// @public
export interface ModelParams extends BaseParams {
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 0 additions & 24 deletions docs/reference/generative-ai.chatsession._constructor_.md

This file was deleted.

6 changes: 2 additions & 4 deletions docs/reference/generative-ai.chatsession.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>ChatSession</code> 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

Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/methods/chat-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -47,10 +47,15 @@ export class ChatSession {
private _history: Content[] = [];
private _sendPromise: Promise<void> = 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,
) {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/methods/generate-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
GenerateContentRequest,
HarmBlockThreshold,
HarmCategory,
Task,
_Task,
} from "../types";

use(sinonChai);
Expand Down Expand Up @@ -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) => {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/methods/generate-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -31,12 +31,12 @@ export async function generateContentStream(
apiKey: string,
model: string,
params: GenerateContentRequest,
makeRequest: MakeRequestFunction,
makeRequest: _MakeRequestFunction,
requestOptions?: RequestOptions,
): Promise<GenerateContentStreamResult> {
const response = await makeRequest(
model,
Task.STREAM_GENERATE_CONTENT,
_Task.STREAM_GENERATE_CONTENT,
apiKey,
/* stream */ true,
JSON.stringify(params),
Expand All @@ -51,7 +51,7 @@ export async function generateContent(
params: GenerateContentRequest,
makeRequest: (
model: string,
task: Task,
task: _Task,
apiKey: string,
stream: boolean,
body: string,
Expand All @@ -61,7 +61,7 @@ export async function generateContent(
): Promise<GenerateContentResult> {
const response = await makeRequest(
model,
Task.GENERATE_CONTENT,
_Task.GENERATE_CONTENT,
apiKey,
/* stream */ false,
JSON.stringify(params),
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/googleai/src/gen-ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
1 change: 0 additions & 1 deletion packages/googleai/src/gen-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

/**
Expand Down
7 changes: 1 addition & 6 deletions packages/googleai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 4 additions & 4 deletions packages/googleai/src/requests/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand All @@ -56,7 +56,7 @@ function getClientHeaders(): string {

export async function makeRequest(
model: string,
task: Task,
task: _Task,
apiKey: string,
stream: boolean,
body: string,
Expand Down Expand Up @@ -113,4 +113,4 @@ function buildFetchOptions(requestOptions?: RequestOptions): RequestInit {
}
return fetchOptions;
}
export { Task };
export { _Task as Task };
9 changes: 6 additions & 3 deletions packages/googleai/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export interface ModelParams extends BaseParams {
*/
export {
BaseParams,
GenerationConfig,
SafetySetting,
Tool,
RequestOptions,
CountTokensRequest,
EmbedContentRequest,
Expand All @@ -52,7 +55,7 @@ export {
EmbedContentResponse,
BatchEmbedContentsResponse,
StartChatParams,
MakeRequestFunction,
_MakeRequestFunction,
Content,
TextPart,
InlineDataPart,
Expand All @@ -72,6 +75,6 @@ export {
CitationSource,
FunctionDeclarationSchemaProperty,
FunctionDeclarationSchemaType,
Task,
POSSIBLE_ROLES
_Task,
POSSIBLE_ROLES,
} from "../../../core/src";

0 comments on commit 44f4f58

Please sign in to comment.