@google/generative-ai
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -43,2 +43,8 @@ 'use strict'; | ||
} | ||
/** | ||
* Errors in the contents of a request originating from user input. | ||
* @public | ||
*/ | ||
class GoogleGenerativeAIRequestInputError extends GoogleGenerativeAIError { | ||
} | ||
@@ -67,3 +73,3 @@ /** | ||
*/ | ||
const PACKAGE_VERSION = "0.11.0"; | ||
const PACKAGE_VERSION = "0.11.1"; | ||
const PACKAGE_LOG_HEADER = "genai-js"; | ||
@@ -251,3 +257,2 @@ var Task; | ||
async uploadFile(filePath, fileMetadata) { | ||
var _a; | ||
const file = fs.readFileSync(filePath); | ||
@@ -259,9 +264,3 @@ const url = new FilesRequestUrl(FilesTask.UPLOAD, this.apiKey, this._requestOptions); | ||
uploadHeaders.append("Content-Type", `multipart/related; boundary=${boundary}`); | ||
const uploadMetadata = { | ||
mimeType: fileMetadata.mimeType, | ||
displayName: fileMetadata.displayName, | ||
name: ((_a = fileMetadata.name) === null || _a === void 0 ? void 0 : _a.includes("/")) | ||
? fileMetadata.name | ||
: `files/${fileMetadata.name}`, | ||
}; | ||
const uploadMetadata = getUploadMetadata(fileMetadata); | ||
// Multipart formatting code taken from @firebase/storage | ||
@@ -340,2 +339,17 @@ const metadataString = JSON.stringify({ file: uploadMetadata }); | ||
} | ||
function getUploadMetadata(inputMetadata) { | ||
if (!inputMetadata.mimeType) { | ||
throw new GoogleGenerativeAIRequestInputError("Must provide a mimeType."); | ||
} | ||
const uploadMetadata = { | ||
mimeType: inputMetadata.mimeType, | ||
displayName: inputMetadata.displayName, | ||
}; | ||
if (inputMetadata.name) { | ||
uploadMetadata.name = inputMetadata.name.includes("/") | ||
? inputMetadata.name | ||
: `files/${inputMetadata.name}`; | ||
} | ||
return uploadMetadata; | ||
} | ||
@@ -342,0 +356,0 @@ /** |
@@ -48,1 +48,2 @@ /** | ||
} | ||
export declare function getUploadMetadata(inputMetadata: FileMetadata): FileMetadata; |
@@ -250,3 +250,3 @@ 'use strict'; | ||
*/ | ||
const PACKAGE_VERSION = "0.11.0"; | ||
const PACKAGE_VERSION = "0.11.1"; | ||
const PACKAGE_LOG_HEADER = "genai-js"; | ||
@@ -253,0 +253,0 @@ var Task; |
@@ -48,1 +48,2 @@ /** | ||
} | ||
export declare function getUploadMetadata(inputMetadata: FileMetadata): FileMetadata; |
{ | ||
"name": "@google/generative-ai", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "Google AI JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
255470
6798