@adminforth/completion-adapter-google-gemini 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Changelog.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [1.0.0] - 2024-12-06
2
+
3
+ ### Added
4
+
5
+ - Added Google Gemini completion adapter.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Devforth.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { GoogleGenAI } from "@google/genai";
11
+ export default class CompletionAdapterGoogleGemini {
12
+ constructor(options) {
13
+ this.complete = (content_1, ...args_1) => __awaiter(this, [content_1, ...args_1], void 0, function* (content, stop = ["."], maxTokens = 50) {
14
+ var _a, _b;
15
+ const ai = new GoogleGenAI({
16
+ apiKey: this.options.geminiApiKey,
17
+ });
18
+ try {
19
+ const response = yield ai.models.generateContent({
20
+ model: this.options.model || "gemini-3-flash-preview",
21
+ contents: content,
22
+ config: {
23
+ temperature: (_b = (_a = this.options.expert) === null || _a === void 0 ? void 0 : _a.temperature) !== null && _b !== void 0 ? _b : 0.7,
24
+ maxOutputTokens: maxTokens,
25
+ stopSequences: stop,
26
+ },
27
+ });
28
+ return {
29
+ content: response.text,
30
+ };
31
+ }
32
+ catch (error) {
33
+ return { error: error.message };
34
+ }
35
+ });
36
+ this.options = options;
37
+ }
38
+ validate() {
39
+ if (!this.options.geminiApiKey) {
40
+ throw new Error("geminiApiKey is required");
41
+ }
42
+ }
43
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type { AdapterOptions } from "./types.js";
2
+ import type { CompletionAdapter } from "adminforth";
3
+ import { GoogleGenAI } from "@google/genai";
4
+
5
+
6
+ export default class CompletionAdapterGoogleGemini
7
+ implements CompletionAdapter
8
+ {
9
+ options: AdapterOptions;
10
+
11
+ constructor(options: AdapterOptions) {
12
+ this.options = options;
13
+ }
14
+
15
+ validate() {
16
+ if (!this.options.geminiApiKey) {
17
+ throw new Error("geminiApiKey is required");
18
+ }
19
+ }
20
+
21
+ complete = async (content: string, stop = ["."], maxTokens = 50): Promise<{
22
+ content?: string;
23
+ finishReason?: string;
24
+ error?: string;
25
+ }> => {
26
+
27
+ const ai = new GoogleGenAI({
28
+ apiKey: this.options.geminiApiKey,
29
+ });
30
+
31
+ try {
32
+ const response = await ai.models.generateContent({
33
+ model: this.options.model || "gemini-3-flash-preview",
34
+ contents: content,
35
+ config: {
36
+ temperature: this.options.expert?.temperature ?? 0.7,
37
+ maxOutputTokens: maxTokens,
38
+ stopSequences: stop,
39
+ },
40
+ });
41
+ return {
42
+ content: response.text,
43
+ };
44
+ } catch (error) {
45
+ return { error: (error as Error).message };
46
+ }
47
+ };
48
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@adminforth/completion-adapter-google-gemini",
3
+ "version": "1.0.2",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "tsc && npm version patch",
9
+ "rollout": "npm run build && npm publish --access public",
10
+ "prepare": "npm link adminforth"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "description": "",
16
+ "dependencies": {
17
+ "@google/genai": "^1.35.0",
18
+ "adminforth": "next"
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "^5.9.3"
22
+ }
23
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include*/
4
+ "module": "node16", /* Specify what module code is generated. */
5
+ "outDir": "./dist", /* Specify an output folder for all emitted files. */
6
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
7
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
8
+ "strict": false, /* Enable all strict type-checking options. */
9
+ "skipLibCheck": true, /* Skip type checking all .d.ts files. */
10
+ },
11
+ "exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
12
+ }
package/types.ts ADDED
@@ -0,0 +1,23 @@
1
+ export interface AdapterOptions {
2
+ /**
3
+ * Google API key. Go to https://aistudio.google.com/api-keys, go to Dashboard -> API keys -> Create new secret key
4
+ * Set geminiApiKey: process.env.GEMINI_API_KEY to access it
5
+ */
6
+ geminiApiKey: string;
7
+
8
+ /**
9
+ * Model name. Go to https://ai.google.dev/gemini-api/docs/models, select model and copy name.
10
+ * Default is `gemini-3-flash-preview`. Use e.g. more expensive `gemini-3-pro-preview` for more powerful model.
11
+ */
12
+ model?: string;
13
+
14
+ /**
15
+ * Expert settings
16
+ */
17
+ expert?: {
18
+ /**
19
+ * Temperature (0-1). Lower is more deterministic, higher is more unpredicted creative. Default is 0.7.
20
+ */
21
+ temperature?: number;
22
+ };
23
+ }