Create NodeJS package
This commit is contained in:
		
							parent
							
								
									483c5bf4fd
								
							
						
					
					
						commit
						b6f1af0bb4
					
				
					 3 changed files with 65 additions and 0 deletions
				
			
		
							
								
								
									
										26
									
								
								package.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								package.json
									
										
									
									
									
										Normal file
									
								
							|  | @ -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" | ||||||
|  | } | ||||||
							
								
								
									
										17
									
								
								scripts/main.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								scripts/main.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -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(); | ||||||
							
								
								
									
										22
									
								
								scripts/prompt.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								scripts/prompt.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue