Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google/generative-ai

Package Overview
Dependencies
Maintainers
4
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google/generative-ai - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

29

dist/files/index.js

@@ -21,2 +21,6 @@ 'use strict';

*/
/**
* Basic error type for this SDK.
* @public
*/
class GoogleGenerativeAIError extends Error {

@@ -27,2 +31,14 @@ constructor(message) {

}
/**
* Error class covering HTTP errors when calling the server. Includes HTTP
* status, statusText, and optional details, if provided in the server response.
*/
class GoogleGenerativeAIFetchError extends GoogleGenerativeAIError {
constructor(message, status, statusText, errorDetails) {
super(message);
this.status = status;
this.statusText = statusText;
this.errorDetails = errorDetails;
}
}

@@ -51,3 +67,3 @@ /**

*/
const PACKAGE_VERSION = "0.8.0";
const PACKAGE_VERSION = "0.9.0";
const PACKAGE_LOG_HEADER = "genai-js";

@@ -167,2 +183,3 @@ var Task;

let message = "";
let errorDetails;
try {

@@ -173,2 +190,3 @@ const json = await response.json();

message += ` ${JSON.stringify(json.error.details)}`;
errorDetails = json.error.details;
}

@@ -179,3 +197,3 @@ }

}
throw new Error(`[${response.status} ${response.statusText}] ${message}`);
throw new GoogleGenerativeAIFetchError(`Error fetching from ${url.toString()}: [${response.status} ${response.statusText}] ${message}`, response.status, response.statusText, errorDetails);
}

