Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-spies-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@google/generative-ai": minor
---

Add GoogleAIFileManager for file uploads.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ These quickstarts describe how to add your API key and the SDK to your app, init
Find complete documentation for the Google AI SDKs and the Gemini model in the Google documentation:\
https://ai.google.dev/docs

Find reference docs for this SDK [here in the repo](/docs/reference/generative-ai.md).
Find reference docs for this SDK [here in the repo](/docs/reference/main/generative-ai.md).

## Changelog
- `@google/generative-ai` - [CHANGELOG.md](/packages/main/CHANGELOG.md)
Expand Down
2 changes: 1 addition & 1 deletion packages/main/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ These quickstarts describe how to add your API key and the SDK to your app, init
Find complete documentation for the Google AI SDKs and the Gemini model in the Google documentation:\
https://ai.google.dev/docs

Find reference docs for this SDK [here in the repo](/docs/reference/generative-ai.md).
Find reference docs for this SDK [here in the repo](/docs/reference/main/generative-ai.md).

## Changelog
- `@google/generative-ai` - [CHANGELOG.md](/main/packages/main/CHANGELOG.md)
Expand Down
12 changes: 12 additions & 0 deletions packages/main/api-extractor.files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../config/api-extractor.json",
"mainEntryPointFilePath": "<projectFolder>/dist/files/src/files/index.d.ts",
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/dist/files/files.d.ts"
},
"docModel": {
"enabled": true,
"apiJsonFilePath": "<projectFolder>/temp/files/<unscopedPackageName>-files.api.json"
}
}
4 changes: 4 additions & 0 deletions packages/main/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts"
},
"docModel": {
"enabled": true,
"apiJsonFilePath": "<projectFolder>/temp/main/<unscopedPackageName>.api.json"
}
}
8 changes: 8 additions & 0 deletions packages/main/files/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@google/generative-ai/files",
"description": "GoogleAI file upload manager",
"main": "./dist/files/index.js",
"browser": "./dist/files/index.mjs",
"module": "./dist/files/index.mjs",
"typings": "./dist/files/files.d.ts"
}
13 changes: 10 additions & 3 deletions packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
"import": "./dist/index.mjs",
"default": "./dist/index.js"
},
"./files": {
"types": "./dist/files/files.d.ts",
"require": "./dist/files/index.js",
"import": "./dist/files/index.mjs",
"default": "./dist/files/index.js"
},
"./package.json": "./package.json"
},
"engines": {
"node": ">=18.0.0"
},
"files": [
"dist"
"dist",
"files/package.json"
],
"scripts": {
"build": "rollup -c && yarn api-report",
Expand All @@ -27,8 +34,8 @@
"test:node:unit": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha \"src/**/*.test.ts\"",
"test:node:integration": "yarn build && TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha \"test-integration/node/**/*.test.ts\"",
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"api-report": "api-extractor run --local --verbose",
"docs": "yarn build && yarn api-documenter markdown -i ./temp -o ../../docs/reference/"
"api-report": "api-extractor run --local --verbose && api-extractor run -c api-extractor.files.json --local --verbose",
"docs": "yarn build && yarn api-documenter markdown -i ./temp/main -o ../../docs/reference/main && yarn api-documenter markdown -i ./temp/files -o ../../docs/reference/files"
},
"repository": {
"type": "git",
Expand Down
28 changes: 19 additions & 9 deletions packages/main/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import typescriptPlugin from "rollup-plugin-typescript2";
import typescript from "typescript";
import json from "@rollup/plugin-json";
import pkg from "./package.json" assert { type: "json" };

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies),
);
import filePkg from "./files/package.json" assert { type: "json" };

const es2017BuildPlugins = [
typescriptPlugin({
Expand Down Expand Up @@ -51,8 +48,7 @@ const esmBuilds = [
format: "es",
sourcemap: true,
},
external: (id) =>
deps.some((dep) => id === dep || id.startsWith(`${dep}/`)),
external: ["fs"],
plugins: [...es2017BuildPlugins],
},
];
Expand All @@ -61,11 +57,25 @@ const cjsBuilds = [
{
input: "src/index.ts",
output: [{ file: pkg.main, format: "cjs", sourcemap: true }],
external: (id) =>
deps.some((dep) => id === dep || id.startsWith(`${dep}/`)),
external: ["fs"],
plugins: [...es2017BuildPlugins],
},
];

const filesBuilds = [
{
input: "src/files/index.ts",
output: [{ file: filePkg.module, format: "es", sourcemap: true }],
external: ["fs"],
plugins: [...es2017BuildPlugins],
},
{
input: "src/files/index.ts",
output: [{ file: filePkg.main, format: "cjs", sourcemap: true }],
external: ["fs"],
plugins: [...es2017BuildPlugins],
},
];

// eslint-disable-next-line import/no-default-export
export default [...esmBuilds, ...cjsBuilds];
export default [...esmBuilds, ...cjsBuilds, ...filesBuilds];
22 changes: 22 additions & 0 deletions packages/main/src/files/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @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.
*/
export enum FilesTask {
UPLOAD = "upload",
LIST = "list",
GET = "get",
DELETE = "delete",
}
Loading