gemini-wrapper-ashes 1.0.0

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/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # gemini-wrapper-ashes
2
+
3
+ A lightweight, TypeScript-first wrapper around the Google Gemini API that simplifies model configuration, system instructions, and response handling.
4
+
5
+ ---
6
+
7
+ ## Requirements
8
+
9
+ - Node.js 18 or later
10
+ - A valid Google Gemini API key
11
+
12
+ ---
13
+
14
+ ## Installation
15
+
16
+ npm install gemini-wrapper-ashes
17
+
18
+ ---
19
+
20
+ ## User Manual
21
+
22
+ ### Create a Client
23
+
24
+ import { GeminiClient } from "gemini-wrapper-ashes";
25
+
26
+ const gemini = new GeminiClient({
27
+ apiKey: process.env.GEMINI_API_KEY,
28
+ model: "gemini-1.5-flash",
29
+ instruction: "You are a senior software engineer"
30
+ });
31
+
32
+ ---
33
+
34
+ ### Ask a Question
35
+
36
+ const response = await gemini.ask("Explain closures in JavaScript");
37
+ console.log(response);
38
+
39
+ ---
40
+
41
+ ### Change System Instruction
42
+
43
+ gemini.setInstruction("You are a strict technical interviewer");
44
+
45
+ ---
46
+
47
+ ### Change Model
48
+
49
+ gemini.setModel("gemini-1.5-pro");
50
+
51
+ Any valid Gemini model string is supported. Model validation is delegated to the Gemini API.
52
+
53
+ ---
54
+
55
+ ### Error Handling
56
+
57
+ import { GeminiError } from "gemini-wrapper-ashes";
58
+
59
+ try {
60
+ await gemini.ask("Hello");
61
+ } catch (error) {
62
+ if (error instanceof GeminiError) {
63
+ console.error(error.message);
64
+ console.error(error.code);
65
+ console.error(error.status);
66
+ }
67
+ }
68
+
69
+ ---
70
+
71
+
@@ -0,0 +1,20 @@
1
+ import { GeminiClientConfig } from "./types";
2
+ export declare class GeminiClient {
3
+ private genAI;
4
+ private model;
5
+ private modelName;
6
+ private instruction;
7
+ constructor(config: GeminiClientConfig);
8
+ /**
9
+ * Update system instruction
10
+ */
11
+ setInstruction(instruction: string): void;
12
+ /**
13
+ * Update Gemini model (ANY model allowed)
14
+ */
15
+ setModel(modelName: string): void;
16
+ /**
17
+ * Ask Gemini a question
18
+ */
19
+ ask(prompt: string): Promise<string>;
20
+ }
@@ -0,0 +1,51 @@
1
+ import { GoogleGenerativeAI } from "@google/generative-ai";
2
+ import { GeminiError } from "./errors";
3
+ export class GeminiClient {
4
+ constructor(config) {
5
+ if (!config.apiKey) {
6
+ throw new GeminiError("Gemini API key is required");
7
+ }
8
+ this.genAI = new GoogleGenerativeAI(config.apiKey);
9
+ this.modelName = config.model ?? "gemini-1.5-flash";
10
+ this.instruction = config.instruction ?? "";
11
+ this.model = this.genAI.getGenerativeModel({
12
+ model: this.modelName,
13
+ });
14
+ }
15
+ /**
16
+ * Update system instruction
17
+ */
18
+ setInstruction(instruction) {
19
+ this.instruction = instruction;
20
+ }
21
+ /**
22
+ * Update Gemini model (ANY model allowed)
23
+ */
24
+ setModel(modelName) {
25
+ if (!modelName || !modelName.trim()) {
26
+ throw new GeminiError("Model name cannot be empty");
27
+ }
28
+ this.modelName = modelName;
29
+ this.model = this.genAI.getGenerativeModel({
30
+ model: modelName,
31
+ });
32
+ }
33
+ /**
34
+ * Ask Gemini a question
35
+ */
36
+ async ask(prompt) {
37
+ if (!prompt || !prompt.trim()) {
38
+ throw new GeminiError("Prompt cannot be empty");
39
+ }
40
+ const finalPrompt = this.instruction
41
+ ? `SYSTEM:\n${this.instruction}\n\nUSER:\n${prompt}`
42
+ : prompt;
43
+ try {
44
+ const result = await this.model.generateContent(finalPrompt);
45
+ return result.response.text().trim();
46
+ }
47
+ catch (error) {
48
+ throw new GeminiError(error?.message || "Gemini request failed", error?.code, error?.status || error?.response?.status);
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,5 @@
1
+ export declare class GeminiError extends Error {
2
+ code?: string;
3
+ status?: number;
4
+ constructor(message: string, code?: string, status?: number);
5
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,8 @@
1
+ export class GeminiError extends Error {
2
+ constructor(message, code, status) {
3
+ super(message);
4
+ this.name = "GeminiError";
5
+ this.code = code;
6
+ this.status = status;
7
+ }
8
+ }
@@ -0,0 +1,3 @@
1
+ export { GeminiClient } from "./GeminiClient";
2
+ export { GeminiError } from "./errors";
3
+ export type { GeminiClientConfig } from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { GeminiClient } from "./GeminiClient";
2
+ export { GeminiError } from "./errors";
@@ -0,0 +1,5 @@
1
+ export interface GeminiClientConfig {
2
+ apiKey: string;
3
+ model?: string;
4
+ instruction?: string;
5
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "gemini-wrapper-ashes",
3
+ "version": "1.0.0",
4
+ "description": "A simple and clean wrapper around Google Gemini API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "keywords": ["gemini", "ai", "llm", "google", "wrapper"],
13
+ "author": "Ashes",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "@google/generative-ai": "^0.21.0"
17
+ },
18
+ "devDependencies": {
19
+ "typescript": "^5.4.0"
20
+ }
21
+ }