Skip to content

Commit a89d427

Browse files
authoredApr 19, 2024··
Add Files API (#102)
1 parent fa952fa commit a89d427

20 files changed

+985
-17
lines changed
 

‎.changeset/tiny-spies-pretend.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@google/generative-ai": minor
3+
---
4+
5+
Add GoogleAIFileManager for file uploads.

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ These quickstarts describe how to add your API key and the SDK to your app, init
9090
Find complete documentation for the Google AI SDKs and the Gemini model in the Google documentation:\
9191
https://ai.google.dev/docs
9292

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

9595
## Changelog
9696
- `@google/generative-ai` - [CHANGELOG.md](/packages/main/CHANGELOG.md)

‎packages/main/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ These quickstarts describe how to add your API key and the SDK to your app, init
9090
Find complete documentation for the Google AI SDKs and the Gemini model in the Google documentation:\
9191
https://ai.google.dev/docs
9292

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

9595
## Changelog
9696
- `@google/generative-ai` - [CHANGELOG.md](/main/packages/main/CHANGELOG.md)
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../config/api-extractor.json",
3+
"mainEntryPointFilePath": "<projectFolder>/dist/files/src/files/index.d.ts",
4+
"dtsRollup": {
5+
"enabled": true,
6+
"untrimmedFilePath": "<projectFolder>/dist/files/files.d.ts"
7+
},
8+
"docModel": {
9+
"enabled": true,
10+
"apiJsonFilePath": "<projectFolder>/temp/files/<unscopedPackageName>-files.api.json"
11+
}
12+
}

‎packages/main/api-extractor.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
"dtsRollup": {
55
"enabled": true,
66
"untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts"
7+
},
8+
"docModel": {
9+
"enabled": true,
10+
"apiJsonFilePath": "<projectFolder>/temp/main/<unscopedPackageName>.api.json"
711
}
812
}

‎packages/main/files/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@google/generative-ai/files",
3+
"description": "GoogleAI file upload manager",
4+
"main": "./dist/files/index.js",
5+
"browser": "./dist/files/index.mjs",
6+
"module": "./dist/files/index.mjs",
7+
"typings": "./dist/files/files.d.ts"
8+
}

‎packages/main/package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
"import": "./dist/index.mjs",
1313
"default": "./dist/index.js"
1414
},
15+
"./files": {
16+
"types": "./dist/files/files.d.ts",
17+
"require": "./dist/files/index.js",
18+
"import": "./dist/files/index.mjs",
19+
"default": "./dist/files/index.js"
20+
},
1521
"./package.json": "./package.json"
1622
},
1723
"engines": {
1824
"node": ">=18.0.0"
1925
},
2026
"files": [
21-
"dist"
27+
"dist",
28+
"files/package.json"
2229
],
2330
"scripts": {
2431
"build": "rollup -c && yarn api-report",
@@ -27,8 +34,8 @@
2734
"test:node:unit": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha \"src/**/*.test.ts\"",
2835
"test:node:integration": "yarn build && TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha \"test-integration/node/**/*.test.ts\"",
2936
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
30-
"api-report": "api-extractor run --local --verbose",
31-
"docs": "yarn build && yarn api-documenter markdown -i ./temp -o ../../docs/reference/"
37+
"api-report": "api-extractor run --local --verbose && api-extractor run -c api-extractor.files.json --local --verbose",
38+
"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"
3239
},
3340
"repository": {
3441
"type": "git",

‎packages/main/rollup.config.mjs

+19-9
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ import typescriptPlugin from "rollup-plugin-typescript2";
2020
import typescript from "typescript";
2121
import json from "@rollup/plugin-json";
2222
import pkg from "./package.json" assert { type: "json" };
23-
24-
const deps = Object.keys(
25-
Object.assign({}, pkg.peerDependencies, pkg.dependencies),
26-
);
23+
import filePkg from "./files/package.json" assert { type: "json" };
2724

2825
const es2017BuildPlugins = [
2926
typescriptPlugin({
@@ -51,8 +48,7 @@ const esmBuilds = [
5148
format: "es",
5249
sourcemap: true,
5350
},
54-
external: (id) =>
55-
deps.some((dep) => id === dep || id.startsWith(`${dep}/`)),
51+
external: ["fs"],
5652
plugins: [...es2017BuildPlugins],
5753
},
5854
];
@@ -61,11 +57,25 @@ const cjsBuilds = [
6157
{
6258
input: "src/index.ts",
6359
output: [{ file: pkg.main, format: "cjs", sourcemap: true }],
64-
external: (id) =>
65-
deps.some((dep) => id === dep || id.startsWith(`${dep}/`)),
60+
external: ["fs"],
61+
plugins: [...es2017BuildPlugins],
62+
},
63+
];
64+
65+
const filesBuilds = [
66+
{
67+
input: "src/files/index.ts",
68+
output: [{ file: filePkg.module, format: "es", sourcemap: true }],
69+
external: ["fs"],
70+
plugins: [...es2017BuildPlugins],
71+
},
72+
{
73+
input: "src/files/index.ts",
74+
output: [{ file: filePkg.main, format: "cjs", sourcemap: true }],
75+
external: ["fs"],
6676
plugins: [...es2017BuildPlugins],
6777
},
6878
];
6979

7080
// eslint-disable-next-line import/no-default-export
71-
export default [...esmBuilds, ...cjsBuilds];
81+
export default [...esmBuilds, ...cjsBuilds, ...filesBuilds];

‎packages/main/src/files/constants.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
export enum FilesTask {
18+
UPLOAD = "upload",
19+
LIST = "list",
20+
GET = "get",
21+
DELETE = "delete",
22+
}

0 commit comments

Comments
 (0)
Please sign in to comment.