adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
147 lines (146 loc) • 4.85 kB
TypeScript
import { Content, GroundingMetadata } from './types';
/**
* Interface representing a response from the LLM model API.
*/
export interface GenerateContentResponse {
candidates?: {
content?: Content;
grounding_metadata?: GroundingMetadata;
finish_reason?: string;
finish_message?: string;
}[];
prompt_feedback?: {
block_reason?: string;
block_reason_message?: string;
};
}
/**
* Options for creating an LlmResponse.
*/
export interface LlmResponseOptions {
/**
* The content of the response.
*/
content?: Content;
/**
* The grounding metadata of the response.
*/
groundingMetadata?: GroundingMetadata;
/**
* Indicates whether the text content is part of an unfinished text stream.
* Only used for streaming mode and when the content is plain text.
*/
partial?: boolean;
/**
* Indicates whether the response from the model is complete.
* Only used for streaming mode.
*/
turnComplete?: boolean;
/**
* Error code if the response is an error. Code varies by model.
*/
errorCode?: string;
/**
* Error message if the response is an error.
*/
errorMessage?: string;
/**
* Flag indicating that LLM was interrupted when generating the content.
* Usually it's due to user interruption during a bidi streaming.
*/
interrupted?: boolean;
/**
* The custom metadata of the LlmResponse.
* An optional key-value pair to label an LlmResponse.
* NOTE: the entire dict must be JSON serializable.
*/
customMetadata?: Record<string, any>;
}
/**
* LLM response class that provides the first candidate response from the model
* if available. Otherwise, returns error code and message.
*/
export declare class LlmResponse {
/**
* The content of the response.
*/
content?: Content;
/**
* The grounding metadata of the response.
*/
groundingMetadata?: GroundingMetadata;
/**
* Indicates whether the text content is part of an unfinished text stream.
* Only used for streaming mode and when the content is plain text.
*/
partial?: boolean;
/**
* Indicates whether the response from the model is complete.
* Only used for streaming mode.
*/
turnComplete?: boolean;
/**
* Error code if the response is an error. Code varies by model.
*/
errorCode?: string;
/**
* Error message if the response is an error.
*/
errorMessage?: string;
/**
* Flag indicating that LLM was interrupted when generating the content.
* Usually it's due to user interruption during a bidi streaming.
*/
interrupted?: boolean;
/**
* The custom metadata of the LlmResponse.
* An optional key-value pair to label an LlmResponse.
* NOTE: the entire dict must be JSON serializable.
*/
customMetadata?: Record<string, any>;
/**
* Creates a new LlmResponse instance.
* @param options Configuration options for the response
*/
constructor(options?: LlmResponseOptions);
/**
* Creates an LlmResponse from a GenerateContentResponse.
* @param generateContentResponse The GenerateContentResponse to create the LlmResponse from.
* @returns The LlmResponse.
*/
static create(generateContentResponse: GenerateContentResponse): LlmResponse;
/**
* Checks if this response has an error.
* @returns True if this response has an error, false otherwise.
*/
hasError(): boolean;
/**
* Gets the text content of this response, if available.
* @returns The text content as a string, or undefined if not available.
*/
getText(): string | undefined;
/**
* Creates a copy of this LlmResponse with the given partial flag.
* @param partial The partial flag value.
* @returns A new LlmResponse with the updated partial flag.
*/
withPartial(partial: boolean): LlmResponse;
/**
* Creates a copy of this LlmResponse with the given turn complete flag.
* @param turnComplete The turn complete flag value.
* @returns A new LlmResponse with the updated turn complete flag.
*/
withTurnComplete(turnComplete: boolean): LlmResponse;
/**
* Creates a copy of this LlmResponse with the given interrupted flag.
* @param interrupted The interrupted flag value.
* @returns A new LlmResponse with the updated interrupted flag.
*/
withInterrupted(interrupted: boolean): LlmResponse;
/**
* Creates a copy of this LlmResponse with the given custom metadata.
* @param customMetadata The custom metadata.
* @returns A new LlmResponse with the updated custom metadata.
*/
withCustomMetadata(customMetadata: Record<string, any>): LlmResponse;
}