@codixfy/gemini
Version:
An npm package for nodejs that makes easier working with Gemini AI API. Includes some useful methods solving common tasks, helping quick and stable development.
101 lines (99 loc) • 3.96 kB
text/typescript
/**
* Represents the various models available in the Gemini series.
* The different model types include standard, professional, vision, and flash versions.
*
* Available models:
* - "gemini-1.0-pro": Gemini version 1.0 professional model.
* - "gemini-pro-vision": Vision series in the professional model.
* - "gemini-1.5-pro": Gemini version 1.5 professional model.
* - "gemini-1.5-flash": Flash series model in the Gemini version 1.5.
* - "gemini-1.0-pro-latest": Latest variant of the Gemini version 1.0 professional model.
* - "gemini-pro-vision-latest": Latest variant of the professional vision series.
* - "gemini-1.5-pro-latest": Latest variant of the Gemini version 1.5 professional model.
* - "gemini-1.5-flash-latest": Latest variant in the flash series for Gemini version 1.5.
*/
type Models = "gemini-pro-vision" | "gemini-1.5-pro" | "gemini-1.5-flash" | "gemini-pro-vision-latest" | "gemini-1.5-pro-latest" | "gemini-1.5-flash-latest" | "gemini-1.5-flash-8b-001" | "gemini-1.5-flash-8b" | "gemini-1.5-flash-8b-latest" | "gemini-2.0-flash";
/**
* Configuration options for Gemini service.
*/
type GeminiOptions = {
model?: Models;
safetySettings?: {
blockDangerousContent?: boolean;
blockExplicitContent?: boolean;
blockHarassmentContent?: boolean;
blockHateContent?: boolean;
};
instructions?: string;
useLatestModel?: boolean;
};
/**
* Represents the type definition for contents, which includes an array of objects.
* Each object contains a `role` indicating the source of the content,
* and `parts`, which can be any type.
*
* @typedef {Object} ContentsType
* @property {"user" | "model"} role - The role of the content's source,
* either "user" or "model".
* @property {any} parts - The content itself, which can be of any type.
*/
type ContentsType = [
{
role: "user" | "model";
parts: any;
}
];
/**
* MimeType is a union type representing a set of common image MIME types.
*
* - "image/png": Indicates that the image file is in PNG format.
* - "image/jpeg": Indicates that the image file is in JPEG format.
* - "image/gif": Indicates that the image file is in GIF format.
* - "image/webp": Indicates that the image file is in WebP format.
*/
type MimeType = "image/png" | "image/jpeg" | "image/gif" | "image/webp" | "video/mp4" | "audio/wav" | "audio/mp3" | "audio/aac";
/**
* Class representing the Gemini model for generating AI content.
*/
declare class Gemini {
private genAI;
protected model: any;
private currentModel;
private apiKey;
constructor(apiKey: string, options?: GeminiOptions);
ask(message: string, extra?: {
files?: string[];
stream?: (data: string) => void;
}): Promise<any>;
createChat(chartContext?: any): GeminiChat;
}
/**
* GeminiChat class is responsible for managing and interacting with a chat-based model.
* It can send messages, manage the chat context, and handle image processing for certain models.
*/
declare class GeminiChat {
model: any;
chatContext: any;
currentModel: Models;
constructor(model: any, chatContext: any, currentModel: Models);
send(message: string, extra?: {
files?: string[];
stream?: (data: string) => void;
}): Promise<any>;
reset(): Promise<void>;
save(): Promise<any>;
load(context: any): Promise<void>;
}
/**
* GeminiUtils class provides utility methods related to image processing.
*/
declare class GeminiUtils {
static fileToGenerativePart(file: string): Promise<{
inline_data: {
data: any;
mime_type: MimeType;
};
}>;
static mimeTypeFromFile(file: string): Promise<"image/png" | "image/jpeg" | "image/gif" | "image/webp" | "video/mp4" | "audio/wav" | "audio/mp3" | "audio/aac">;
}
export { type ContentsType, Gemini, type GeminiOptions, GeminiUtils, type MimeType, type Models };