UNPKG

@onepunya/ez-gemini

Version:

A wrapper for Google Gemini (Gemini Ai) API supporting both CommonJS (CJS) and ECMAScript Modules (ESM).

85 lines (66 loc) 2.08 kB
##@onepunya/ez-gemini A wrapper for Google Gemini (Gemini Ai) API supporting both CommonJS (CJS) and ECMAScript Modules (ESM). # Installation Install the package using npm: ```bash npm install @onepunya/ez-gemini ``` #Usage CommonJS (CJS) Create a new file example.js and add the following code to use the package with CommonJS: ```javascript const Gemini = require('@onepunya/ez-gemini'); const gemini = new Gemini(); (async () => { try { const textResponse = await gemini.pro('Hello'); console.log('Text Response:', textResponse); const imageResponse = await gemini.vision('https://example.com/image.jpg', 'Describe this image'); console.log('Response text:', imageResponse); } catch (error) { console.error('Error:', error); } })(); ``` ECMAScript Modules (ESM) Create a new file example.js and add the following code to use the package with ECMAScript Modules: ```javascript import Gemini from '@onepunya/ez-gemini'; const gemini = new Gemini(); (async () => { try { const textResponse = await gemini.pro('Hello'); console.log('Text Response:', textResponse); const imageResponse = await gemini.vision('https://example.com/image.jpg', 'Describe this image'); console.log('Response text:', imageResponse); } catch (error) { console.error('Error:', error); } })(); ``` ```javascript //use personal apikey new Gemini(apiKey) //or leave it blank new Gemini() //by default ``` ##example ```javascript const Gemini = require('@onepunya/ez-gemini'); const gemini = new Gemini(); (async () => { try { const textResponse = await gemini.pro('Hello, world!'); console.log('Text Response:', textResponse); const imageResponse = await gemini.vision('https://example.com/image.jpg', 'What is in this image?'); console.log('Image Response:', imageResponse); } catch (error) { console.error('Error:', error); } })(); ``` follow me • [github](https://github.com/onepunya) • [insta](https://Instagram.com/mr.one.id) • [comunity](https://chat.whatsapp.com/FRL4FzReE0X4qf8Yy80RkW) licence ISC