From b6f1af0bb49bffa63bae7b63b5d0ddfd0e808fee Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 8 May 2025 09:43:47 +0800 Subject: [PATCH] Create NodeJS package --- package.json | 26 ++++++++++++++++++++++++++ scripts/main.js | 17 +++++++++++++++++ scripts/prompt.js | 22 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 package.json create mode 100644 scripts/main.js create mode 100644 scripts/prompt.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..a909250 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "googlegeminiapitest", + "version": "0.0.1", + "description": "Some testing with the Google Gemini API using NodeJS", + "main": "scripts/main.js", + "type": "module", + "scripts": { + "test": "node --watch scripts/main.js", + "run": "node scripts/main.js" + }, + "repository": { + "type": "git", + "url": "https://gitdab.com/buzzcode2007/GoogleGeminiAPITests_NodeJS.git" + }, + "keywords": [ + "AI", + "Google", + "Gemini", + "test" + ], + "dependencies": { + "@google/genai": "^0.13.0", + "dotenv": "^8.2.0" + }, + "author": "buzzcode2007" +} diff --git a/scripts/main.js b/scripts/main.js new file mode 100644 index 0000000..6a39c92 --- /dev/null +++ b/scripts/main.js @@ -0,0 +1,17 @@ +import Tests from './prompt.js'; + +class main { + constructor() { + this.platform = new Tests(); + this.first(); + } + + first () { + let result = this.platform.generate("gemini-1.5-flash", "What is a TPU?"); + result.then((log) => { + console.log(log.text) + }) + } +} + +let runtime = new main(); \ No newline at end of file diff --git a/scripts/prompt.js b/scripts/prompt.js new file mode 100644 index 0000000..38ef5b7 --- /dev/null +++ b/scripts/prompt.js @@ -0,0 +1,22 @@ +import { GoogleGenAI } from "@google/genai"; + +class Tests { + #key; + #toolkit; + + constructor () { + this.#key = process.env.GoogleGenAIKey + this.#toolkit = new GoogleGenAI({ apiKey: this.#key }); + } + + async generate (model, contents) { + const response = await this.#toolkit.models.generateContent({ + "model": model, + "contents": contents + }); + + return response; + } +} + +export default Tests; \ No newline at end of file