Skip to content

Add additional Vertex types #8131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/vertexai/src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ export enum HarmBlockThreshold {
BLOCK_NONE = 'BLOCK_NONE'
}

/**
* @public
*/
export enum HarmBlockMethod {
// The harm block method is unspecified.
HARM_BLOCK_METHOD_UNSPECIFIED = 'HARM_BLOCK_METHOD_UNSPECIFIED',
// The harm block method uses both probability and severity scores.
SEVERITY = 'SEVERITY',
// The harm block method uses the probability score.
PROBABILITY = 'PROBABILITY'
}

/**
* Probability that a prompt or candidate matches a harm category.
* @public
Expand All @@ -73,6 +85,23 @@ export enum HarmProbability {
HIGH = 'HIGH'
}

/**
* Harm severity levels.
* @public
*/
export enum HarmSeverity {
// Harm severity unspecified.
HARM_SEVERITY_UNSPECIFIED = 'HARM_SEVERITY_UNSPECIFIED',
// Negligible level of harm severity.
HARM_SEVERITY_NEGLIGIBLE = 'HARM_SEVERITY_NEGLIGIBLE',
// Low level of harm severity.
HARM_SEVERITY_LOW = 'HARM_SEVERITY_LOW',
// Medium level of harm severity.
HARM_SEVERITY_MEDIUM = 'HARM_SEVERITY_MEDIUM',
// High level of harm severity.
HARM_SEVERITY_HIGH = 'HARM_SEVERITY_HIGH'
}

/**
* Reason that a prompt was blocked.
* @public
Expand Down
5 changes: 4 additions & 1 deletion packages/vertexai/src/types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Content } from './content';
import { HarmBlockThreshold, HarmCategory } from './enums';
import { HarmBlockMethod, HarmBlockThreshold, HarmCategory } from './enums';

/**
* Base parameters for a number of methods.
Expand Down Expand Up @@ -52,6 +52,7 @@ export interface GenerateContentRequest extends BaseParams {
export interface SafetySetting {
category: HarmCategory;
threshold: HarmBlockThreshold;
method: HarmBlockMethod;
}

/**
Expand All @@ -65,6 +66,8 @@ export interface GenerationConfig {
temperature?: number;
topP?: number;
topK?: number;
presencePenalty?: number;
frequencyPenalty?: number;
}

/**
Expand Down
61 changes: 60 additions & 1 deletion packages/vertexai/src/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
BlockReason,
FinishReason,
HarmCategory,
HarmProbability
HarmProbability,
HarmSeverity
} from './enums';

/**
Expand Down Expand Up @@ -101,6 +102,7 @@ export interface GenerateContentCandidate {
finishMessage?: string;
safetyRatings?: SafetyRating[];
citationMetadata?: CitationMetadata;
groundingMetadata?: GroundingMetadata;
}

/**
Expand All @@ -124,6 +126,51 @@ export interface Citation {
publicationDate?: Date;
}

/**
* Metadata returned to client when grounding is enabled.
* @public
*/
export interface GroundingMetadata {
webSearchQueries?: string[];
retrievalQueries?: string[];
groundingAttributions: GroundingAttribution[];
}

/**
* @public
*/
export interface GroundingAttribution {
segment: Segment;
confidenceScore?: number;
web?: WebAttribution;
retrievedContext?: RetrievedContextAttribution;
}

/**
* @public
*/
export interface Segment {
partIndex: number;
startIndex: number;
endIndex: number;
}

/**
* @public
*/
export interface WebAttribution {
uri: string;
title: string;
}

/**
* @public
*/
export interface RetrievedContextAttribution {
uri: string;
title: string;
}

/**
* Protobuf google.type.Date
* @public
Expand All @@ -141,12 +188,24 @@ export interface Date {
export interface SafetyRating {
category: HarmCategory;
probability: HarmProbability;
severity: HarmSeverity;
probabilityScore: number;
severityScore: number;
blocked: boolean;
}

/**
* Response from calling {@link GenerativeModel.countTokens}.
* @public
*/
export interface CountTokensResponse {
/**
* The total number of tokens counted across all instances from the request.
*/
totalTokens: number;
/**
* The total number of billable characters counted across all instances
* from the request.
*/
totalBillableCharacters?: number;
}