@@ -187,4 +205,7 @@ else {

catch (e) {
const err = new GoogleGenerativeAIError(`Error on task type: ${url.task} fetching from ${url.toString()}: ${e.message}`);
err.stack = e.stack;
let err = e;
if (!(e instanceof GoogleGenerativeAIFetchError)) {
err = new GoogleGenerativeAIError(`Error fetching from ${url.toString()}: ${e.message}`);
err.stack = e.stack;
}
throw err;

@@ -191,0 +212,0 @@ }

@@ -17,5 +17,14 @@ /**

*/
/**
* Basic error type for this SDK.
* @public
*/
export declare class GoogleGenerativeAIError extends Error {
constructor(message: string);
}
/**
* Errors in the contents of a response from the model. This includes parsing
* errors, or responses including a safety block reason.
* @public
*/
export declare class GoogleGenerativeAIResponseError<T> extends GoogleGenerativeAIError {

@@ -25,1 +34,23 @@ response?: T;

}
/**
* Error class covering HTTP errors when calling the server. Includes HTTP
* status, statusText, and optional details, if provided in the server response.
*/
export declare class GoogleGenerativeAIFetchError extends GoogleGenerativeAIError {
status?: number;
statusText?: string;
errorDetails?: ErrorDetails[];
constructor(message: string, status?: number, statusText?: string, errorDetails?: ErrorDetails[]);
}
/**
* Details object that may be included in an error response.
* @public
*/
interface ErrorDetails {
"@type"?: string;
reason?: string;
domain?: string;
metadata?: Record<string, unknown>;
[key: string]: unknown;
}
export {};

@@ -19,1 +19,2 @@ /**

export * from "./gen-ai";
export * from "./errors";

@@ -18,4 +18,5 @@ /**

import { Content, EmbedContentRequest, GenerateContentRequest, Part } from "../../types";
export declare function formatSystemInstruction(input?: string | Part | Content): Content | undefined;
export declare function formatNewContent(request: string | Array<string | Part>): Content;
export declare function formatGenerateContentInput(params: GenerateContentRequest | string | Array<string | Part>): GenerateContentRequest;
export declare function formatEmbedContentInput(params: EmbedContentRequest | string | Array<string | Part>): EmbedContentRequest;

8

dist/files/types/requests.d.ts

@@ -17,3 +17,3 @@ /**

*/
import { Content } from "./content";
import { Content, Part } from "./content";
import { FunctionCallingMode, HarmBlockThreshold, HarmCategory, TaskType } from "./enums";

@@ -36,3 +36,3 @@ /**

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -47,3 +47,3 @@ /**

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -78,3 +78,3 @@ /**

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -81,0 +81,0 @@ /**

@@ -181,2 +181,14 @@ /**

/**
* Details object that may be included in an error response.
* @public
*/
declare interface ErrorDetails {
"@type"?: string;
reason?: string;
domain?: string;
metadata?: Record<string, unknown>;
[key: string]: unknown;
}
/**
* Data pointing to a file uploaded with the Files API.

@@ -435,3 +447,3 @@ * @public

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -557,2 +569,47 @@

/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Basic error type for this SDK.
* @public
*/
export declare class GoogleGenerativeAIError extends Error {
constructor(message: string);
}
/**
* Error class covering HTTP errors when calling the server. Includes HTTP
* status, statusText, and optional details, if provided in the server response.
*/
export declare class GoogleGenerativeAIFetchError extends GoogleGenerativeAIError {
status?: number;
statusText?: string;
errorDetails?: ErrorDetails[];
constructor(message: string, status?: number, statusText?: string, errorDetails?: ErrorDetails[]);
}
/**
* Errors in the contents of a response from the model. This includes parsing
* errors, or responses including a safety block reason.
* @public
*/
export declare class GoogleGenerativeAIResponseError<T> extends GoogleGenerativeAIError {
response?: T;
constructor(message: string, response?: T);
}
/**
* Threshold above which a prompt or candidate will be blocked.

@@ -613,3 +670,3 @@ * @public

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -691,3 +748,3 @@

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -694,0 +751,0 @@

@@ -188,2 +188,6 @@ 'use strict';

*/
/**
* Basic error type for this SDK.
* @public
*/
class GoogleGenerativeAIError extends Error {

@@ -194,2 +198,7 @@ constructor(message) {

}
/**
* Errors in the contents of a response from the model. This includes parsing
* errors, or responses including a safety block reason.
* @public
*/
class GoogleGenerativeAIResponseError extends GoogleGenerativeAIError {

@@ -201,2 +210,14 @@ constructor(message, response) {

}
/**
* Error class covering HTTP errors when calling the server. Includes HTTP
* status, statusText, and optional details, if provided in the server response.
*/
class GoogleGenerativeAIFetchError extends GoogleGenerativeAIError {
constructor(message, status, statusText, errorDetails) {
super(message);
this.status = status;
this.statusText = statusText;
this.errorDetails = errorDetails;
}
}

@@ -225,3 +246,3 @@ /**

*/
const PACKAGE_VERSION = "0.8.0";
const PACKAGE_VERSION = "0.9.0";
const PACKAGE_LOG_HEADER = "genai-js";

@@ -297,2 +318,3 @@ var Task;

let message = "";
let errorDetails;
try {

@@ -303,2 +325,3 @@ const json = await response.json();

message += ` ${JSON.stringify(json.error.details)}`;
errorDetails = json.error.details;
}

@@ -309,8 +332,11 @@ }

}
throw new Error(`[${response.status} ${response.statusText}] ${message}`);
throw new GoogleGenerativeAIFetchError(`Error fetching from ${url.toString()}: [${response.status} ${response.statusText}] ${message}`, response.status, response.statusText, errorDetails);
}
}
catch (e) {
const err = new GoogleGenerativeAIError(`Error fetching from ${url.toString()}: ${e.message}`);
err.stack = e.stack;
let err = e;
if (!(e instanceof GoogleGenerativeAIFetchError)) {
err = new GoogleGenerativeAIError(`Error fetching from ${url.toString()}: ${e.message}`);
err.stack = e.stack;
}
throw err;

@@ -724,2 +750,22 @@ }

