Skip to content

Commit

Permalink
Add additional Vertex types (#8131)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Apr 8, 2024
1 parent acef5e3 commit f25ccbb
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
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;
}

0 comments on commit f25ccbb

Please sign in to comment.