*/
function formatSystemInstruction(input) {
// null or undefined
if (input == null) {
return undefined;
}
else if (typeof input === "string") {
return { role: "system", parts: [{ text: input }] };
}
else if (input.text) {
return { role: "system", parts: [input] };
}
else if (input.parts) {
if (!input.role) {
return { role: "system", parts: input.parts };
}
else {
return input;
}
}
}
function formatNewContent(request) {

@@ -777,9 +823,15 @@ let newParts = [];

function formatGenerateContentInput(params) {
let formattedRequest;
if (params.contents) {
return params;
formattedRequest = params;
}
else {
// Array or string
const content = formatNewContent(params);
return { contents: [content] };
formattedRequest = { contents: [content] };
}
if (params.systemInstruction) {
formattedRequest.systemInstruction = formatSystemInstruction(params.systemInstruction);
}
return formattedRequest;
}

@@ -1108,3 +1160,3 @@ function formatEmbedContentInput(params) {

this.toolConfig = modelParams.toolConfig;
this.systemInstruction = modelParams.systemInstruction;
this.systemInstruction = formatSystemInstruction(modelParams.systemInstruction);
this.requestOptions = requestOptions || {};

@@ -1198,3 +1250,6 @@ }

exports.GoogleGenerativeAI = GoogleGenerativeAI;
exports.GoogleGenerativeAIError = GoogleGenerativeAIError;
exports.GoogleGenerativeAIFetchError = GoogleGenerativeAIFetchError;
exports.GoogleGenerativeAIResponseError = GoogleGenerativeAIResponseError;
exports.POSSIBLE_ROLES = POSSIBLE_ROLES;
//# sourceMappingURL=index.js.map

@@ -17,5 +17,14 @@ /**

*/
/**
* Basic error type for this SDK.
* @public
*/
export declare class GoogleGenerativeAIError extends Error {
constructor(message: string);
}
/**
* Errors in the contents of a response from the model. This includes parsing
* errors, or responses including a safety block reason.
* @public
*/
export declare class GoogleGenerativeAIResponseError<T> extends GoogleGenerativeAIError {

@@ -25,1 +34,23 @@ response?: T;

}
/**
* Error class covering HTTP errors when calling the server. Includes HTTP
* status, statusText, and optional details, if provided in the server response.
*/
export declare class GoogleGenerativeAIFetchError extends GoogleGenerativeAIError {
status?: number;
statusText?: string;
errorDetails?: ErrorDetails[];
constructor(message: string, status?: number, statusText?: string, errorDetails?: ErrorDetails[]);
}
/**
* Details object that may be included in an error response.
* @public
*/
interface ErrorDetails {
"@type"?: string;
reason?: string;
domain?: string;
metadata?: Record<string, unknown>;
[key: string]: unknown;
}
export {};

@@ -19,1 +19,2 @@ /**

export * from "./gen-ai";
export * from "./errors";

@@ -18,4 +18,5 @@ /**

import { Content, EmbedContentRequest, GenerateContentRequest, Part } from "../../types";
export declare function formatSystemInstruction(input?: string | Part | Content): Content | undefined;
export declare function formatNewContent(request: string | Array<string | Part>): Content;
export declare function formatGenerateContentInput(params: GenerateContentRequest | string | Array<string | Part>): GenerateContentRequest;
export declare function formatEmbedContentInput(params: EmbedContentRequest | string | Array<string | Part>): EmbedContentRequest;

@@ -17,3 +17,3 @@ /**

*/
import { Content } from "./content";
import { Content, Part } from "./content";
import { FunctionCallingMode, HarmBlockThreshold, HarmCategory, TaskType } from "./enums";

@@ -36,3 +36,3 @@ /**

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -47,3 +47,3 @@ /**

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -78,3 +78,3 @@ /**

toolConfig?: ToolConfig;
systemInstruction?: Content;
systemInstruction?: string | Part | Content;
}

@@ -81,0 +81,0 @@ /**

{
"name": "@google/generative-ai",
"version": "0.8.0",
"version": "0.9.0",
"description": "Google AI JavaScript SDK",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,3 +0,11 @@

# Google AI JavaScript SDK
# Google AI SDK for JavaScript
> [!CAUTION]
> **Using the Google AI SDK for JavaScript directly from a client-side app is
> recommended for prototyping only.** If you plan to enable billing, we strongly
> recommend that you call the Google AI Gemini API only server-side to keep your
> API key safe. You risk potentially exposing your API key to malicious actors
> if you embed your API key directly in your JavaScript app or fetch it remotely
> at runtime.
The Google AI JavaScript SDK enables developers to use Google's state-of-the-art generative AI models (like Gemini) to build AI-powered features and applications. This SDK supports use cases like:

@@ -4,0 +12,0 @@ - Generate text from text-only input

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc